File tree Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Expand file tree Collapse file tree 1 file changed +3
-9
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ pub async fn get_balance(address: String) -> Nat {
61
61
62
62
let hex_balance = match response {
63
63
RequestResult :: Ok ( balance_result) => {
64
- // The response to a successful `eth_getBalance` call has the format
64
+ // The response to a successful `eth_getBalance` call has the following format:
65
65
// { "id": "[ID]", "jsonrpc": "2.0", "result": "[BALANCE IN HEX]" }
66
66
let response: serde_json:: Value = serde_json:: from_str ( & balance_result) . unwrap ( ) ;
67
67
response
@@ -73,14 +73,8 @@ pub async fn get_balance(address: String) -> Nat {
73
73
RequestResult :: Err ( e) => panic ! ( "Received an error response: {:?}" , e) ,
74
74
} ;
75
75
76
- // Make sure that the number of digits is even and remove the "0x" prefix.
77
- let hex_balance = if hex_balance. len ( ) % 2 != 0 {
78
- format ! ( "0{}" , & hex_balance[ 2 ..] )
79
- } else {
80
- hex_balance[ 2 ..] . to_string ( )
81
- } ;
82
-
83
- Nat ( BigUint :: from_str_radix ( & hex_balance, 16 ) . unwrap ( ) )
76
+ // Remove the "0x" prefix before converting to a decimal number.
77
+ Nat ( BigUint :: from_str_radix ( & hex_balance[ 2 ..] , 16 ) . unwrap ( ) )
84
78
}
85
79
86
80
#[ update]
You can’t perform that action at this time.
0 commit comments