|
7 | 7 |
|
8 | 8 | package etherscan
|
9 | 9 |
|
10 |
| -import "math/big" |
| 10 | +// AccountBalance gets ether balance for a single address |
| 11 | +func (c *Client) AccountBalance(address string) (balance *BigInt, err error) { |
| 12 | + param := M{ |
| 13 | + "tag": "latest", |
| 14 | + "address": address, |
| 15 | + } |
| 16 | + balance = new(BigInt) |
| 17 | + err = c.call("account", "balance", param, balance) |
| 18 | + return |
| 19 | +} |
11 | 20 |
|
12 |
| -// SingleAddrBalance get latest address balance |
13 |
| -func (c *Client) SingleAddrBalance(address string) (balance *big.Int, err error) { |
| 21 | +// MultiAccountBalance gets ether balance for multiple addresses in a single call |
| 22 | +func (c *Client) MultiAccountBalance(addresses ...string) (balances []AccountBalance, err error) { |
14 | 23 | param := M{
|
15 | 24 | "tag": "latest",
|
| 25 | + "address": addresses, |
| 26 | + } |
| 27 | + balances = make([]AccountBalance, 0, len(addresses)) |
| 28 | + err = c.call("account", "balancemulti", param, &balances) |
| 29 | + return |
| 30 | +} |
| 31 | + |
| 32 | +// NormalTxByAddress gets a list of "normal" transactions by address |
| 33 | +// startBlock and endBlock can be nil |
| 34 | +// if desc is true, result will be sorted in blockNum descendant order. |
| 35 | +func (c *Client) NormalTxByAddress(address string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []NormalTx, err error) { |
| 36 | + param := M{ |
| 37 | + "address": address, |
| 38 | + "page": page, |
| 39 | + "offset": offset, |
| 40 | + } |
| 41 | + compose(param, "startblock", startBlock) |
| 42 | + compose(param, "endblock", endBlock) |
| 43 | + if desc { |
| 44 | + param["sort"] = "desc" |
| 45 | + } else { |
| 46 | + param["sort"] = "asc" |
| 47 | + } |
| 48 | + |
| 49 | + err = c.call("account", "txlist", param, &txs) |
| 50 | + return |
| 51 | +} |
| 52 | + |
| 53 | +// InternalTxByAddress gets a list of "internal" transactions by address |
| 54 | +// startBlock and endBlock can be nil |
| 55 | +// if desc is true, result will be sorted in descendant order. |
| 56 | +func (c *Client) InternalTxByAddress(address string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []InternalTx, err error) { |
| 57 | + param := M{ |
16 | 58 | "address": address,
|
| 59 | + "page": page, |
| 60 | + "offset": offset, |
| 61 | + } |
| 62 | + compose(param, "startblock", startBlock) |
| 63 | + compose(param, "endblock", endBlock) |
| 64 | + if desc { |
| 65 | + param["sort"] = "desc" |
| 66 | + } else { |
| 67 | + param["sort"] = "asc" |
| 68 | + } |
| 69 | + |
| 70 | + err = c.call("account", "txlistinternal", param, &txs) |
| 71 | + return |
| 72 | +} |
| 73 | + |
| 74 | +// ERC20TransferTx get a list of "erc20 - token transfer events" by |
| 75 | +// contract address and/or from/to address. |
| 76 | +// leave undesired condition to nil. |
| 77 | +func (c *Client) ERC20TransferTx(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int) (txs []ERC20Transfer, err error) { |
| 78 | + param := M{ |
| 79 | + "page": page, |
| 80 | + "offset": offset, |
| 81 | + } |
| 82 | + compose(param, "contractaddress", contractAddress) |
| 83 | + compose(param, "address", address) |
| 84 | + compose(param, "startblock", startBlock) |
| 85 | + compose(param, "endblock", endBlock) |
| 86 | + |
| 87 | + err = c.call("account", "tokentx", param, &txs) |
| 88 | + return |
| 89 | +} |
| 90 | + |
| 91 | +// BlocksMinedByAddress gets list of blocks mined by address |
| 92 | +func (c *Client) BlocksMinedByAddress(address string, page int, offset int) (mined []MinedBlock, err error) { |
| 93 | + param := M{ |
| 94 | + "address": address, |
| 95 | + "blocktype": "blocks", |
| 96 | + "page": page, |
| 97 | + "offset": offset, |
| 98 | + } |
| 99 | + |
| 100 | + err = c.call("account", "getminedblocks", param, &mined) |
| 101 | + return |
| 102 | +} |
| 103 | + |
| 104 | +// UnclesMinedByAddress gets list of uncles mined by address |
| 105 | +func (c *Client) UnclesMinedByAddress(address string, page int, offset int) (mined []MinedBlock, err error) { |
| 106 | + param := M{ |
| 107 | + "address": address, |
| 108 | + "blocktype": "uncles", |
| 109 | + "page": page, |
| 110 | + "offset": offset, |
17 | 111 | }
|
18 | 112 |
|
19 |
| - var b BigInt |
20 |
| - err = c.call("account", "balance", param, &b) |
21 |
| - balance = (*big.Int)(&b) |
| 113 | + err = c.call("account", "getminedblocks", param, &mined) |
22 | 114 | return
|
23 | 115 | }
|
0 commit comments