-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallets.go
61 lines (49 loc) · 1.27 KB
/
wallets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package arweave
import (
"fmt"
"io/ioutil"
"math/big"
"net/http"
)
// WalletBalance Get the balance for a given wallet. Unknown wallet addresses will simply return 0.
func (a *Arweave) WalletBalance(address string) (*big.Int, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/wallet/%s/balance", a.fqdn(), address), nil)
if err != nil {
return nil, err
}
res, err := a.client.Do(req)
if err != nil {
return nil, err
}
if res.StatusCode != http.StatusOK {
return nil, ErrorNotOk(res.StatusCode)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
i := new(big.Int)
if err := i.UnmarshalText(body); err != nil {
return nil, ErrorUnmarshalTextToBigInt(err)
}
return i, nil
}
// WalletLastTransactionID Get the last outgoing transaction for the given wallet address.
func (a *Arweave) WalletLastTransactionID(address string) (string, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/wallet/%s/last_tx", a.fqdn(), address), nil)
if err != nil {
return "", err
}
res, err := a.client.Do(req)
if err != nil {
return "", err
}
if res.StatusCode != http.StatusOK {
return "", ErrorNotOk(res.StatusCode)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return "", err
}
return string(body), nil
}