fedimovies/src/ethereum/utils.rs

25 lines
559 B
Rust
Raw Normal View History

2021-04-09 00:22:17 +00:00
use std::str::FromStr;
use secp256k1::SecretKey;
2021-04-09 00:22:17 +00:00
use web3::{
signing::Key,
2021-04-09 00:22:17 +00:00
types::Address,
};
pub fn key_to_ethereum_address(private_key: &SecretKey) -> Address {
private_key.address()
2021-04-09 00:22:17 +00:00
}
#[derive(thiserror::Error, Debug)]
#[error("address error")]
pub struct AddressError;
pub fn parse_address(address: &str) -> Result<Address, AddressError> {
Address::from_str(address).map_err(|_| AddressError)
}
/// Converts address object to lowercase hex string
pub fn address_to_string(address: Address) -> String {
format!("{:#x}", address)
}