Skip to content

Commit aad6682

Browse files
committed
feat: add EtherscanTx interface
1 parent 5a32153 commit aad6682

File tree

1 file changed

+128
-105
lines changed

1 file changed

+128
-105
lines changed

response.go

+128-105
Original file line numberDiff line numberDiff line change
@@ -30,115 +30,138 @@ type AccountBalance struct {
3030
Balance *BigInt `json:"balance"`
3131
}
3232

33-
// NormalTx holds info from normal tx query
34-
type NormalTx struct {
35-
BlockNumber int `json:"blockNumber,string"`
36-
TimeStamp Time `json:"timeStamp"`
37-
Hash string `json:"hash"`
38-
Nonce int `json:"nonce,string"`
39-
BlockHash string `json:"blockHash"`
40-
TransactionIndex int `json:"transactionIndex,string"`
41-
From string `json:"from"`
42-
To string `json:"to"`
43-
Value *BigInt `json:"value"`
44-
Gas int `json:"gas,string"`
45-
GasPrice *BigInt `json:"gasPrice"`
46-
IsError int `json:"isError,string"`
47-
TxReceiptStatus string `json:"txreceipt_status"`
48-
Input string `json:"input"`
49-
ContractAddress string `json:"contractAddress"`
50-
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
51-
GasUsed int `json:"gasUsed,string"`
52-
Confirmations int `json:"confirmations,string"`
53-
}
33+
type (
34+
// EtherscanTx represents
35+
EtherscanTx interface {
36+
GetBlockNumber() int
37+
GetHash() string
38+
}
5439

55-
// InternalTx holds info from internal tx query
56-
type InternalTx struct {
57-
BlockNumber int `json:"blockNumber,string"`
58-
TimeStamp Time `json:"timeStamp"`
59-
Hash string `json:"hash"`
60-
From string `json:"from"`
61-
To string `json:"to"`
62-
Value *BigInt `json:"value"`
63-
ContractAddress string `json:"contractAddress"`
64-
Input string `json:"input"`
65-
Type string `json:"type"`
66-
Gas int `json:"gas,string"`
67-
GasUsed int `json:"gasUsed,string"`
68-
TraceID string `json:"traceId"`
69-
IsError int `json:"isError,string"`
70-
ErrCode string `json:"errCode"`
71-
}
40+
// NormalTx holds info from normal tx query
41+
NormalTx struct {
42+
BlockNumber int `json:"blockNumber,string"`
43+
TimeStamp Time `json:"timeStamp"`
44+
Hash string `json:"hash"`
45+
Nonce int `json:"nonce,string"`
46+
BlockHash string `json:"blockHash"`
47+
TransactionIndex int `json:"transactionIndex,string"`
48+
From string `json:"from"`
49+
To string `json:"to"`
50+
Value *BigInt `json:"value"`
51+
Gas int `json:"gas,string"`
52+
GasPrice *BigInt `json:"gasPrice"`
53+
IsError int `json:"isError,string"`
54+
TxReceiptStatus string `json:"txreceipt_status"`
55+
Input string `json:"input"`
56+
ContractAddress string `json:"contractAddress"`
57+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
58+
GasUsed int `json:"gasUsed,string"`
59+
Confirmations int `json:"confirmations,string"`
60+
}
7261

73-
// ERC20Transfer holds info from ERC20 token transfer event query
74-
type ERC20Transfer struct {
75-
BlockNumber int `json:"blockNumber,string"`
76-
TimeStamp Time `json:"timeStamp"`
77-
Hash string `json:"hash"`
78-
Nonce int `json:"nonce,string"`
79-
BlockHash string `json:"blockHash"`
80-
From string `json:"from"`
81-
ContractAddress string `json:"contractAddress"`
82-
To string `json:"to"`
83-
Value *BigInt `json:"value"`
84-
TokenName string `json:"tokenName"`
85-
TokenSymbol string `json:"tokenSymbol"`
86-
TokenDecimal int `json:"tokenDecimal,string"`
87-
TransactionIndex int `json:"transactionIndex,string"`
88-
Gas int `json:"gas,string"`
89-
GasPrice *BigInt `json:"gasPrice"`
90-
GasUsed int `json:"gasUsed,string"`
91-
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
92-
Input string `json:"input"`
93-
Confirmations int `json:"confirmations,string"`
94-
}
62+
// InternalTx holds info from internal tx query
63+
InternalTx struct {
64+
BlockNumber int `json:"blockNumber,string"`
65+
TimeStamp Time `json:"timeStamp"`
66+
Hash string `json:"hash"`
67+
From string `json:"from"`
68+
To string `json:"to"`
69+
Value *BigInt `json:"value"`
70+
ContractAddress string `json:"contractAddress"`
71+
Input string `json:"input"`
72+
Type string `json:"type"`
73+
Gas int `json:"gas,string"`
74+
GasUsed int `json:"gasUsed,string"`
75+
TraceID string `json:"traceId"`
76+
IsError int `json:"isError,string"`
77+
ErrCode string `json:"errCode"`
78+
}
9579

96-
// ERC721Transfer holds info from ERC721 token transfer event query
97-
type ERC721Transfer struct {
98-
BlockNumber int `json:"blockNumber,string"`
99-
TimeStamp Time `json:"timeStamp"`
100-
Hash string `json:"hash"`
101-
Nonce int `json:"nonce,string"`
102-
BlockHash string `json:"blockHash"`
103-
From string `json:"from"`
104-
ContractAddress string `json:"contractAddress"`
105-
To string `json:"to"`
106-
TokenID *BigInt `json:"tokenID"`
107-
TokenName string `json:"tokenName"`
108-
TokenSymbol string `json:"tokenSymbol"`
109-
TokenDecimal int `json:"tokenDecimal,string"`
110-
TransactionIndex int `json:"transactionIndex,string"`
111-
Gas int `json:"gas,string"`
112-
GasPrice *BigInt `json:"gasPrice"`
113-
GasUsed int `json:"gasUsed,string"`
114-
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
115-
Input string `json:"input"`
116-
Confirmations int `json:"confirmations,string"`
117-
}
80+
// ERC20Transfer holds info from ERC20 token transfer event query
81+
ERC20Transfer struct {
82+
BlockNumber int `json:"blockNumber,string"`
83+
TimeStamp Time `json:"timeStamp"`
84+
Hash string `json:"hash"`
85+
Nonce int `json:"nonce,string"`
86+
BlockHash string `json:"blockHash"`
87+
From string `json:"from"`
88+
ContractAddress string `json:"contractAddress"`
89+
To string `json:"to"`
90+
Value *BigInt `json:"value"`
91+
TokenName string `json:"tokenName"`
92+
TokenSymbol string `json:"tokenSymbol"`
93+
TokenDecimal int `json:"tokenDecimal,string"`
94+
TransactionIndex int `json:"transactionIndex,string"`
95+
Gas int `json:"gas,string"`
96+
GasPrice *BigInt `json:"gasPrice"`
97+
GasUsed int `json:"gasUsed,string"`
98+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
99+
Input string `json:"input"`
100+
Confirmations int `json:"confirmations,string"`
101+
}
118102

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 int `json:"tokenDecimal,string"`
133-
//TokenValue int `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-
}
103+
// ERC721Transfer holds info from ERC721 token transfer event query
104+
ERC721Transfer struct {
105+
BlockNumber int `json:"blockNumber,string"`
106+
TimeStamp Time `json:"timeStamp"`
107+
Hash string `json:"hash"`
108+
Nonce int `json:"nonce,string"`
109+
BlockHash string `json:"blockHash"`
110+
From string `json:"from"`
111+
ContractAddress string `json:"contractAddress"`
112+
To string `json:"to"`
113+
TokenID *BigInt `json:"tokenID"`
114+
TokenName string `json:"tokenName"`
115+
TokenSymbol string `json:"tokenSymbol"`
116+
TokenDecimal int `json:"tokenDecimal,string"`
117+
TransactionIndex int `json:"transactionIndex,string"`
118+
Gas int `json:"gas,string"`
119+
GasPrice *BigInt `json:"gasPrice"`
120+
GasUsed int `json:"gasUsed,string"`
121+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
122+
Input string `json:"input"`
123+
Confirmations int `json:"confirmations,string"`
124+
}
125+
126+
// ERC1155Transfer holds info from ERC1155 token transfer event query
127+
ERC1155Transfer struct {
128+
BlockNumber int `json:"blockNumber,string"`
129+
TimeStamp Time `json:"timeStamp"`
130+
Hash string `json:"hash"`
131+
//Nonce int `json:"nonce,string"`
132+
BlockHash string `json:"blockHash"`
133+
From string `json:"from"`
134+
ContractAddress string `json:"contractAddress"`
135+
To string `json:"to"`
136+
//TokenID *BigInt `json:"tokenID"`
137+
TokenName string `json:"tokenName"`
138+
TokenSymbol string `json:"tokenSymbol"`
139+
//TokenDecimal int `json:"tokenDecimal,string"`
140+
//TokenValue int `json:"tokenValue,string"`
141+
//TransactionIndex int `json:"transactionIndex,string"`
142+
//Gas int `json:"gas,string"`
143+
//GasPrice *BigInt `json:"gasPrice"`
144+
//GasUsed int `json:"gasUsed,string"`
145+
//CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
146+
Input string `json:"input"`
147+
//Confirmations int `json:"confirmations,string"`
148+
}
149+
)
150+
151+
func (tx NormalTx) GetBlockNumber() int { return tx.BlockNumber }
152+
func (tx NormalTx) GetHash() string { return tx.Hash }
153+
154+
func (tx InternalTx) GetBlockNumber() int { return tx.BlockNumber }
155+
func (tx InternalTx) GetHash() string { return tx.Hash }
156+
157+
func (tx ERC20Transfer) GetBlockNumber() int { return tx.BlockNumber }
158+
func (tx ERC20Transfer) GetHash() string { return tx.Hash }
159+
160+
func (tx ERC721Transfer) GetBlockNumber() int { return tx.BlockNumber }
161+
func (tx ERC721Transfer) GetHash() string { return tx.Hash }
162+
163+
func (tx ERC1155Transfer) GetBlockNumber() int { return tx.BlockNumber }
164+
func (tx ERC1155Transfer) GetHash() string { return tx.Hash }
142165

143166
// MinedBlock holds info from query for mined block by address
144167
type MinedBlock struct {

0 commit comments

Comments
 (0)