Skip to content

Commit 867376f

Browse files
committed
[dev] block module
1 parent eedeb17 commit 867376f

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

block.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2018 LI Zhennan
3+
*
4+
* Use of this work is governed by a MIT License.
5+
* You may find a license copy in project root.
6+
*/
7+
8+
package etherscan
9+
10+
// BlockReward gets block and uncle rewards by block number
11+
func (c *Client) BlockReward(blockNum int) (rewards BlockRewards, err error) {
12+
param := M{
13+
"blockno": blockNum,
14+
}
15+
16+
err = c.call("block", "getblockreward", param, &rewards)
17+
return
18+
}

block_e2e_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2018 LI Zhennan
3+
*
4+
* Use of this work is governed by a MIT License.
5+
* You may find a license copy in project root.
6+
*/
7+
8+
package etherscan
9+
10+
import (
11+
"encoding/json"
12+
"testing"
13+
)
14+
15+
func TestClient_BlockReward(t *testing.T) {
16+
const ans = `{"blockNumber":"2165403","timeStamp":"1472533979","blockMiner":"0x13a06d3dfe21e0db5c016c03ea7d2509f7f8d1e3","blockReward":"5314181600000000000","uncles":[{"miner":"0xbcdfc35b86bedf72f0cda046a3c16829a2ef41d1","unclePosition":"0","blockreward":"3750000000000000000"},{"miner":"0x0d0c9855c722ff0c78f21e43aa275a5b8ea60dce","unclePosition":"1","blockreward":"3750000000000000000"}],"uncleInclusionReward":"312500000000000000"}`
17+
18+
reward, err := api.BlockReward(2165403)
19+
noError(t, err, "api.BlockReward")
20+
21+
j, err := json.Marshal(reward)
22+
noError(t, err, "json.Marshal")
23+
if string(j) != ans {
24+
t.Errorf("api.BlockReward not working, got %s, want %s", j, ans)
25+
}
26+
}

response.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ type ExecutionStatus struct {
114114
IsError int `json:"isError,string"`
115115
ErrDescription string `json:"errDescription"`
116116
}
117+
118+
// BlockRewards holds info from query for block and uncle rewards
119+
type BlockRewards struct {
120+
BlockNumber int `json:"blockNumber,string"`
121+
TimeStamp Time `json:"timeStamp"`
122+
BlockMiner string `json:"blockMiner"`
123+
BlockReward *BigInt `json:"blockReward"`
124+
Uncles []struct {
125+
Miner string `json:"miner"`
126+
UnclePosition int `json:"unclePosition,string"`
127+
BlockReward *BigInt `json:"blockreward"`
128+
} `json:"uncles"`
129+
UncleInclusionReward *BigInt `json:"uncleInclusionReward"`
130+
}

0 commit comments

Comments
 (0)