50 lines
1.7 KiB
Rust
50 lines
1.7 KiB
Rust
use std::fs;
|
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
|
use rust_util::util_clap::{Command, CommandError};
|
|
use crate::util::JsonKeyPair;
|
|
use crate::tx::{Transaction, TransactionBody};
|
|
use crate::engine::ContractEngine;
|
|
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();
|
|
|
|
let key_json = fs::read_to_string(key)?;
|
|
let (pri_key, pub_key) = JsonKeyPair::from_json(&key_json)?.to_key_pair()?;
|
|
|
|
let parameters = CreditContractQueryAllParameters {
|
|
name: name.into(),
|
|
};
|
|
let transaction_body = TransactionBody {
|
|
timestamp: 0,
|
|
nonce: "".into(),
|
|
contract: "credit".into(),
|
|
action: "query_all".into(),
|
|
parameters: serde_json::to_string(¶meters)?.into(),
|
|
};
|
|
let tx = Transaction::new(&transaction_body, &pri_key, &pub_key)?;
|
|
|
|
information!("Create transaction: {:#?}", tx);
|
|
|
|
let engine = ContractEngine::new();
|
|
engine.execute(&tx)?;
|
|
|
|
Ok(None)
|
|
}
|
|
}
|