forked from nanmu42/etherscan-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.go
49 lines (39 loc) · 1013 Bytes
/
block.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
/*
* Copyright (c) 2018 LI Zhennan
*
* Use of this work is governed by a MIT License.
* You may find a license copy in project root.
*/
package etherscan
import (
"fmt"
"strconv"
)
// BlockReward gets block and uncle rewards by block number
func (c *Client) BlockReward(blockNum int) (rewards BlockRewards, err error) {
param := M{
"blockno": blockNum,
}
err = c.call("block", "getblockreward", param, &rewards)
return
}
// BlockNumber gets the closest block number by UNIX timestamp
//
// valid closest option: before, after
func (c *Client) BlockNumber(timestamp int64, closest string) (blockNumber int, err error) {
var blockNumberStr string
param := M{
"timestamp": strconv.FormatInt(timestamp, 10),
"closest": closest,
}
err = c.call("block", "getblocknobytime", param, &blockNumberStr)
if err != nil {
return
}
blockNumber, err = strconv.Atoi(blockNumberStr)
if err != nil {
err = fmt.Errorf("parsing block number %q: %w", blockNumberStr, err)
return
}
return
}