Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Aug 5, 2024
1 parent 463eb67 commit a0d54d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
14 changes: 13 additions & 1 deletion crates/subcoin-node/src/cli/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ pub enum Chain {
BitcoinSignet,
}

impl Chain {
/// Returns the value of `id` in `SubstrateCli::load_spec(id)`.
fn chain_spec_id(&self) -> &'static str {
// Convert to kebab-case for consistency in CLI.
match self {
Self::BitcoinMainnet => "bitcoin-mainnet",
Self::BitcoinTestnet => "bitcoin-testnet",
Self::BitcoinSignet => "bitcoin-signet",
}
}
}

#[derive(Debug, Clone, Parser)]
pub struct NetworkParams {
/// Specify the remote peer address to connect.
Expand Down Expand Up @@ -107,7 +119,7 @@ impl CommonParams {
pub fn as_shared_params(&self) -> sc_cli::SharedParams {
// TODO: expose more flags?
sc_cli::SharedParams {
chain: Some(format!("{:?}", self.chain)),
chain: Some(self.chain.chain_spec_id().to_string()),
dev: false,
base_path: self.base_path.clone(),
log: self.log.clone(),
Expand Down
14 changes: 4 additions & 10 deletions crates/subcoin-node/src/substrate_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use subcoin_service::ChainSpec;

const BITCOIN_MAINNET_CHAIN_SPEC: &str = include_str!("../res/chain-spec-raw-bitcoin-mainnet.json");

fn chain_spec_bitcoin_mainnet() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(BITCOIN_MAINNET_CHAIN_SPEC.as_bytes())
}

/// Fake CLI for satisfying the Substrate CLI interface.
///
/// Primarily for creating a Substrate runner.
Expand Down Expand Up @@ -38,13 +34,11 @@ impl sc_cli::SubstrateCli for SubstrateCli {
}

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
// TODO: different chain spec for different bitcoin network.
// parse network from id
// The chain spec here does not impact the chain but only for showing the proper
// network type on explorer.

let chain_spec = match id {
"bitcoin-mainnet" => chain_spec_bitcoin_mainnet()?,
"bitcoin-mainnet" => ChainSpec::from_json_bytes(BITCOIN_MAINNET_CHAIN_SPEC.as_bytes())?,
"bitcoin-testnet" | "bitcoin-signet" => {
unimplemented!("Bitcoin testnet and signet are unsupported")
}
path => ChainSpec::from_json_file(std::path::PathBuf::from(path))?,
};

Expand Down

0 comments on commit a0d54d3

Please sign in to comment.