Skip to content

Commit 148ba4e

Browse files
committed
Removed the unnecessary size check of the hexadecimal balance.
1 parent e2382e7 commit 148ba4e

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

rust/basic_ethereum/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub async fn get_balance(address: String) -> Nat {
6161

6262
let hex_balance = match response {
6363
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:
6565
// { "id": "[ID]", "jsonrpc": "2.0", "result": "[BALANCE IN HEX]" }
6666
let response: serde_json::Value = serde_json::from_str(&balance_result).unwrap();
6767
response
@@ -73,14 +73,8 @@ pub async fn get_balance(address: String) -> Nat {
7373
RequestResult::Err(e) => panic!("Received an error response: {:?}", e),
7474
};
7575

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())
8478
}
8579

8680
#[update]

0 commit comments

Comments
 (0)