Skip to content

Commit d8fcb92

Browse files
committed
feat: replace all occurences of BigInt with big.Int
1 parent a65a8d8 commit d8fcb92

File tree

4 files changed

+111
-110
lines changed

4 files changed

+111
-110
lines changed

account_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestClient_MultiAccountBalance(t *testing.T) {
3535
if item.Account == "" {
3636
t.Errorf("bound error on index %v", i)
3737
}
38-
if item.Balance.Int().Cmp(big.NewInt(0)) != 1 {
38+
if item.Balance.Cmp(big.NewInt(0)) != 1 {
3939
t.Errorf("rich man %s at index %v is no longer rich.", item.Account, i)
4040
}
4141
}

helper.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ type M map[string]interface{}
4242
type BigInt big.Int
4343

4444
// UnmarshalText implements the encoding.TextUnmarshaler interface.
45-
func (b *BigInt) UnmarshalText(text []byte) (err error) {
45+
func (b *BigInt) UnmarshalText(text []byte) error {
4646
var bigInt = new(big.Int)
47-
err = bigInt.UnmarshalText(text)
48-
if err != nil {
49-
return
47+
if err := bigInt.UnmarshalText(text); err != nil {
48+
return err
5049
}
5150

5251
*b = BigInt(*bigInt)
5352
return nil
5453
}
5554

5655
// MarshalText implements the encoding.TextMarshaler
57-
func (b *BigInt) MarshalText() (text []byte, err error) {
56+
func (b *BigInt) MarshalText() ([]byte, error) {
5857
return []byte(b.Int().String()), nil
5958
}
6059

logs_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func TestClient_GetLogs(t *testing.T) {
1010
expectedLogs := []Log{
11-
Log{
11+
{
1212
Address: "0x33990122638b9132ca29c723bdf037f1a891a70c",
1313
Topics: []string{"0xf63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a8545", "0x72657075746174696f6e00000000000000000000000000000000000000000000", "0x000000000000000000000000d9b2f59f3b5c7b3c67047d2f03c3e8052470be92"},
1414
Data: "0x",

response.go

Lines changed: 105 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ package etherscan
1010
import (
1111
"encoding/json"
1212
"fmt"
13+
"math/big"
1314
"strconv"
1415
"strings"
16+
"time"
1517
)
1618

1719
// Envelope is the carrier of nearly every response
@@ -26,125 +28,125 @@ type Envelope struct {
2628

2729
// AccountBalance account and its balance in pair
2830
type AccountBalance struct {
29-
Account string `json:"account"`
30-
Balance *BigInt `json:"balance"`
31+
Account string `json:"account"`
32+
Balance *big.Int `json:"balance"`
3133
}
3234

3335
// NormalTx holds info from normal tx query
3436
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"`
37+
BlockNumber int `json:"blockNumber,string"`
38+
TimeStamp time.Time `json:"timeStamp"`
39+
Hash string `json:"hash"`
40+
Nonce int `json:"nonce,string"`
41+
BlockHash string `json:"blockHash"`
42+
TransactionIndex int `json:"transactionIndex,string"`
43+
From string `json:"from"`
44+
To string `json:"to"`
45+
Value *big.Int `json:"value"`
46+
Gas int `json:"gas,string"`
47+
GasPrice *big.Int `json:"gasPrice"`
48+
IsError int `json:"isError,string"`
49+
TxReceiptStatus string `json:"txreceipt_status"`
50+
Input string `json:"input"`
51+
ContractAddress string `json:"contractAddress"`
52+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
53+
GasUsed int `json:"gasUsed,string"`
54+
Confirmations int `json:"confirmations,string"`
5355
}
5456

5557
// InternalTx holds info from internal tx query
5658
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"`
59+
BlockNumber int `json:"blockNumber,string"`
60+
TimeStamp time.Time `json:"timeStamp"`
61+
Hash string `json:"hash"`
62+
From string `json:"from"`
63+
To string `json:"to"`
64+
Value *big.Int `json:"value"`
65+
ContractAddress string `json:"contractAddress"`
66+
Input string `json:"input"`
67+
Type string `json:"type"`
68+
Gas int `json:"gas,string"`
69+
GasUsed int `json:"gasUsed,string"`
70+
TraceID string `json:"traceId"`
71+
IsError int `json:"isError,string"`
72+
ErrCode string `json:"errCode"`
7173
}
7274

7375
// ERC20Transfer holds info from ERC20 token transfer event query
7476
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 uint8 `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"`
77+
BlockNumber int `json:"blockNumber,string"`
78+
TimeStamp time.Time `json:"timeStamp"`
79+
Hash string `json:"hash"`
80+
Nonce int `json:"nonce,string"`
81+
BlockHash string `json:"blockHash"`
82+
From string `json:"from"`
83+
ContractAddress string `json:"contractAddress"`
84+
To string `json:"to"`
85+
Value *big.Int `json:"value"`
86+
TokenName string `json:"tokenName"`
87+
TokenSymbol string `json:"tokenSymbol"`
88+
TokenDecimal uint8 `json:"tokenDecimal,string"`
89+
TransactionIndex int `json:"transactionIndex,string"`
90+
Gas int `json:"gas,string"`
91+
GasPrice *big.Int `json:"gasPrice"`
92+
GasUsed int `json:"gasUsed,string"`
93+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
94+
Input string `json:"input"`
95+
Confirmations int `json:"confirmations,string"`
9496
}
9597

9698
// ERC721Transfer holds info from ERC721 token transfer event query
9799
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 uint8 `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"`
100+
BlockNumber int `json:"blockNumber,string"`
101+
TimeStamp time.Time `json:"timeStamp"`
102+
Hash string `json:"hash"`
103+
Nonce int `json:"nonce,string"`
104+
BlockHash string `json:"blockHash"`
105+
From string `json:"from"`
106+
ContractAddress string `json:"contractAddress"`
107+
To string `json:"to"`
108+
TokenID *big.Int `json:"tokenID"`
109+
TokenName string `json:"tokenName"`
110+
TokenSymbol string `json:"tokenSymbol"`
111+
TokenDecimal uint8 `json:"tokenDecimal,string"`
112+
TransactionIndex int `json:"transactionIndex,string"`
113+
Gas int `json:"gas,string"`
114+
GasPrice *big.Int `json:"gasPrice"`
115+
GasUsed int `json:"gasUsed,string"`
116+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
117+
Input string `json:"input"`
118+
Confirmations int `json:"confirmations,string"`
117119
}
118120

119121
// ERC1155Transfer holds info from ERC1155 token transfer event query
120122
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"`
123+
BlockNumber int `json:"blockNumber,string"`
124+
TimeStamp time.Time `json:"timeStamp"`
125+
Hash string `json:"hash"`
126+
Nonce int `json:"nonce,string"`
127+
BlockHash string `json:"blockHash"`
128+
From string `json:"from"`
129+
ContractAddress string `json:"contractAddress"`
130+
To string `json:"to"`
131+
TokenID *big.Int `json:"tokenID"`
132+
TokenName string `json:"tokenName"`
133+
TokenSymbol string `json:"tokenSymbol"`
134+
TokenDecimal int `json:"tokenDecimal,string"`
135+
TokenValue int `json:"tokenValue,string"`
136+
TransactionIndex int `json:"transactionIndex,string"`
137+
Gas int `json:"gas,string"`
138+
GasPrice *big.Int `json:"gasPrice"`
139+
GasUsed int `json:"gasUsed,string"`
140+
CumulativeGasUsed int `json:"cumulativeGasUsed,string"`
141+
Input string `json:"input"`
142+
Confirmations int `json:"confirmations,string"`
141143
}
142144

143145
// MinedBlock holds info from query for mined block by address
144146
type MinedBlock struct {
145-
BlockNumber int `json:"blockNumber,string"`
146-
TimeStamp Time `json:"timeStamp"`
147-
BlockReward *BigInt `json:"blockReward"`
147+
BlockNumber int `json:"blockNumber,string"`
148+
TimeStamp Time `json:"timeStamp"`
149+
BlockReward *big.Int `json:"blockReward"`
148150
}
149151

150152
// ContractSource holds info from query for contract source code
@@ -173,16 +175,16 @@ type ExecutionStatus struct {
173175

174176
// BlockRewards holds info from query for block and uncle rewards
175177
type BlockRewards struct {
176-
BlockNumber int `json:"blockNumber,string"`
177-
TimeStamp Time `json:"timeStamp"`
178-
BlockMiner string `json:"blockMiner"`
179-
BlockReward *BigInt `json:"blockReward"`
178+
BlockNumber int `json:"blockNumber,string"`
179+
TimeStamp Time `json:"timeStamp"`
180+
BlockMiner string `json:"blockMiner"`
181+
BlockReward *big.Int `json:"blockReward"`
180182
Uncles []struct {
181-
Miner string `json:"miner"`
182-
UnclePosition int `json:"unclePosition,string"`
183-
BlockReward *BigInt `json:"blockreward"`
183+
Miner string `json:"miner"`
184+
UnclePosition int `json:"unclePosition,string"`
185+
BlockReward *big.Int `json:"blockreward"`
184186
} `json:"uncles"`
185-
UncleInclusionReward *BigInt `json:"uncleInclusionReward"`
187+
UncleInclusionReward *big.Int `json:"uncleInclusionReward"`
186188
}
187189

188190
// LatestPrice holds info from query for latest ether price

0 commit comments

Comments
 (0)