style: format

This commit is contained in:
2021-01-01 22:34:57 +08:00
parent ba35489cdf
commit de0184e253
8 changed files with 20 additions and 2 deletions

View File

@@ -9,12 +9,14 @@ use crate::engine_plugin_credit::CreditContractCreateParameters;
pub struct CommandImpl; pub struct CommandImpl;
impl Command for CommandImpl { impl Command for CommandImpl {
fn name(&self) -> &str { "create" } fn name(&self) -> &str { "create" }
fn subcommand<'a>(&self) -> App<'a, 'a> { fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Create credit contract subcommand") 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("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("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")) .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 { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
let name = sub_arg_matches.value_of("name").unwrap(); let name = sub_arg_matches.value_of("name").unwrap();
let limit = sub_arg_matches.value_of("limit").unwrap(); let limit = sub_arg_matches.value_of("limit").unwrap();

View File

@@ -9,6 +9,7 @@ use crate::engine_plugin_credit::CreditContractIssueParameters;
pub struct CommandImpl; pub struct CommandImpl;
impl Command for CommandImpl { impl Command for CommandImpl {
fn name(&self) -> &str { "issue" } fn name(&self) -> &str { "issue" }
fn subcommand<'a>(&self) -> App<'a, 'a> { fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Issue credit contract subcommand") 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")) .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("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")) .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 { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
let name = sub_arg_matches.value_of("name").unwrap(); let name = sub_arg_matches.value_of("name").unwrap();
let receiver = sub_arg_matches.value_of("receiver").unwrap(); let receiver = sub_arg_matches.value_of("receiver").unwrap();

View File

@@ -9,12 +9,14 @@ use crate::engine_plugin_credit::CreditContractQueryParameters;
pub struct CommandImpl; pub struct CommandImpl;
impl Command for CommandImpl { impl Command for CommandImpl {
fn name(&self) -> &str { "query" } fn name(&self) -> &str { "query" }
fn subcommand<'a>(&self) -> App<'a, 'a> { fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Query credit contract subcommand") 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("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("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")) .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 { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
let name = sub_arg_matches.value_of("name").unwrap(); let name = sub_arg_matches.value_of("name").unwrap();
let account = sub_arg_matches.value_of("account").unwrap(); let account = sub_arg_matches.value_of("account").unwrap();

View File

@@ -9,11 +9,13 @@ use crate::engine_plugin_credit::CreditContractQueryAllParameters;
pub struct CommandImpl; pub struct CommandImpl;
impl Command for CommandImpl { impl Command for CommandImpl {
fn name(&self) -> &str { "queryall" } fn name(&self) -> &str { "queryall" }
fn subcommand<'a>(&self) -> App<'a, 'a> { fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Queryall credit contract subcommand") 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("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")) .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 { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
let name = sub_arg_matches.value_of("name").unwrap(); let name = sub_arg_matches.value_of("name").unwrap();
let key = sub_arg_matches.value_of("key").unwrap(); let key = sub_arg_matches.value_of("key").unwrap();

View File

@@ -9,6 +9,7 @@ use crate::engine_plugin_credit::CreditContractTransferParameters;
pub struct CommandImpl; pub struct CommandImpl;
impl Command for CommandImpl { impl Command for CommandImpl {
fn name(&self) -> &str { "transfer" } fn name(&self) -> &str { "transfer" }
fn subcommand<'a>(&self) -> App<'a, 'a> { fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Transfer credit contract subcommand") 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")) .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("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")) .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 { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
let name = sub_arg_matches.value_of("name").unwrap(); let name = sub_arg_matches.value_of("name").unwrap();
let receiver = sub_arg_matches.value_of("receiver").unwrap(); let receiver = sub_arg_matches.value_of("receiver").unwrap();

View File

@@ -3,9 +3,11 @@ use crate::cmd::CommandError;
pub struct CommandImpl; pub struct CommandImpl;
impl CommandImpl { impl CommandImpl {
pub fn process_command<'a>(app: App<'a, 'a>) -> App<'a, 'a> { 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")) app.arg(Arg::with_name("verbose").long("verbose").short("v").multiple(true).help("Show verbose info"))
} }
pub fn run(arg_matches: &ArgMatches) -> CommandError { pub fn run(arg_matches: &ArgMatches) -> CommandError {
let verbose_count = arg_matches.occurrences_of("verbose"); let verbose_count = arg_matches.occurrences_of("verbose");
information!("Verbose count: {}", verbose_count); information!("Verbose count: {}", verbose_count);

View File

@@ -7,18 +7,22 @@ use crate::util::{JsonKeyPair, make_key_pair};
pub struct CommandImpl; pub struct CommandImpl;
impl Command for CommandImpl { impl Command for CommandImpl {
fn name(&self) -> &str { "genkey" } fn name(&self) -> &str { "genkey" }
fn subcommand<'a>(&self) -> App<'a, 'a> { fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Generate key pair subcommand") 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("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 { fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
let output = sub_arg_matches.value_of("output").unwrap(); let output = sub_arg_matches.value_of("output").unwrap();
let tag = sub_arg_matches.value_of("tag");
if let Ok(_) = File::open(output) { if let Ok(_) = File::open(output) {
failure!("Output file exists: {}", output); failure!("Output file exists: {}", output);
return Ok(()); return Ok(());
} }
let (pri_key, pub_key) = make_key_pair(); 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())?; fs::write(output, json_key_pair.to_json()?.as_bytes())?;
Ok(()) Ok(())
} }

View File

@@ -10,14 +10,16 @@ use std::str::FromStr;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct JsonKeyPair { pub struct JsonKeyPair {
pub tag: Option<String>,
pub identity: String, pub identity: String,
pub pri_key: String, pub pri_key: String,
pub pub_key: String, pub pub_key: String,
} }
impl JsonKeyPair { impl JsonKeyPair {
pub fn from(pri_key: SecretKey, pub_key: PublicKey) -> Self { pub fn from(pri_key: SecretKey, pub_key: PublicKey, tag: Option<String>) -> Self {
JsonKeyPair { JsonKeyPair {
tag,
identity: make_btc_address(&pub_key), identity: make_btc_address(&pub_key),
pri_key: format!("{}", pri_key), pri_key: format!("{}", pri_key),
pub_key: format!("{}", pub_key), pub_key: format!("{}", pub_key),