Skip to content

Commit cf99fda

Browse files
Dodonov PavelDodonov Pavel
Dodonov Pavel
authored and
Dodonov Pavel
committed
erc1155 tx struct and ERC1155Transfers added
1 parent 115bac1 commit cf99fda

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

account.go

+24
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ func (c *Client) ERC721Transfers(contractAddress, address *string, startBlock *i
131131
return
132132
}
133133

134+
// ERC1155Transfers get a list of "erc1155 - token transfer events" by
135+
// contract address and/or from/to address.
136+
//
137+
// leave undesired condition to nil.
138+
func (c *Client) ERC1155Transfers(contractAddress, address *string, startBlock *int, endBlock *int, page int, offset int, desc bool) (txs []ERC1155Transfer, err error) {
139+
param := M{
140+
"page": page,
141+
"offset": offset,
142+
}
143+
compose(param, "contractaddress", contractAddress)
144+
compose(param, "address", address)
145+
compose(param, "startblock", startBlock)
146+
compose(param, "endblock", endBlock)
147+
148+
if desc {
149+
param["sort"] = "desc"
150+
} else {
151+
param["sort"] = "asc"
152+
}
153+
154+
err = c.call("account", "token1155tx", param, &txs)
155+
return
156+
}
157+
134158
// BlocksMinedByAddress gets list of blocks mined by address
135159
func (c *Client) BlocksMinedByAddress(address string, page int, offset int) (mined []MinedBlock, err error) {
136160
param := M{

account_e2e_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,21 @@ func TestClient_ERC721Transfers(t *testing.T) {
169169
t.Errorf("got txs length %v, want %v", len(txs), wantLen)
170170
}
171171
}
172+
173+
func TestClient_ERC1155Transfers(t *testing.T) {
174+
const (
175+
wantLen = 1
176+
)
177+
178+
var a, b = 128135633, 1802672
179+
var contract, address = "0x3edf71a31b80Ff6a45Fdb0858eC54DE98dF047AA", "0x4b986EF20Bb83532911521FB4F6F5605122a0721"
180+
txs, err := api.ERC1155Transfers(&contract, &address, &b, &a, 0, 0, true)
181+
noError(t, err, "api.ERC721Transfers")
182+
183+
j, _ := json.MarshalIndent(txs, "", " ")
184+
fmt.Printf("%s\n", j)
185+
186+
if len(txs) != wantLen {
187+
t.Errorf("got txs length %v, want %v", len(txs), wantLen)
188+
}
189+
}

response.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ type ERC721Transfer struct {
116116
Confirmations int `json:"confirmations,string"`
117117
}
118118

119+
// ERC1155Transfer holds info from ERC1155 token transfer event query
120+
type ERC1155Transfer struct {
121+
BlockNumber int `json:"blockNumber,string"`
122+
TimeStamp Time `json:"timeStamp"`
123+
Hash string `json:"hash"`
124+
Nonce int `json:"nonce,string"`
125+
BlockHash string `json:"blockHash"`
126+
From string `json:"from"`
127+
ContractAddress string `json:"contractAddress"`
128+
To string `json:"to"`
129+
TokenID *BigInt `json:"tokenID"`
130+
TokenName string `json:"tokenName"`
131+
TokenSymbol string `json:"tokenSymbol"`
132+
TokenDecimal uint8 `json:"tokenDecimal,string"`
133+
TokenValue uint8 `json:"tokenValue,string"`
134+
TransactionIndex int `json:"transactionIndex,string"`
135+
Gas int `json:"gas,string"`
136+
GasPrice *BigInt `json:"gasPrice"`
137+
GasUsed int `json:"gasUsed,string"`
138+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
139+
Input string `json:"input"`
140+
Confirmations int `json:"confirmations,string"`
141+
}
142+
119143
// MinedBlock holds info from query for mined block by address
120144
type MinedBlock struct {
121145
BlockNumber int `json:"blockNumber,string"`
@@ -180,8 +204,8 @@ type Log struct {
180204
Removed bool `json:"removed"`
181205
}
182206

183-
//GasPrices holds info for Gas Oracle queries
184-
//Gas Prices are returned in Gwei
207+
// GasPrices holds info for Gas Oracle queries
208+
// Gas Prices are returned in Gwei
185209
type GasPrices struct {
186210
LastBlock int
187211
SafeGasPrice float64

0 commit comments

Comments
 (0)