style: format
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -10,14 +10,16 @@ use std::str::FromStr;
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct JsonKeyPair {
|
||||
pub tag: Option<String>,
|
||||
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<String>) -> Self {
|
||||
JsonKeyPair {
|
||||
tag,
|
||||
identity: make_btc_address(&pub_key),
|
||||
pri_key: format!("{}", pri_key),
|
||||
pub_key: format!("{}", pub_key),
|
||||
|
||||
Reference in New Issue
Block a user