diff --git a/account.go b/account.go index 85d48fa..690ccde 100644 --- a/account.go +++ b/account.go @@ -79,7 +79,7 @@ func (c *Client) InternalTxByAddress(address string, startBlock *int, endBlock * // contract address and/or from/to address. // // leave undesired condition to nil. -func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int) (txs []ERC20Transfer, err error) { +func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC20Transfer, err error) { param := M{ "page": page, "offset": offset, @@ -89,6 +89,12 @@ func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *in compose(param, "startblock", startBlock) compose(param, "endblock", endBlock) + if desc { + param["sort"] = "desc" + } else { + param["sort"] = "asc" + } + err = c.call("account", "tokentx", param, &txs) return } diff --git a/client.go b/client.go index e7422cd..56a64d0 100644 --- a/client.go +++ b/client.go @@ -123,8 +123,9 @@ func (c *Client) call(module, action string, param map[string]interface{}, outco return } + contentBytes := bytes.Replace(content.Bytes(), []byte(`"tokenDecimal":""`), []byte(`"tokenDecimal":"0"`), -1) var envelope Envelope - err = json.Unmarshal(content.Bytes(), &envelope) + err = json.Unmarshal(contentBytes, &envelope) if err != nil { err = wrapErr(err, "json unmarshal envelope") return