feat: works

This commit is contained in:
2021-01-01 22:16:11 +08:00
parent 601f11efe6
commit 24150ca0f1
16 changed files with 555 additions and 82 deletions

View File

@@ -1,32 +1,42 @@
pub mod util;
pub mod tx;
pub mod credit;
pub mod engine;
pub mod engine_credit;
use std::str::FromStr;
use rust_util::XResult;
use secp256k1::{Message, Secp256k1, Signature};
use util::*;
mod cmd;
mod cmd_default;
mod cmd_genkey;
mod cmd_credit_create;
mod cmd_credit_issue;
mod cmd_credit_transfer;
mod cmd_credit_query;
mod cmd_credit_queryall;
fn main() -> XResult<()> {
let (pri_key, pub_key) = make_key_pair();
println!("{:?}", pri_key);
println!("{:?}", pub_key);
println!("{:?}", JsonKeyPair::from(pri_key, pub_key).to_json());
println!("{:?}", JsonKeyPair::from(pri_key, pub_key).to_key_pair());
println!("{}", make_btc_address(&pub_key));
use clap::App;
use cmd::{Command, CommandError};
let p256k1 = Secp256k1::new();
let s =calc_sha256("hello".as_bytes());
let message = Message::from_slice(&s)?;
let sign = p256k1.sign(&message, &pri_key);
let sign_hex = format!("{}", sign);
println!("{}", sign_hex);
let sig = Signature::from_str(&sign_hex)?;
let result = p256k1.verify(&message, &sig, &pub_key);
println!("{:?}", result);
Ok(())
fn main() -> CommandError {
let commands: Vec<Box<dyn Command>> = vec![
Box::new(cmd_genkey::CommandImpl),
Box::new(cmd_credit_create::CommandImpl),
Box::new(cmd_credit_issue::CommandImpl),
Box::new(cmd_credit_transfer::CommandImpl),
Box::new(cmd_credit_query::CommandImpl),
Box::new(cmd_credit_queryall::CommandImpl),
];
let mut app = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.about(env!("CARGO_PKG_DESCRIPTION"));
app = cmd_default::CommandImpl::process_command(app);
for command in &commands {
app = app.subcommand(command.subcommand());
}
let matches = app.get_matches();
for command in &commands {
if let Some(sub_cmd_matches) = matches.subcommand_matches(command.name()) {
return command.run(&matches, sub_cmd_matches);
}
}
cmd_default::CommandImpl::run(&matches)
}