Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Validate address util from hub-core #235

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading