Skip to content

Commit 3c00552

Browse files
committed
client: GetTransactionField, GetWalletBalance; update README
1 parent f681c57 commit 3c00552

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

README.md

+38-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
}
2929

3030
id, stat, err := wallet.SendWinston(
31-
big.NewInt(1),
31+
big.NewInt(1), // Winston amount
3232
{{target}}, // target address
3333
[]types.Tag{
3434
types.Tag{
@@ -62,7 +62,7 @@ func main() {
6262
}
6363

6464
id, stat, err := wallet.SendData(
65-
[]byte("123"),
65+
[]byte("123"), // Data bytes
6666
[]types.Tag{
6767
types.Tag{
6868
Name: "testSendData",
@@ -75,6 +75,42 @@ func main() {
7575
}
7676
```
7777

78+
### Golang Package
79+
80+
#### client
81+
82+
- [x] GetInfo
83+
- [x] GetTransactionByID
84+
- [x] GetTransactionField
85+
- [x] GetTransactionData
86+
- [x] GetTransactionPrice
87+
- [x] GetTransactionAnchor
88+
- [x] SubmitTransaction
89+
- [x] Arql
90+
- [x] GetWalletBalance
91+
- [x] GetLastTransactionID
92+
- [x] GetBlockByID
93+
- [x] GetBlockByHeight
94+
95+
Initialize the instance:
96+
97+
```golang
98+
arClient := New("https://arweave.net")
99+
```
100+
101+
#### wallet
102+
103+
- [x] SendAR
104+
- [x] SendWinston
105+
- [x] SendData
106+
- [x] SendTransaction
107+
108+
Initialize the instance, use a keyfile.json:
109+
110+
```golang
111+
arWallet := NewFromPath("./keyfile.json")
112+
```
113+
78114
### Development
79115

80116
#### Test

client/client.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55
"encoding/json"
66
"fmt"
77
"io/ioutil"
8+
"math/big"
89
"net/http"
910
"net/url"
1011
"path"
1112
"strconv"
1213

1314
"github.com/everFinance/goar/types"
15+
"github.com/everFinance/goar/utils"
1416
)
1517

1618
type Client struct {
@@ -52,7 +54,14 @@ func (c *Client) GetTransactionByID(id string) (tx *types.Transaction, status st
5254
}
5355

5456
func (c *Client) GetTransactionField(id string, field string) (f string, err error) {
55-
// TODO
57+
url := fmt.Sprintf("tx/%v/%v", id, field)
58+
59+
body, statusCode, err := c.httpGet(url)
60+
if statusCode != 200 {
61+
err = fmt.Errorf("not found data")
62+
}
63+
64+
f = string(body)
5665
return
5766
}
5867

@@ -112,8 +121,20 @@ func (c *Client) Arql(arql string) (ids []string, err error) {
112121
}
113122

114123
// Wallet
115-
func (c *Client) GetWalletBalance(address string) (amount string, err error) {
116-
// TODO
124+
func (c *Client) GetWalletBalance(address string) (arAmount *big.Float, err error) {
125+
body, _, err := c.httpGet(fmt.Sprintf("wallet/%s/balance", address))
126+
if err != nil {
127+
return
128+
}
129+
130+
winstomStr := string(body)
131+
winstom, ok := new(big.Int).SetString(winstomStr, 10)
132+
if !ok {
133+
err = fmt.Errorf("invalid balance: %v", winstomStr)
134+
return
135+
}
136+
137+
arAmount = utils.WinstonToAR(winstom)
117138
return
118139
}
119140

client/client_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@ package client
6262
// `),
6363
// )
6464
// }
65+
66+
// func TestGetWalletBalance(t *testing.T) {
67+
// client := New("https://arweave.net")
68+
// fmt.Println(
69+
// client.GetWalletBalance("dQzTM9hXV5MD1fRniOKI3MvPF_-8b2XDLmpfcMN9hi8"),
70+
// )
71+
// }

0 commit comments

Comments
 (0)