use clap::{Parser, Subcommand};
#[derive(Debug, Clone, Subcommand)]
pub enum CliCommand {
Info,
OfferContract(Offer),
Offers,
AcceptOffer(Accept),
Contracts,
#[command(about = "Get the wallet balance.")]
Balance,
#[clap(subcommand)]
Wallet(WalletCommand),
#[clap(subcommand)]
Oracle(OracleCommand),
Peers,
Connect {
#[arg(help = "The counter party to connect to. <PUBKEY>@<HOST>")]
connect_string: String,
},
#[command(about = "Sync the wallet and contracts.")]
Sync,
}
#[derive(Parser, Clone, Debug)]
pub struct Offer {
#[arg(help = "Generate a contract automatically with peer.")]
#[arg(short = 'g', long = "generate", default_value = "false")]
pub generate: bool,
#[arg(help = "The contract counterparty to send to.")]
pub counter_party: String,
}
#[derive(Clone, Debug, Subcommand)]
pub enum WalletCommand {
#[command(about = "Generate a new, unused address from the wallet.")]
NewAddress,
#[command(about = "Get the wallet transactions.")]
Transactions,
#[command(about = "Get the wallet utxos.")]
Utxos,
#[command(about = "Send a Bitcoin amount to an address")]
Send {
address: String,
amount: u64,
fee_rate: u64,
},
#[command(about = "Sync the on-chain wallet.")]
Sync,
}
#[derive(Clone, Debug, Subcommand)]
pub enum OracleCommand {
#[command(about = "Get all known oracle announcements.")]
Announcements {
#[arg(help = "The announcement id to get.")]
event_id: String,
},
#[command(about = "Create an enum oracle event.")]
CreateEnum {
#[arg(help = "The maturity of the event.")]
maturity: u32,
#[arg(help = "The outcomes of the event. Separate by spaces.")]
outcomes: Vec<String>,
},
#[command(about = "Create a numeric oracle event.")]
CreateNumeric {
#[arg(help = "The maturity of the event.")]
maturity: u32,
#[arg(help = "Number of digits for the numeric event.")]
nb_digits: u32,
},
#[command(about = "Sign an oracle announcement.")]
Sign {
#[arg(
long,
help = "Specify if the event is enum.",
conflicts_with = "numeric"
)]
r#enum: bool,
#[arg(
long,
help = "Specify if the event is numeric.",
conflicts_with = "enum"
)]
numeric: bool,
#[arg(long, help = "The outcome to sign.")]
outcome: String,
#[arg(long, help = "The event id to sign.")]
event_id: String,
},
}
#[derive(Parser, Clone, Debug)]
pub struct Accept {
pub contract_id: String,
}
#[derive(Parser, Clone, Debug)]
pub struct Connect {
#[arg(help = "The public key to connect to.")]
pub pubkey: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_oracle_create_enum_structure() {
let cmd = OracleCommand::CreateEnum {
maturity: 1234567890,
outcomes: vec!["YES".to_string(), "NO".to_string()],
};
match cmd {
OracleCommand::CreateEnum { maturity, outcomes } => {
assert_eq!(maturity, 1234567890);
assert_eq!(outcomes, vec!["YES", "NO"]);
}
_ => panic!("Wrong variant"),
}
}
#[test]
fn test_oracle_create_numeric_structure() {
let cmd = OracleCommand::CreateNumeric {
maturity: 1234567890,
nb_digits: 5,
};
match cmd {
OracleCommand::CreateNumeric {
maturity,
nb_digits,
} => {
assert_eq!(maturity, 1234567890);
assert_eq!(nb_digits, 5);
}
_ => panic!("Wrong variant"),
}
}
#[test]
fn test_oracle_sign_enum_structure() {
let cmd = OracleCommand::Sign {
r#enum: true,
numeric: false,
outcome: "YES".to_string(),
event_id: "test123".to_string(),
};
match cmd {
OracleCommand::Sign {
r#enum,
numeric,
outcome,
event_id,
} => {
assert!(r#enum);
assert!(!numeric);
assert_eq!(outcome, "YES");
assert_eq!(event_id, "test123");
}
_ => panic!("Wrong variant"),
}
}
#[test]
fn test_oracle_sign_numeric_structure() {
let cmd = OracleCommand::Sign {
r#enum: false,
numeric: true,
outcome: "42".to_string(),
event_id: "test123".to_string(),
};
match cmd {
OracleCommand::Sign {
r#enum,
numeric,
outcome,
event_id,
} => {
assert!(!r#enum);
assert!(numeric);
assert_eq!(outcome, "42");
assert_eq!(event_id, "test123");
}
_ => panic!("Wrong variant"),
}
}
#[test]
fn test_oracle_announcements_structure() {
let cmd = OracleCommand::Announcements {
event_id: "event123".to_string(),
};
match cmd {
OracleCommand::Announcements { event_id } => {
assert_eq!(event_id, "event123");
}
_ => panic!("Wrong variant"),
}
}
}