From c8511eb4a762f528ced7845a8862d2bd7833b622 Mon Sep 17 00:00:00 2001 From: Greg Nazario Date: Wed, 16 Oct 2024 19:12:21 -0400 Subject: [PATCH] [rosetta] Remove supported currencies with an empty symbol (#14973) --- crates/aptos-rosetta/src/main.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/aptos-rosetta/src/main.rs b/crates/aptos-rosetta/src/main.rs index 11574dd66ca18..d652ef09254c1 100644 --- a/crates/aptos-rosetta/src/main.rs +++ b/crates/aptos-rosetta/src/main.rs @@ -9,6 +9,7 @@ use aptos_config::config::{ApiConfig, DEFAULT_MAX_PAGE_SIZE}; use aptos_logger::prelude::*; use aptos_node::AptosNodeArgs; use aptos_rosetta::{bootstrap, common::native_coin, types::Currency}; +use aptos_sdk::move_types::language_storage::StructTag; use aptos_types::chain_id::ChainId; use clap::Parser; use std::{ @@ -16,6 +17,7 @@ use std::{ fs::File, net::SocketAddr, path::PathBuf, + str::FromStr, sync::{ atomic::{AtomicBool, Ordering}, Arc, @@ -243,9 +245,28 @@ impl ServerArgs for OfflineArgs { if let Some(ref filepath) = self.currency_config_file { let file = File::open(filepath).unwrap(); let currencies: Vec = serde_json::from_reader(file).unwrap(); - currencies.into_iter().for_each(|item| { - supported_currencies.insert(item); - }); + for item in currencies.into_iter() { + // Do a safety check on possible currencies on startup + if item.symbol.as_str() == "" { + warn!( + "Currency {:?} has an empty symbol, and is being skipped", + item + ); + } else if let Some(metadata) = item.metadata.as_ref() { + if let Some(move_type) = metadata.move_type.as_ref() { + if StructTag::from_str(move_type).is_ok() { + supported_currencies.insert(item); + continue; + } + } + warn!( + "Currency {:?} has an invalid metadata coin type, and is being skipped", + item + ); + } else { + supported_currencies.insert(item); + } + } } supported_currencies