Skip to content

Commit

Permalink
Merge pull request #63 from 7AC/master
Browse files Browse the repository at this point in the history
account: add ERC721Transfers()
  • Loading branch information
nanmu42 authored Dec 5, 2021
2 parents 4bf649f + 57f5d0b commit 2ceb77c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
24 changes: 24 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *in
return
}

// ERC721Transfers get a list of "erc721 - token transfer events" by
// contract address and/or from/to address.
//
// leave undesired condition to nil.
func (c *Client) ERC721Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC721Transfer, err error) {
param := M{
"page": page,
"offset": offset,
}
compose(param, "contractaddress", contractAddress)
compose(param, "address", address)
compose(param, "startblock", startBlock)
compose(param, "endblock", endBlock)

if desc {
param["sort"] = "desc"
} else {
param["sort"] = "asc"
}

err = c.call("account", "tokennfttx", param, &txs)
return
}

// BlocksMinedByAddress gets list of blocks mined by address
func (c *Client) BlocksMinedByAddress(address string, page int, offset int) (mined []MinedBlock, err error) {
param := M{
Expand Down
23 changes: 23 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ type ERC20Transfer struct {
Confirmations int `json:"confirmations,string"`
}

// ERC721Transfer holds info from ERC721 token transfer event query
type ERC721Transfer struct {
BlockNumber int `json:"blockNumber,string"`
TimeStamp Time `json:"timeStamp"`
Hash string `json:"hash"`
Nonce int `json:"nonce,string"`
BlockHash string `json:"blockHash"`
From string `json:"from"`
ContractAddress string `json:"contractAddress"`
To string `json:"to"`
TokenID *BigInt `json:"tokenID"`
TokenName string `json:"tokenName"`
TokenSymbol string `json:"tokenSymbol"`
TokenDecimal uint8 `json:"tokenDecimal,string"`
TransactionIndex int `json:"transactionIndex,string"`
Gas int `json:"gas,string"`
GasPrice *BigInt `json:"gasPrice"`
GasUsed int `json:"gasUsed,string"`
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
Input string `json:"input"`
Confirmations int `json:"confirmations,string"`
}

// MinedBlock holds info from query for mined block by address
type MinedBlock struct {
BlockNumber int `json:"blockNumber,string"`
Expand Down

0 comments on commit 2ceb77c

Please sign in to comment.