Skip to content

Commit

Permalink
Parse all deploy contract arguments (paritytech#289)
Browse files Browse the repository at this point in the history
* parse all deploy contract arguments

* cargo fmt --all
  • Loading branch information
svyatonik authored and bkchr committed Apr 10, 2024
1 parent 7a71279 commit a0555d8
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions bridges/relays/ethereum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,28 @@ fn substrate_sync_params(matches: &clap::ArgMatches) -> Result<SubstrateSyncPara
}

fn ethereum_deploy_contract_params(matches: &clap::ArgMatches) -> Result<EthereumDeployContractParams, String> {
let eth_contract_code = if let Some(eth_contract_code) = matches.value_of("eth-contract-code") {
hex::decode(&eth_contract_code).map_err(|e| format!("Failed to parse eth-contract-code: {}", e))?
} else {
let eth_contract_code = parse_hex_argument(matches, "eth-contract-code")?.unwrap_or_else(|| {
hex::decode(include_str!("../res/substrate-bridge-bytecode.hex")).expect("code is hardcoded, thus valid; qed")
});
let sub_initial_authorities_set_id = match matches.value_of("sub-authorities-set-id") {
Some(sub_initial_authorities_set_id) => Some(
sub_initial_authorities_set_id
.parse()
.map_err(|e| format!("Failed to parse sub-authorities-set-id: {}", e))?,
),
None => None,
};
let sub_initial_authorities_set = parse_hex_argument(matches, "sub-authorities-set")?;
let sub_initial_header = parse_hex_argument(matches, "sub-initial-header")?;

let params = EthereumDeployContractParams {
eth_params: ethereum_connection_params(matches)?,
eth_sign: ethereum_signing_params(matches)?,
sub_params: substrate_connection_params(matches)?,
instance: instance_params(matches)?,
sub_initial_authorities_set_id: None,
sub_initial_authorities_set: None,
sub_initial_header: None,
sub_initial_authorities_set_id,
sub_initial_authorities_set,
sub_initial_header,
eth_contract_code,
};

Expand Down Expand Up @@ -407,3 +415,12 @@ fn instance_params(matches: &clap::ArgMatches) -> Result<Box<dyn BridgeInstance>

Ok(instance)
}

fn parse_hex_argument(matches: &clap::ArgMatches, arg: &str) -> Result<Option<Vec<u8>>, String> {
match matches.value_of(arg) {
Some(value) => Ok(Some(
hex::decode(value).map_err(|e| format!("Failed to parse {}: {}", arg, e))?,
)),
None => Ok(None),
}
}

0 comments on commit a0555d8

Please sign in to comment.