Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit d290719

Browse files
committed
new example. generate public key
1 parent 4646e03 commit d290719

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

examples/pubkey.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use dotenv::dotenv;
2+
use secp256k1::Secp256k1;
3+
4+
use terra_rust_cli::cli_helpers;
5+
6+
async fn run() -> anyhow::Result<()> {
7+
let cli = cli_helpers::gen_cli("pubkey", "pubkey");
8+
let matches = cli.get_matches();
9+
let secp = Secp256k1::new();
10+
let private_key = cli_helpers::get_private_key(&secp, &matches)?;
11+
12+
let msg = "mary had a little lamb. I ate, coz lamb is delicious";
13+
// let signature = from_key.sign(&secp, &cli.message)?;
14+
let signature = private_key.sign(&secp, &msg)?;
15+
16+
println!("PubKeySig={}", signature.pub_key.value);
17+
18+
Ok(())
19+
}
20+
21+
#[tokio::main]
22+
async fn main() {
23+
dotenv().ok();
24+
env_logger::init();
25+
26+
if let Err(ref err) = run().await {
27+
log::error!("{}", err);
28+
err.chain()
29+
.skip(1)
30+
.for_each(|cause| log::error!("because: {}", cause));
31+
32+
// The backtrace is not always generated. Try to run this example
33+
// with `$env:RUST_BACKTRACE=1`.
34+
// if let Some(backtrace) = e.backtrace() {
35+
// log::debug!("backtrace: {:?}", backtrace);
36+
// }
37+
38+
::std::process::exit(1);
39+
}
40+
}

0 commit comments

Comments
 (0)