mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-08-03 16:40:08 +00:00
add request function for offer request
This commit is contained in:
@ -1,4 +1,3 @@
|
|||||||
mod trader;
|
|
||||||
mod coordinator;
|
mod coordinator;
|
||||||
mod cli;
|
mod cli;
|
||||||
mod communication;
|
mod communication;
|
||||||
|
1751
taptrade-cli-demo/trader/Cargo.lock
generated
1751
taptrade-cli-demo/trader/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -4,3 +4,8 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.86"
|
||||||
|
bdk = "0.29.0"
|
||||||
|
clap = "4.5.4"
|
||||||
|
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
|
||||||
|
serde = "1.0.203"
|
||||||
|
91
taptrade-cli-demo/trader/src/cli/mod.rs
Executable file
91
taptrade-cli-demo/trader/src/cli/mod.rs
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
use clap::{command, Arg, Command, ArgMatches};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Coordinator;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct TraderSettings {
|
||||||
|
pub electrum_endpoint: String,
|
||||||
|
pub coordinator_endpoint: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum CliSettings {
|
||||||
|
Coordinator(Coordinator),
|
||||||
|
Taker(TraderSettings),
|
||||||
|
Maker(TraderSettings)
|
||||||
|
}
|
||||||
|
|
||||||
|
trait ArgMatchesParser {
|
||||||
|
fn parse_into_enum(&self) -> CliSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ArgMatchesParser for ArgMatches {
|
||||||
|
fn parse_into_enum(&self) -> CliSettings {
|
||||||
|
if let Some(_mode) = self.subcommand_matches("coordinator") {
|
||||||
|
CliSettings::Coordinator(Coordinator { })
|
||||||
|
} else if let Some(mode) = self.subcommand_matches("trader") {
|
||||||
|
let trader_settings = TraderSettings {
|
||||||
|
coordinator_endpoint: mode.get_one::<String>("coordinator-ep")
|
||||||
|
.expect("Coordinator endpoint not provided!").clone(),
|
||||||
|
electrum_endpoint: mode.get_one::<String>("electrum-ep")
|
||||||
|
.expect("Electrum endpoint not provided").clone()
|
||||||
|
};
|
||||||
|
if mode.contains_id("maker") {
|
||||||
|
CliSettings::Maker( trader_settings )
|
||||||
|
} else if mode.contains_id("taker") {
|
||||||
|
CliSettings::Taker( trader_settings )
|
||||||
|
} else {
|
||||||
|
panic!("Wrong arguments for Trader mode!")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("Select either coordinator or trader mode!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_cli_args() -> CliSettings {
|
||||||
|
command!()
|
||||||
|
.about("RoboSats taproot onchain trade pipeline CLI demonstrator. Don't use with real funds.")
|
||||||
|
.subcommand(
|
||||||
|
Command::new("coordinator")
|
||||||
|
.about("Run in coordinator mode.")
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
Command::new("trader")
|
||||||
|
.about("Two available trader modes: Maker and Taker. Select one and provide Coordinator and Electum endpoint")
|
||||||
|
.arg(
|
||||||
|
Arg::new("taker")
|
||||||
|
.short('t')
|
||||||
|
.long("taker")
|
||||||
|
.help("Run program as taker")
|
||||||
|
.num_args(0)
|
||||||
|
.conflicts_with("maker")
|
||||||
|
)
|
||||||
|
.arg (
|
||||||
|
Arg::new("maker")
|
||||||
|
.short('m')
|
||||||
|
.long("maker")
|
||||||
|
.num_args(0)
|
||||||
|
.help("Run program as maker")
|
||||||
|
.conflicts_with("taker")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("coordinator-ep")
|
||||||
|
.short('p')
|
||||||
|
.long("endpoint")
|
||||||
|
.required(true)
|
||||||
|
.help("Communication endpoint of the coordinator to connect to")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("electrum-ep")
|
||||||
|
.short('e')
|
||||||
|
.long("electrum")
|
||||||
|
.required(true)
|
||||||
|
.help("URL of the electrum endpoint")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.arg_required_else_help(true)
|
||||||
|
.get_matches()
|
||||||
|
.parse_into_enum()
|
||||||
|
}
|
14
taptrade-cli-demo/trader/src/communication/mod.rs
Normal file
14
taptrade-cli-demo/trader/src/communication/mod.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use reqwest;
|
||||||
|
use anyhow::Result;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct OfferConditions {
|
||||||
|
pub locking_address: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fetch_offer(coordinator_ep: &String) -> Result<OfferConditions> {
|
||||||
|
let res = reqwest::blocking::get(format!("{}{}", coordinator_ep, "/create-offer"))?;
|
||||||
|
let offer_conditions: OfferConditions = res.json()?;
|
||||||
|
Ok(offer_conditions)
|
||||||
|
}
|
@ -1,3 +1,9 @@
|
|||||||
|
mod cli;
|
||||||
|
mod communication;
|
||||||
|
|
||||||
|
use cli::parse_cli_args;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
let mode = parse_cli_args();
|
||||||
|
dbg!(mode);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user