Skip to content

Commit c8511eb

Browse files
authored
[rosetta] Remove supported currencies with an empty symbol (#14973)
1 parent fa4d47c commit c8511eb

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

crates/aptos-rosetta/src/main.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ use aptos_config::config::{ApiConfig, DEFAULT_MAX_PAGE_SIZE};
99
use aptos_logger::prelude::*;
1010
use aptos_node::AptosNodeArgs;
1111
use aptos_rosetta::{bootstrap, common::native_coin, types::Currency};
12+
use aptos_sdk::move_types::language_storage::StructTag;
1213
use aptos_types::chain_id::ChainId;
1314
use clap::Parser;
1415
use std::{
1516
collections::HashSet,
1617
fs::File,
1718
net::SocketAddr,
1819
path::PathBuf,
20+
str::FromStr,
1921
sync::{
2022
atomic::{AtomicBool, Ordering},
2123
Arc,
@@ -243,9 +245,28 @@ impl ServerArgs for OfflineArgs {
243245
if let Some(ref filepath) = self.currency_config_file {
244246
let file = File::open(filepath).unwrap();
245247
let currencies: Vec<Currency> = serde_json::from_reader(file).unwrap();
246-
currencies.into_iter().for_each(|item| {
247-
supported_currencies.insert(item);
248-
});
248+
for item in currencies.into_iter() {
249+
// Do a safety check on possible currencies on startup
250+
if item.symbol.as_str() == "" {
251+
warn!(
252+
"Currency {:?} has an empty symbol, and is being skipped",
253+
item
254+
);
255+
} else if let Some(metadata) = item.metadata.as_ref() {
256+
if let Some(move_type) = metadata.move_type.as_ref() {
257+
if StructTag::from_str(move_type).is_ok() {
258+
supported_currencies.insert(item);
259+
continue;
260+
}
261+
}
262+
warn!(
263+
"Currency {:?} has an invalid metadata coin type, and is being skipped",
264+
item
265+
);
266+
} else {
267+
supported_currencies.insert(item);
268+
}
269+
}
249270
}
250271

251272
supported_currencies

0 commit comments

Comments
 (0)