-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.rs
More file actions
92 lines (76 loc) · 2.44 KB
/
main.rs
File metadata and controls
92 lines (76 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![warn(clippy::all, clippy::pedantic)]
use cli::commands::basic::Basic;
use cli::commands::option_offer::OptionOffer;
use cli::modules::utils::{esplora_url_from_network, wallet_data_root};
use anyhow::Result;
use clap::{Parser, Subcommand};
use wallet_abi::runtime::WalletRuntimeConfig;
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
/// Command-line entrypoint for the Simplicity helper CLI.
#[derive(Parser, Debug)]
#[command(
name = "simplicity-cli",
version,
about = "Simplicity helper CLI for Liquid testnet"
)]
struct Cli {
#[command(subcommand)]
command: Commands,
/// Network on which to send a transaction
#[arg(long = "network")]
network: lwk_common::Network,
#[arg(short, long, env = "MNEMONIC")]
mnemonic: Option<String>,
}
/// Top-level subcommand groups.
#[derive(Subcommand, Debug)]
enum Commands {
/// Simple transaction utilities
Basic {
#[command(subcommand)]
basic: Box<Basic>,
},
/// Option-offer contract utilities
OptionOffer {
#[command(subcommand)]
option_offer: Box<OptionOffer>,
},
// /// Options contract utilities
// Options {
// #[command(subcommand)]
// options: Box<Options>,
// },
// /// Storage utilities
// Storage {
// #[command(subcommand)]
// storage: Box<SMTStorage>,
// },
}
const TEST_MNEMONIC: &str =
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
#[tokio::main]
async fn main() -> Result<()> {
let _ = dotenvy::dotenv();
logging_init();
let parsed = Cli::parse();
let mnemonic = parsed.mnemonic.unwrap_or_else(|| TEST_MNEMONIC.to_string());
let runtime = WalletRuntimeConfig::from_mnemonic(
&mnemonic,
parsed.network,
&esplora_url_from_network(parsed.network),
wallet_data_root(),
)?;
match parsed.command {
Commands::Basic { basic } => basic.handle(runtime).await,
Commands::OptionOffer { option_offer } => Box::pin(option_offer.handle(runtime)).await,
// TODO: Commands::Options { options } => options.handle().await,
// TODO: Commands::Storage { storage } => storage.handle().await,
}
}
fn logging_init() {
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
tracing_subscriber::registry()
.with(fmt::layer().with_target(true))
.with(filter)
.init();
}