-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Misc]: Add WalletCore binary binary tools (#3865)
* [Misc]: Add wallet_core_bin crate with binary tools * Add `registry-stats` command * [Misc]: Add a helper function to `tools/registry` * [Misc]: Fix build and test scripts * [Misc]: Fix linux-ci-rust CI * [Misc]: Use a script in linux-ci-rust.yml * [Misc]: Fix linux-ci-rust.yml
- Loading branch information
1 parent
a3d763b
commit 55ca3e5
Showing
11 changed files
with
160 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ members = [ | |
"tw_number", | ||
"tw_proto", | ||
"tw_utxo", | ||
"wallet_core_bin", | ||
"wallet_core_rs", | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "wallet_core_bin" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
serde = "1.0" | ||
serde_json = "1.0" | ||
tw_coin_registry = { path = "../tw_coin_registry" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
mod registry_stats; | ||
|
||
#[derive(Debug)] | ||
enum Error { | ||
MissingArguments, | ||
UnknownCommand, | ||
InvalidRegistry, | ||
InvalidRegistryParam { | ||
#[allow(dead_code)] | ||
param: &'static str, | ||
}, | ||
} | ||
|
||
fn help() { | ||
println!("WalletCore binary tools:"); | ||
println!(); | ||
println!("\tregistry-stats Print registry statistic (e.g Rust transition progress)"); | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
let args: Vec<String> = std::env::args().collect(); | ||
|
||
if args.len() < 2 { | ||
help(); | ||
return Err(Error::MissingArguments); | ||
} | ||
|
||
match args[1].as_str() { | ||
"registry-stats" => registry_stats::registry_stats(), | ||
_ => { | ||
help(); | ||
Err(Error::UnknownCommand) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use crate::Error; | ||
use serde_json::Value as Json; | ||
use std::collections::HashSet; | ||
use tw_coin_registry::blockchain_type::BlockchainType; | ||
use tw_coin_registry::registry; | ||
|
||
struct BlockchainStats { | ||
total: usize, | ||
supported: usize, | ||
} | ||
|
||
fn blockchain_stats() -> Result<BlockchainStats, Error> { | ||
let chains: Vec<Json> = | ||
serde_json::from_str(registry::REGISTRY_JSON).map_err(|_| Error::InvalidRegistry)?; | ||
|
||
fn extract_blockchain(chain: &Json) -> Option<(&str, BlockchainType)> { | ||
let blockchain_val = chain.get("blockchain")?; | ||
let blockchain_str = chain["blockchain"].as_str()?; | ||
let blockchain_type: BlockchainType = | ||
serde_json::from_value(blockchain_val.clone()).ok()?; | ||
Some((blockchain_str, blockchain_type)) | ||
} | ||
|
||
let mut supported = HashSet::new(); | ||
let mut total = HashSet::new(); | ||
|
||
for chain in chains.iter() { | ||
let (blockchain_str, blockchain_type) = | ||
extract_blockchain(chain).ok_or(Error::InvalidRegistryParam { | ||
param: "blockchain", | ||
})?; | ||
|
||
total.insert(blockchain_str); | ||
match blockchain_type { | ||
BlockchainType::Unsupported => (), | ||
_ => { | ||
supported.insert(blockchain_str); | ||
}, | ||
} | ||
} | ||
|
||
Ok(BlockchainStats { | ||
total: total.len(), | ||
supported: supported.len(), | ||
}) | ||
} | ||
|
||
pub fn registry_stats() -> Result<(), Error> { | ||
let total_chains = registry::registry_iter().count(); | ||
let chains_in_rust = registry::supported_coin_items().count(); | ||
let rust_chains_progress = (chains_in_rust * 100) as f64 / total_chains as f64; | ||
|
||
let blockchain_stats = blockchain_stats()?; | ||
let blockchain_progress = | ||
(blockchain_stats.supported * 100) as f64 / blockchain_stats.total as f64; | ||
|
||
println!(); | ||
println!("total chains: {total_chains}"); | ||
println!("supported chains: {chains_in_rust}"); | ||
println!("chains transition progress: {rust_chains_progress:.1}%"); | ||
|
||
println!(); | ||
println!("total blockchain impls: {}", blockchain_stats.total); | ||
println!("supported blockchain impls: {}", blockchain_stats.supported); | ||
println!("blockchains transition progress: {blockchain_progress:.1}%"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters