@@ -171,9 +171,13 @@ func main() {
171
171
EnvVar : pkVarName ,
172
172
Destination : & privateKey ,
173
173
Hidden : false },
174
+ cli.StringFlag {
175
+ Name : "block" ,
176
+ Usage : "Block number" ,
177
+ Hidden : false },
174
178
},
175
179
Action : func (c * cli.Context ) {
176
- GetAddressDetails (ctx , network , c .Args ().First (), privateKey , false , "" )
180
+ GetAddressDetails (ctx , network , c .Args ().First (), privateKey , false , "" , c . String ( "block" ) )
177
181
},
178
182
},
179
183
{
@@ -195,6 +199,10 @@ func main() {
195
199
EnvVar : addrVarName ,
196
200
Usage : "Contract address" ,
197
201
Hidden : false },
202
+ cli.StringFlag {
203
+ Name : "block" ,
204
+ Usage : "Block number" ,
205
+ Hidden : false },
198
206
},
199
207
Action : func (c * cli.Context ) {
200
208
contractAddress = ""
@@ -204,7 +212,7 @@ func main() {
204
212
fatalExit (errors .New ("You must set ERC20 contract address" ))
205
213
}
206
214
}
207
- GetAddressDetails (ctx , network , c .Args ().First (), privateKey , true , contractAddress )
215
+ GetAddressDetails (ctx , network , c .Args ().First (), privateKey , true , contractAddress , c . String ( "block" ) )
208
216
},
209
217
},
210
218
{
@@ -1151,7 +1159,7 @@ func GetBlockDetails(ctx context.Context, network web3.Network, numberOrHash str
1151
1159
if numberOrHash != "" {
1152
1160
blockN , err = web3 .ParseBigInt (numberOrHash )
1153
1161
if err != nil {
1154
- fatalExit (fmt .Errorf ("Block argument must be a number (decimal integer) or hash (hexadecimal with 0x prefix) %q: %v" , numberOrHash , err ))
1162
+ fatalExit (fmt .Errorf ("Block argument must be a number (decimal integer) %q: %v" , numberOrHash , err ))
1155
1163
}
1156
1164
}
1157
1165
block , err = client .GetBlockByNumber (ctx , blockN , includeTxs )
@@ -1292,7 +1300,7 @@ func printInputData(data []byte, format string) {
1292
1300
}
1293
1301
1294
1302
func GetAddressDetails (ctx context.Context , network web3.Network , addrHash , privateKey string , onlyBalance bool ,
1295
- contractAddress string ) {
1303
+ contractAddress string , blockNumber string ) {
1296
1304
if addrHash == "" {
1297
1305
if privateKey == "" {
1298
1306
fatalExit (errors .New ("Missing address. Must be specified as only argument, or implied from a private key." ))
@@ -1320,12 +1328,22 @@ func GetAddressDetails(ctx context.Context, network web3.Network, addrHash, priv
1320
1328
return
1321
1329
}
1322
1330
1331
+ var blockN * big.Int
1332
+ var err error
1333
+ // Don't try to parse empty string, which means 'latest'.
1334
+ if blockNumber != "" {
1335
+ blockN , err = web3 .ParseBigInt (blockNumber )
1336
+ if err != nil {
1337
+ fatalExit (fmt .Errorf ("Block argument must be a number (decimal integer) %q: %v" , blockNumber , err ))
1338
+ }
1339
+ }
1340
+
1323
1341
client , err := web3 .Dial (network .URL )
1324
1342
if err != nil {
1325
1343
fatalExit (fmt .Errorf ("Failed to connect to %q: %v" , network .URL , err ))
1326
1344
}
1327
1345
defer client .Close ()
1328
- bal , err := client .GetBalance (ctx , addrHash , nil )
1346
+ bal , err := client .GetBalance (ctx , addrHash , blockN )
1329
1347
if err != nil {
1330
1348
fatalExit (fmt .Errorf ("Cannot get address balance from the network: %v" , err ))
1331
1349
}
0 commit comments