From f155d6658a047bbb751fcffd231f24cc5dd7d389 Mon Sep 17 00:00:00 2001 From: aya015757881 <2581015450@qq.com> Date: Mon, 25 Nov 2024 11:09:21 +0800 Subject: [PATCH] fix: prepend 0x to ETH address --- Cargo.lock | 2 +- crates/anychain-ethereum/Cargo.toml | 2 +- crates/anychain-ethereum/src/address.rs | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0760023..6b6887c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,7 +188,7 @@ dependencies = [ [[package]] name = "anychain-ethereum" -version = "0.1.20" +version = "0.1.21" dependencies = [ "anychain-core", "ethabi", diff --git a/crates/anychain-ethereum/Cargo.toml b/crates/anychain-ethereum/Cargo.toml index 1ef031d..85c60eb 100644 --- a/crates/anychain-ethereum/Cargo.toml +++ b/crates/anychain-ethereum/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "anychain-ethereum" description = "A Rust library for Ethereum-focused cryptocurrency wallets, enabling seamless transactions on the Ethereum blockchain" -version = "0.1.20" +version = "0.1.21" keywords = ["blockchain", "crypto", "ethereum", "wallet"] categories = ["cryptography::cryptocurrencies"] diff --git a/crates/anychain-ethereum/src/address.rs b/crates/anychain-ethereum/src/address.rs index 7f83963..a6a1b2e 100644 --- a/crates/anychain-ethereum/src/address.rs +++ b/crates/anychain-ethereum/src/address.rs @@ -94,7 +94,10 @@ impl FromStr for EthereumAddress { } let addr = addr.to_lowercase(); let _ = hex::decode(addr)?; - Ok(EthereumAddress(address.to_string())) + match address.starts_with("0x") { + true => Ok(EthereumAddress(address.to_string())), + false => Ok(EthereumAddress(format!("0x{}", address))), + } } }