Skip to content

Commit 277bb08

Browse files
authored
Merge pull request #19 from everFinance/fix-bug
feat(): fix get block by height bug
2 parents 7e435ba + 1659205 commit 277bb08

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

client.go

+17
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ func (c *Client) GetTransactionField(id string, field string) (f string, err err
9797
return
9898
}
9999

100+
func (c *Client) GetTransactionTags(id string) ([]types.Tag, error) {
101+
jsTags, err := c.GetTransactionField(id, "tags")
102+
if err != nil {
103+
return nil, err
104+
}
105+
106+
tags := make([]types.Tag, 0)
107+
if err := json.Unmarshal([]byte(jsTags), &tags); err != nil {
108+
return nil, err
109+
}
110+
tags, err = utils.TagsDecode(tags)
111+
if err != nil {
112+
return nil, err
113+
}
114+
return tags, nil
115+
}
116+
100117
func (c *Client) GetTransactionData(id string, extension ...string) (body []byte, err error) {
101118
url := fmt.Sprintf("tx/%v/%v", id, "data")
102119
if extension != nil {

client_test.go

+26-16
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,13 @@ func TestClient_DownloadChunkData(t *testing.T) {
112112
// assert.NoError(t, err)
113113
}
114114

115-
func TestClient_GetTransactionData(t *testing.T) {
116-
// proxy := "http://127.0.0.1:8001"
117-
client := NewClient("https://arweave.net")
118-
id := "lSHWbAfjJsK0so08BTTmHO_n809fGW2DYOMySsXHNuI"
119-
data, err := client.GetTransactionData(id, "json")
120-
if err != nil {
121-
t.Log(err.Error())
122-
}
123-
124-
t.Log(string(data))
125-
}
126-
127-
func TestNew(t *testing.T) {
128-
data := []byte("this is a goar test small size file data")
129-
a := utils.Base64Encode(data)
130-
t.Log(a)
115+
func TestClient_Arql(t *testing.T) {
116+
// client := NewClient("https://arweave.dev")
117+
// id := "PvLGaQzn9MOwucO91uuMGRnq8pj1qlwbURPqhmW0UiM"
118+
//
119+
// status, err := client.GetTransactionStatus(id)
120+
// assert.NoError(t, err)
121+
// t.Log(status)
131122
}
132123

133124
func TestClient_VerifyTx(t *testing.T) {
@@ -173,3 +164,22 @@ func TestGetTransaction(t *testing.T) {
173164
// assert.Equal(t, "Pending",err.Error())
174165
// assert.Nil(t, txStatus)
175166
}
167+
168+
func TestClient_GetTransactionTags(t *testing.T) {
169+
arNode := "https://arweave.net"
170+
cli := NewClient(arNode)
171+
id := "gdXUJuj9EZm99TmeES7zRHCJtnJoP3XgYo_7KJNV8Vw"
172+
tags, err := cli.GetTransactionTags(id)
173+
assert.NoError(t, err)
174+
assert.Equal(t, "App", tags[0].Name)
175+
assert.Equal(t, "Version", tags[1].Name)
176+
assert.Equal(t, "Owner", tags[2].Name)
177+
}
178+
179+
func TestClient_GetBlockByHeight(t *testing.T) {
180+
arNode := "https://arweave.net"
181+
cli := NewClient(arNode)
182+
block, err := cli.GetBlockByHeight(737432)
183+
assert.NoError(t, err)
184+
assert.Equal(t, "7YeJpe53rFsEE03yKjGcBQAAw6efgVfSeGNLmPRGY4c", block.Nonce)
185+
}

types/types.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ type Block struct {
2525
WalletList string `json:"wallet_list"`
2626
RewardAddr string `json:"reward_addr"`
2727
Tags []interface{} `json:"tags"`
28-
RewardPool int `json:"reward_pool"`
29-
WeaveSize int `json:"weave_size"`
30-
BlockSize int `json:"block_size"`
28+
RewardPool string `json:"reward_pool"`
29+
WeaveSize string `json:"weave_size"`
30+
BlockSize string `json:"block_size"`
3131
}
3232

3333
type TransactionChunk struct {

0 commit comments

Comments
 (0)