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

Add other all blockchair and fix noble path #214

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
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
41 changes: 27 additions & 14 deletions crates/primitives/src/block_explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,30 @@ pub fn get_block_explorers(chain: Chain) -> Vec<Box<dyn BlockExplorer>> {
EtherScan::new(EVMChain::Ethereum),
Blockchair::new_ethereum(),
],
Chain::SmartChain => vec![EtherScan::new(EVMChain::SmartChain)],
Chain::Polygon => vec![EtherScan::new(EVMChain::Polygon)],
Chain::Arbitrum => vec![EtherScan::new(EVMChain::Arbitrum)],
Chain::Optimism => vec![EtherScan::new(EVMChain::Optimism)],
Chain::SmartChain => vec![EtherScan::new(EVMChain::SmartChain), Blockchair::new_bnb()],
Chain::Polygon => vec![EtherScan::new(EVMChain::Polygon), Blockchair::new_polygon()],
Chain::Arbitrum => vec![
EtherScan::new(EVMChain::Arbitrum),
Blockchair::new_arbitrum(),
],
Chain::Optimism => vec![
EtherScan::new(EVMChain::Optimism),
Blockchair::new_optimism(),
],
Chain::Base => vec![EtherScan::new(EVMChain::Base), Blockchair::new_base()],
Chain::AvalancheC => vec![EtherScan::new(EVMChain::AvalancheC)],
Chain::OpBNB => vec![EtherScan::new(EVMChain::OpBNB)],
Chain::Fantom => vec![EtherScan::new(EVMChain::Fantom)],
Chain::Gnosis => vec![EtherScan::new(EVMChain::Gnosis)],
Chain::AvalancheC => vec![
EtherScan::new(EVMChain::AvalancheC),
Blockchair::new_avalanche(),
],
Chain::OpBNB => vec![EtherScan::new(EVMChain::OpBNB), Blockchair::new_opbnb()],
Chain::Fantom => vec![EtherScan::new(EVMChain::Fantom), Blockchair::new_fantom()],
Chain::Gnosis => vec![EtherScan::new(EVMChain::Gnosis), Blockchair::new_gnosis()],
Chain::Manta => vec![BlockScout::new_manta(), EtherScan::new(EVMChain::Manta)],
Chain::Blast => vec![EtherScan::new(EVMChain::Blast)],
Chain::Linea => vec![EtherScan::new(EVMChain::Linea)],
Chain::Linea => vec![EtherScan::new(EVMChain::Linea), Blockchair::new_linea()],
Chain::Celo => vec![BlockScout::new_celo(), EtherScan::new(EVMChain::Celo)],
Chain::ZkSync => vec![ZkSync::new(), EtherScan::new(EVMChain::ZkSync)],
Chain::Solana => vec![SolanaFM::new(), Solscan::new()],
Chain::Solana => vec![SolanaFM::new(), Solscan::new(), Blockchair::new_solana()],
Chain::Thorchain => vec![Viewblock::new()],

Chain::Cosmos => vec![MintScan::new_cosmos()],
Expand All @@ -68,10 +77,14 @@ pub fn get_block_explorers(chain: Chain) -> Vec<Box<dyn BlockExplorer>> {
Chain::Noble => vec![MintScan::new_noble()],
Chain::Mantle => vec![MantleExplorer::new(), EtherScan::new(EVMChain::Mantle)],

Chain::Ton => vec![TonViewer::new(), TonScan::new()],
Chain::Tron => vec![TronScan::new()],
Chain::Xrp => vec![XrpScan::new()],
Chain::Aptos => vec![AptosExplorer::new(), AptosScan::new()],
Chain::Ton => vec![TonViewer::new(), TonScan::new(), Blockchair::new_ton()],
Chain::Tron => vec![TronScan::new(), Blockchair::new_tron()],
Chain::Xrp => vec![XrpScan::new(), Blockchair::new_xrp()],
Chain::Aptos => vec![
AptosExplorer::new(),
AptosScan::new(),
Blockchair::new_aptos(),
],
Chain::Sui => vec![SuiScan::new(), SuiVision::new()],
Chain::Near => vec![NearBlocks::new()],
}
Expand Down
126 changes: 126 additions & 0 deletions crates/primitives/src/explorers/blockchair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,132 @@ impl Blockchair {
},
})
}

pub fn new_bnb() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("bnb"),
},
})
}

pub fn new_polygon() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("polygon"),
},
})
}

pub fn new_arbitrum() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("arbitrum-one"),
},
})
}

pub fn new_optimism() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("optimism"),
},
})
}

pub fn new_avalanche() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("avalanche"),
},
})
}

pub fn new_opbnb() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("opbnb"),
},
})
}

pub fn new_fantom() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("fantom"),
},
})
}

pub fn new_gnosis() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("gnosis-chain"),
},
})
}

pub fn new_linea() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("linea"),
},
})
}

pub fn new_solana() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("solana"),
},
})
}

pub fn new_ton() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("ton"),
},
})
}

pub fn new_tron() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("tron"),
},
})
}

pub fn new_xrp() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("xrp-ledger"),
},
})
}

pub fn new_aptos() -> Box<Self> {
Box::new(Self {
meta: Metadata {
name: BLOCKCHAIR_NAME,
base_url: blockchair_url!("aptos"),
},
})
}
}

impl BlockExplorer for Blockchair {
Expand Down
8 changes: 4 additions & 4 deletions crates/primitives/src/explorers/mintscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ static MINTSCAN_NAME: &str = "Mintscan";

macro_rules! mintscan_url {
($chain:expr) => {
concat!("https://mintscan.io/", $chain)
concat!("https://www.mintscan.io/", $chain)
};
}

Expand Down Expand Up @@ -62,7 +62,7 @@ impl MintScan {
Box::new(Self {
meta: Metadata {
name: MINTSCAN_NAME,
base_url: mintscan_url!("mantle"),
base_url: mintscan_url!("noble"),
},
})
}
Expand All @@ -76,9 +76,9 @@ impl BlockExplorer for MintScan {
format!("{}/tx/{}", self.meta.base_url, hash)
}
fn get_address_url(&self, address: &str) -> String {
format!("{}/account/{}", self.meta.base_url, address)
format!("{}/address/{}", self.meta.base_url, address)
}
fn get_token_url(&self, _token: &str) -> Option<String> {
None
format!("{}/assets/{}", self.meta.base_url, _token).into()
}
}
51 changes: 46 additions & 5 deletions gemstone/src/block_explorer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mod tests {

assert_eq!(explorers.len(), 2);
assert_eq!(explorers[0].name(), "Etherscan");
assert_eq!(explorers[1].name(), "Blockchair");

let explorer = Explorer::new(chain.as_ref());
let account_url = explorer.get_address_url(
Expand Down Expand Up @@ -109,8 +110,10 @@ mod tests {
let chain = Chain::Ton;
let explorers = get_block_explorers(chain);

assert_eq!(explorers.len(), 2);
assert_eq!(explorers.len(), 3);
assert_eq!(explorers[0].name(), "TonViewer");
assert_eq!(explorers[1].name(), "Tonscan");
assert_eq!(explorers[2].name(), "Blockchair");

let explorer = Explorer::new(chain.as_ref());
let account_url = explorer.get_address_url(
Expand Down Expand Up @@ -143,7 +146,7 @@ mod tests {
let chain = Chain::Solana;
let explorers = get_block_explorers(chain);

assert_eq!(explorers.len(), 2);
assert_eq!(explorers.len(), 3);
assert_eq!(explorers[0].name(), "SolanaFM");
assert_eq!(explorers[1].name(), "Solscan");

Expand Down Expand Up @@ -198,17 +201,55 @@ mod tests {
&explorers[0].name(),
"CFB4B38D75DB9D9055A7D4A2A76C67B8A27C37124C4E5663BEE104589E726763",
);
let asset_url = explorer
.get_token_url(
&explorers[0].name(),
"ibc/0025F8A87464A471E66B234C4F93AEC5B4DA3D42D7986451A059273426290DD5",
)
.unwrap();

assert_eq!(
account_url,
"https://mintscan.io/cosmos/account/cosmos1fxygpgus4nd5jmfl5j7fh5y8hyy53z8u95dzx7"
"https://www.mintscan.io/cosmos/address/cosmos1fxygpgus4nd5jmfl5j7fh5y8hyy53z8u95dzx7"
);
assert_eq!(
tx_url,
"https://mintscan.io/cosmos/tx/CFB4B38D75DB9D9055A7D4A2A76C67B8A27C37124C4E5663BEE104589E726763"
"https://www.mintscan.io/cosmos/tx/CFB4B38D75DB9D9055A7D4A2A76C67B8A27C37124C4E5663BEE104589E726763"
);
assert_eq!(
asset_url,
"https://www.mintscan.io/cosmos/assets/ibc/0025F8A87464A471E66B234C4F93AEC5B4DA3D42D7986451A059273426290DD5"
)
}

#[test]
fn test_noble_explorer() {
let chain = Chain::Noble;
let explorers = get_block_explorers(chain);

assert_eq!(explorers.len(), 1);
assert_eq!(explorers[0].name(), "Mintscan");

let explorer = Explorer::new(chain.as_ref());
let account_url = explorer.get_address_url(
&explorers[0].name(),
"noble17w8y9eujrz4m08nn0h349s5h2rs8uz5hqe02z4",
);
let tx_url = explorer.get_transaction_url(
&explorers[0].name(),
"22F0B4F48A85925A668D64134B7377476DC5BAE3CF7CC38AFC0E17E5F7D90001",
);

assert_eq!(
account_url,
"https://www.mintscan.io/noble/address/noble17w8y9eujrz4m08nn0h349s5h2rs8uz5hqe02z4"
);
assert_eq!(
tx_url,
"https://www.mintscan.io/noble/tx/22F0B4F48A85925A668D64134B7377476DC5BAE3CF7CC38AFC0E17E5F7D90001"
);
}

#[test]
fn test_sui_vision() {
let chain = Chain::Sui;
Expand Down Expand Up @@ -256,7 +297,7 @@ mod tests {
let chain = Chain::Tron;
let explorers = get_block_explorers(chain);

assert_eq!(explorers.len(), 1);
assert_eq!(explorers.len(), 2);
assert_eq!(explorers[0].name(), "TRONSCAN");

let explorer = Explorer::new(chain.as_ref());
Expand Down
Loading