Skip to content

Commit

Permalink
Merge pull request #235 from holaplex/abdul/validate-util-from-core
Browse files Browse the repository at this point in the history
Use Validate address util from hub-core
  • Loading branch information
imabdulbasit authored Sep 20, 2023
2 parents 5e525e3 + 75069f1 commit bb4f8da
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions api/src/mutations/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use hub_core::{
chrono::Utc,
credits::{CreditsClient, TransactionId},
producer::Producer,
util::ValidateAddress,
};
use reqwest::Url;
use sea_orm::{prelude::*, ModelTrait, Set, TransactionTrait};
use serde::{Deserialize, Serialize};
use solana_program::pubkey::Pubkey;

use crate::{
blockchains::{polygon::Polygon, solana::Solana, CollectionEvent},
Expand Down Expand Up @@ -708,7 +708,7 @@ pub fn validate_creators(blockchain: BlockchainEnum, creators: &Vec<Creator>) ->
/// # Errors
/// - Returns an error if the provided address is not a valid Solana address.
pub fn validate_solana_address(address: &str) -> Result<()> {
if Pubkey::from_str(address).is_err() {
if !ValidateAddress::is_solana_address(&address) {
return Err(Error::new(format!(
"{address} is not a valid Solana address"
)));
Expand All @@ -721,21 +721,8 @@ pub fn validate_solana_address(address: &str) -> Result<()> {
/// # Errors
/// - Returns an error if the provided address does not match the required EVM address format.
pub fn validate_evm_address(address: &str) -> Result<()> {
let err = Err(Error::new(format!("{address} is not a valid EVM address")));

// Ethereum address must start with '0x'
if !address.starts_with("0x") {
return err;
}

// Ethereum address must be exactly 40 characters long after removing '0x'
if address.len() != 42 {
return err;
}

// Check that the address contains only hexadecimal characters
if !address[2..].chars().all(|c| c.is_ascii_hexdigit()) {
return err;
if !ValidateAddress::is_evm_address(&address) {
return Err(Error::new(format!("{address} is not a valid EVM address")));
}

Ok(())
Expand Down

0 comments on commit bb4f8da

Please sign in to comment.