Move address_to_string to ethereum::utils module

This commit is contained in:
silverpill 2022-04-16 21:22:07 +00:00
parent c0837bbf77
commit 0d6807e5a2
3 changed files with 9 additions and 8 deletions

View file

@ -4,6 +4,7 @@ use siwe::Message;
use web3::types::H160; use web3::types::H160;
use crate::errors::ValidationError; use crate::errors::ValidationError;
use super::utils::address_to_string;
/// Verifies EIP-4361 signature and returns wallet address /// Verifies EIP-4361 signature and returns wallet address
pub fn verify_eip4361_signature( pub fn verify_eip4361_signature(
@ -30,7 +31,7 @@ pub fn verify_eip4361_signature(
return Err(ValidationError("message shouldn't have expiration time")); return Err(ValidationError("message shouldn't have expiration time"));
}; };
// Return wallet address in lower case // Return wallet address in lower case
let wallet_address = format!("{:#x}", H160(message.address)); let wallet_address = address_to_string(H160(message.address));
Ok(wallet_address) Ok(wallet_address)
} }

View file

@ -7,7 +7,7 @@ use web3::{
contract::Contract, contract::Contract,
ethabi::RawLog, ethabi::RawLog,
transports::Http, transports::Http,
types::{Address, BlockId, BlockNumber, FilterBuilder, U256}, types::{BlockId, BlockNumber, FilterBuilder, U256},
}; };
use crate::config::BlockchainConfig; use crate::config::BlockchainConfig;
@ -25,12 +25,7 @@ use crate::models::users::queries::get_user_by_wallet_address;
use crate::models::users::types::WALLET_CURRENCY_CODE; use crate::models::users::types::WALLET_CURRENCY_CODE;
use super::errors::EthereumError; use super::errors::EthereumError;
use super::signatures::{sign_contract_call, CallArgs, SignatureData}; use super::signatures::{sign_contract_call, CallArgs, SignatureData};
use super::utils::parse_address; use super::utils::{address_to_string, parse_address};
/// Converts address object to lowercase hex string
fn address_to_string(address: Address) -> String {
format!("{:#x}", address)
}
fn u256_to_date(value: U256) -> Result<DateTime<Utc>, ConversionError> { fn u256_to_date(value: U256) -> Result<DateTime<Utc>, ConversionError> {
let timestamp: i64 = value.try_into().map_err(|_| ConversionError)?; let timestamp: i64 = value.try_into().map_err(|_| ConversionError)?;

View file

@ -45,6 +45,11 @@ pub fn parse_address(address: &str) -> Result<Address, AddressError> {
Address::from_str(address).map_err(|_| 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)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;