From de0184e253a6eff86d6b130b9c10b0e1d04197e6 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Fri, 1 Jan 2021 22:34:57 +0800 Subject: [PATCH] style: format --- __crypto/simple_contract/src/cmd_credit_create.rs | 2 ++ __crypto/simple_contract/src/cmd_credit_issue.rs | 2 ++ __crypto/simple_contract/src/cmd_credit_query.rs | 2 ++ __crypto/simple_contract/src/cmd_credit_queryall.rs | 2 ++ __crypto/simple_contract/src/cmd_credit_transfer.rs | 2 ++ __crypto/simple_contract/src/cmd_default.rs | 2 ++ __crypto/simple_contract/src/cmd_genkey.rs | 6 +++++- __crypto/simple_contract/src/util.rs | 4 +++- 8 files changed, 20 insertions(+), 2 deletions(-) diff --git a/__crypto/simple_contract/src/cmd_credit_create.rs b/__crypto/simple_contract/src/cmd_credit_create.rs index e72df8d..3668389 100644 --- a/__crypto/simple_contract/src/cmd_credit_create.rs +++ b/__crypto/simple_contract/src/cmd_credit_create.rs @@ -9,12 +9,14 @@ use crate::engine_plugin_credit::CreditContractCreateParameters; pub struct CommandImpl; impl Command for CommandImpl { fn name(&self) -> &str { "create" } + fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()).about("Create credit contract subcommand") .arg(Arg::with_name("name").long("name").short("n").required(true).takes_value(true).help("Contract name")) .arg(Arg::with_name("limit").long("limit").short("l").required(true).takes_value(true).help("Contract credit limit")) .arg(Arg::with_name("key").long("key").short("k").required(true).takes_value(true).help("Key pair")) } + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let name = sub_arg_matches.value_of("name").unwrap(); let limit = sub_arg_matches.value_of("limit").unwrap(); diff --git a/__crypto/simple_contract/src/cmd_credit_issue.rs b/__crypto/simple_contract/src/cmd_credit_issue.rs index eff0fb0..57aadc8 100644 --- a/__crypto/simple_contract/src/cmd_credit_issue.rs +++ b/__crypto/simple_contract/src/cmd_credit_issue.rs @@ -9,6 +9,7 @@ use crate::engine_plugin_credit::CreditContractIssueParameters; pub struct CommandImpl; impl Command for CommandImpl { fn name(&self) -> &str { "issue" } + fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()).about("Issue credit contract subcommand") .arg(Arg::with_name("name").long("name").short("n").required(true).takes_value(true).help("Contract name")) @@ -16,6 +17,7 @@ impl Command for CommandImpl { .arg(Arg::with_name("credit").long("credit").short("c").required(true).takes_value(true).help("Credit")) .arg(Arg::with_name("key").long("key").short("k").required(true).takes_value(true).help("Key pair")) } + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let name = sub_arg_matches.value_of("name").unwrap(); let receiver = sub_arg_matches.value_of("receiver").unwrap(); diff --git a/__crypto/simple_contract/src/cmd_credit_query.rs b/__crypto/simple_contract/src/cmd_credit_query.rs index 154993c..b1aeb73 100644 --- a/__crypto/simple_contract/src/cmd_credit_query.rs +++ b/__crypto/simple_contract/src/cmd_credit_query.rs @@ -9,12 +9,14 @@ use crate::engine_plugin_credit::CreditContractQueryParameters; pub struct CommandImpl; impl Command for CommandImpl { fn name(&self) -> &str { "query" } + fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()).about("Query credit contract subcommand") .arg(Arg::with_name("name").long("name").short("n").required(true).takes_value(true).help("Contract name")) .arg(Arg::with_name("account").long("account").short("a").required(true).takes_value(true).help("Account")) .arg(Arg::with_name("key").long("key").short("k").required(true).takes_value(true).help("Key pair")) } + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let name = sub_arg_matches.value_of("name").unwrap(); let account = sub_arg_matches.value_of("account").unwrap(); diff --git a/__crypto/simple_contract/src/cmd_credit_queryall.rs b/__crypto/simple_contract/src/cmd_credit_queryall.rs index c5ea074..f70fcd4 100644 --- a/__crypto/simple_contract/src/cmd_credit_queryall.rs +++ b/__crypto/simple_contract/src/cmd_credit_queryall.rs @@ -9,11 +9,13 @@ use crate::engine_plugin_credit::CreditContractQueryAllParameters; pub struct CommandImpl; impl Command for CommandImpl { fn name(&self) -> &str { "queryall" } + fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()).about("Queryall credit contract subcommand") .arg(Arg::with_name("name").long("name").short("n").required(true).takes_value(true).help("Contract name")) .arg(Arg::with_name("key").long("key").short("k").required(true).takes_value(true).help("Key pair")) } + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let name = sub_arg_matches.value_of("name").unwrap(); let key = sub_arg_matches.value_of("key").unwrap(); diff --git a/__crypto/simple_contract/src/cmd_credit_transfer.rs b/__crypto/simple_contract/src/cmd_credit_transfer.rs index 1a995a7..3daf4b4 100644 --- a/__crypto/simple_contract/src/cmd_credit_transfer.rs +++ b/__crypto/simple_contract/src/cmd_credit_transfer.rs @@ -9,6 +9,7 @@ use crate::engine_plugin_credit::CreditContractTransferParameters; pub struct CommandImpl; impl Command for CommandImpl { fn name(&self) -> &str { "transfer" } + fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()).about("Transfer credit contract subcommand") .arg(Arg::with_name("name").long("name").short("n").required(true).takes_value(true).help("Contract name")) @@ -16,6 +17,7 @@ impl Command for CommandImpl { .arg(Arg::with_name("credit").long("credit").short("c").required(true).takes_value(true).help("Credit")) .arg(Arg::with_name("key").long("key").short("k").required(true).takes_value(true).help("Key pair")) } + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let name = sub_arg_matches.value_of("name").unwrap(); let receiver = sub_arg_matches.value_of("receiver").unwrap(); diff --git a/__crypto/simple_contract/src/cmd_default.rs b/__crypto/simple_contract/src/cmd_default.rs index 6618764..7e8925a 100644 --- a/__crypto/simple_contract/src/cmd_default.rs +++ b/__crypto/simple_contract/src/cmd_default.rs @@ -3,9 +3,11 @@ use crate::cmd::CommandError; pub struct CommandImpl; impl CommandImpl { + pub fn process_command<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app.arg(Arg::with_name("verbose").long("verbose").short("v").multiple(true).help("Show verbose info")) } + pub fn run(arg_matches: &ArgMatches) -> CommandError { let verbose_count = arg_matches.occurrences_of("verbose"); information!("Verbose count: {}", verbose_count); diff --git a/__crypto/simple_contract/src/cmd_genkey.rs b/__crypto/simple_contract/src/cmd_genkey.rs index f516dc9..f762957 100644 --- a/__crypto/simple_contract/src/cmd_genkey.rs +++ b/__crypto/simple_contract/src/cmd_genkey.rs @@ -7,18 +7,22 @@ use crate::util::{JsonKeyPair, make_key_pair}; pub struct CommandImpl; impl Command for CommandImpl { fn name(&self) -> &str { "genkey" } + fn subcommand<'a>(&self) -> App<'a, 'a> { SubCommand::with_name(self.name()).about("Generate key pair subcommand") .arg(Arg::with_name("output").long("output").short("o").required(true).takes_value(true).help("Key pair output")) + .arg(Arg::with_name("tag").long("tag").short("t").takes_value(true).help("Key pair output")) } + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { let output = sub_arg_matches.value_of("output").unwrap(); + let tag = sub_arg_matches.value_of("tag"); if let Ok(_) = File::open(output) { failure!("Output file exists: {}", output); return Ok(()); } let (pri_key, pub_key) = make_key_pair(); - let json_key_pair = JsonKeyPair::from(pri_key, pub_key); + let json_key_pair = JsonKeyPair::from(pri_key, pub_key, tag.map(|t| t.into())); fs::write(output, json_key_pair.to_json()?.as_bytes())?; Ok(()) } diff --git a/__crypto/simple_contract/src/util.rs b/__crypto/simple_contract/src/util.rs index 598fd63..8379cbe 100644 --- a/__crypto/simple_contract/src/util.rs +++ b/__crypto/simple_contract/src/util.rs @@ -10,14 +10,16 @@ use std::str::FromStr; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct JsonKeyPair { + pub tag: Option, pub identity: String, pub pri_key: String, pub pub_key: String, } impl JsonKeyPair { - pub fn from(pri_key: SecretKey, pub_key: PublicKey) -> Self { + pub fn from(pri_key: SecretKey, pub_key: PublicKey, tag: Option) -> Self { JsonKeyPair { + tag, identity: make_btc_address(&pub_key), pri_key: format!("{}", pri_key), pub_key: format!("{}", pub_key),