From 7b5c438a012bac17ed189371a2d667e974416692 Mon Sep 17 00:00:00 2001 From: Felix <51097237+f321x@users.noreply.github.com> Date: Sun, 23 Jun 2024 16:02:08 +0000 Subject: [PATCH 1/5] add comments, make functions more generic, waiting for confirmation --- taptrade-cli-demo/trader/src/cli/mod.rs | 5 ++--- .../trader/src/communication/mod.rs | 3 +-- .../src/communication/taker_requests.rs | 2 +- taptrade-cli-demo/trader/src/trading/mod.rs | 19 +++++++++++-------- .../trader/src/trading/taker_utils.rs | 10 +++------- taptrade-cli-demo/trader/src/trading/utils.rs | 10 +++++++++- taptrade-cli-demo/trader/src/wallet/mod.rs | 9 +++------ 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/taptrade-cli-demo/trader/src/cli/mod.rs b/taptrade-cli-demo/trader/src/cli/mod.rs index 91ae4a2..6ef54fc 100755 --- a/taptrade-cli-demo/trader/src/cli/mod.rs +++ b/taptrade-cli-demo/trader/src/cli/mod.rs @@ -1,7 +1,6 @@ use crate::wallet::get_wallet_xprv; use anyhow::{anyhow, Result}; use bdk::bitcoin::bip32::ExtendedPrivKey; -use hex; use sha2::{Digest, Sha256}; use std::{ env, @@ -90,7 +89,7 @@ impl CliSettings { } // parses the hours input string and returns the unix timestamp + the trade duration in seconds - fn hours_to_ts(hours: &String) -> Result { + fn hours_to_ts(hours: &str) -> Result { let duration: u64 = hours.parse()?; Ok(SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + duration * 3600) } @@ -98,7 +97,7 @@ impl CliSettings { fn get_trader_settings() -> Result { let electrum_endpoint = Self::get_user_input("Enter electrum endpoint: "); let coordinator_endpoint = Self::get_user_input("Enter coordinator endpoint: "); - let robosats_robohash_hex = hex::encode(&hash256(&Self::get_user_input( + let robosats_robohash_hex = hex::encode(hash256(&Self::get_user_input( "Enter your robosats robot key: ", // just for testing purposes, to be improved to the real robohash spec ))); let trade_type: OfferType = Self::get_trade_type(None); diff --git a/taptrade-cli-demo/trader/src/communication/mod.rs b/taptrade-cli-demo/trader/src/communication/mod.rs index c20659c..5896f58 100644 --- a/taptrade-cli-demo/trader/src/communication/mod.rs +++ b/taptrade-cli-demo/trader/src/communication/mod.rs @@ -78,7 +78,7 @@ impl BondSubmissionRequest { } pub fn send_maker( - robohash_hex: &String, + robohash_hex: &str, bond: &PartiallySignedTransaction, musig_data: &mut MuSigData, payout_address: &AddressInfo, @@ -106,7 +106,6 @@ impl OfferTakenResponse { trader_setup: &TraderSettings, ) -> Result> { let request = OfferTakenRequest { - // maybe can be made a bit more efficient (less clone) robohash_hex: trader_setup.robosats_robohash_hex.clone(), order_id_hex: offer.offer_id_hex.clone(), }; diff --git a/taptrade-cli-demo/trader/src/communication/taker_requests.rs b/taptrade-cli-demo/trader/src/communication/taker_requests.rs index d964cf2..02c5d36 100644 --- a/taptrade-cli-demo/trader/src/communication/taker_requests.rs +++ b/taptrade-cli-demo/trader/src/communication/taker_requests.rs @@ -103,7 +103,7 @@ impl IsOfferReadyRequest { return Ok(()); } else if res.status() != 201 { return Err(anyhow!( - "Submitting taker psbt failed. Status: {}", + "Requesting offer status when waiting on maker to sign psbt failed: {}", res.status() )); } diff --git a/taptrade-cli-demo/trader/src/trading/mod.rs b/taptrade-cli-demo/trader/src/trading/mod.rs index f96e6a9..14fabc2 100644 --- a/taptrade-cli-demo/trader/src/trading/mod.rs +++ b/taptrade-cli-demo/trader/src/trading/mod.rs @@ -6,8 +6,8 @@ use self::utils::ActiveOffer; use crate::{ cli::TraderSettings, communication::api::{ - BondRequirementResponse, BondSubmissionRequest, OfferTakenRequest, OfferTakenResponse, - PsbtSubmissionRequest, PublicOffer, PublicOffers, + BondRequirementResponse, BondSubmissionRequest, IsOfferReadyRequest, OfferTakenRequest, + OfferTakenResponse, PsbtSubmissionRequest, PublicOffer, PublicOffers, }, wallet::{ bond::Bond, @@ -28,8 +28,8 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> { let offer = ActiveOffer::create(&wallet, maker_config)?; dbg!(&offer); - let mut escrow_contract_psbt = offer.wait_until_taken(maker_config)?; + let mut escrow_contract_psbt = offer.wait_until_taken(maker_config)?; wallet .validate_maker_psbt(&escrow_contract_psbt)? .sign_escrow_psbt(&mut escrow_contract_psbt)?; @@ -40,7 +40,9 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> { offer.offer_id_hex.clone(), maker_config, )?; + // wait for confirmation + offer.wait_on_trade_ready_confirmation(maker_config)?; Ok(()) } @@ -49,18 +51,19 @@ pub fn run_taker(taker_config: &TraderSettings) -> Result<()> { let wallet = TradingWallet::load_wallet(taker_config)?; let mut available_offers = PublicOffers::fetch(taker_config)?; - while let None = available_offers.offers { - println!("No offers available, trying again in 10 sec."); + while available_offers.offers.is_none() { + println!("No offers available, fetching again in 10 sec."); thread::sleep(Duration::from_secs(10)); available_offers = PublicOffers::fetch(taker_config)?; } let selected_offer: &PublicOffer = available_offers.ask_user_to_select()?; // take selected offer and wait for maker to sign his input to the ecrow transaction - let accepted_offer = - ActiveOffer::take(&wallet, taker_config, selected_offer)?.wait_on_maker(taker_config)?; + let accepted_offer = ActiveOffer::take(&wallet, taker_config, selected_offer)? + .wait_on_trade_ready_confirmation(taker_config)? + .wait_on_fiat_confirmation_cli_input()?; - accepted_offer.wait_on_fiat_confirmation()?; + // .wait_on_maker_confirmation(); // here we wait for the maker to confirm the reciept of the fiat. We could go into escrow here. Ok(()) } diff --git a/taptrade-cli-demo/trader/src/trading/taker_utils.rs b/taptrade-cli-demo/trader/src/trading/taker_utils.rs index ddd9533..2aff2c9 100644 --- a/taptrade-cli-demo/trader/src/trading/taker_utils.rs +++ b/taptrade-cli-demo/trader/src/trading/taker_utils.rs @@ -50,13 +50,9 @@ impl ActiveOffer { }) } - pub fn wait_on_maker(self, taker_config: &TraderSettings) -> Result { - IsOfferReadyRequest::poll(taker_config, &self)?; - Ok(self) - } - - pub fn wait_on_fiat_confirmation(&self) -> Result<&Self> { - // let user confirm in CLI that the fiat payment has been sent/receivec + pub fn wait_on_fiat_confirmation_cli_input(&self) -> Result<&Self> { + // let user confirm in CLI that the fiat payment has been sent/received + println!("The escrow is now locked and the fiat exchange can begin safely."); loop { println!("Please confirm that the fiat payment has been sent/received. (y/N)"); let mut input = String::new(); diff --git a/taptrade-cli-demo/trader/src/trading/utils.rs b/taptrade-cli-demo/trader/src/trading/utils.rs index 3d4ca35..f5ab2ef 100644 --- a/taptrade-cli-demo/trader/src/trading/utils.rs +++ b/taptrade-cli-demo/trader/src/trading/utils.rs @@ -1,4 +1,3 @@ -use super::maker_utils::*; use super::*; #[derive(Debug)] @@ -9,3 +8,12 @@ pub struct ActiveOffer { pub expected_payout_address: AddressInfo, pub escrow_psbt: Option, } + +impl ActiveOffer { + // polls till the other party signed the trade transaction and it got confirmed. + // once the coordinator signals OfferReady the fiat exchange can begin + pub fn wait_on_trade_ready_confirmation(self, trader_config: &TraderSettings) -> Result { + IsOfferReadyRequest::poll(trader_config, &self)?; + Ok(self) + } +} diff --git a/taptrade-cli-demo/trader/src/wallet/mod.rs b/taptrade-cli-demo/trader/src/wallet/mod.rs index dfd1186..0bfa599 100644 --- a/taptrade-cli-demo/trader/src/wallet/mod.rs +++ b/taptrade-cli-demo/trader/src/wallet/mod.rs @@ -43,11 +43,8 @@ impl TradingWallet { pub fn load_wallet(trader_config: &TraderSettings) -> Result { let backend = ElectrumBlockchain::from(Client::new(&trader_config.electrum_endpoint)?); let wallet = Wallet::new( - Bip86(trader_config.wallet_xprv.clone(), KeychainKind::External), - Some(Bip86( - trader_config.wallet_xprv.clone(), - KeychainKind::Internal, - )), + Bip86(trader_config.wallet_xprv, KeychainKind::External), + Some(Bip86(trader_config.wallet_xprv, KeychainKind::Internal)), bitcoin::Network::Testnet, MemoryDatabase::default(), // non-permanent storage )?; @@ -64,7 +61,7 @@ impl TradingWallet { trader_config: &TraderSettings, ) -> Result<(PartiallySignedTransaction, MuSigData, AddressInfo)> { let trading_wallet = &self.wallet; - let bond = Bond::assemble(&self.wallet, &offer_conditions, trader_config)?; + let bond = Bond::assemble(&self.wallet, offer_conditions, trader_config)?; let payout_address: AddressInfo = trading_wallet.get_address(bdk::wallet::AddressIndex::LastUnused)?; let musig_data = MuSigData::create(&trader_config.wallet_xprv, trading_wallet.secp_ctx())?; From 0b20c1d723e1a36a99cabe440cc1d041dda5f8b1 Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 24 Jun 2024 08:57:06 +0000 Subject: [PATCH 2/5] trade confirmation --- .../trader/src/communication/api.rs | 9 +++++- .../trader/src/communication/mod.rs | 30 ++++++++++++++++++- taptrade-cli-demo/trader/src/trading/mod.rs | 25 ++++++++++++---- .../trader/src/trading/taker_utils.rs | 14 --------- taptrade-cli-demo/trader/src/trading/utils.rs | 26 ++++++++++++++-- 5 files changed, 80 insertions(+), 24 deletions(-) diff --git a/taptrade-cli-demo/trader/src/communication/api.rs b/taptrade-cli-demo/trader/src/communication/api.rs index 2f61dd2..b15c53c 100644 --- a/taptrade-cli-demo/trader/src/communication/api.rs +++ b/taptrade-cli-demo/trader/src/communication/api.rs @@ -22,7 +22,7 @@ pub struct BondRequirementResponse { // maker step 2 // (submission of signed bond and other data neccessary to coordinate the trade) #[derive(Serialize, Debug)] -pub struct BondSubmissionRequest { +pub struct BondSubmissionRequest { pub robohash_hex: String, pub signed_bond_hex: String, // signed bond transaction, hex encoded pub payout_address: String, // does this make sense here? @@ -93,3 +93,10 @@ pub struct IsOfferReadyRequest { pub robohash_hex: String, pub offer_id_hex: String, } + +// request posted by both parties when the trade obligations +#[derive(Debug, Serialize)] +pub struct TradeObligationsSatisfied { + pub robohash_hex: String, + pub offer_id_hex: String, +} diff --git a/taptrade-cli-demo/trader/src/communication/mod.rs b/taptrade-cli-demo/trader/src/communication/mod.rs index 5896f58..016596d 100644 --- a/taptrade-cli-demo/trader/src/communication/mod.rs +++ b/taptrade-cli-demo/trader/src/communication/mod.rs @@ -9,7 +9,7 @@ use crate::{ use anyhow::{anyhow, Result}; use api::{ BondRequirementResponse, BondSubmissionRequest, OfferTakenRequest, OfferTakenResponse, - OrderActivatedResponse, OrderRequest, PsbtSubmissionRequest, + OrderActivatedResponse, OrderRequest, PsbtSubmissionRequest, TradeObligationsSatisfied, }; use bdk::bitcoin::consensus::encode::serialize_hex; use bdk::{ @@ -155,3 +155,31 @@ impl PsbtSubmissionRequest { Ok(()) } } + +impl TradeObligationsSatisfied { + // if the trader is satisfied he can submit this to signal the coordinator readiness to close the trade + // if the other party also submits this the coordinator can initiate the closing transaction, otherwise + // escrow has to be initiated + pub fn submit(offer_id_hex: &String, trader_config: &TraderSettings) -> Result<()> { + let request = TradeObligationsSatisfied { + robohash_hex: trader_config.robosats_robohash_hex.clone(), + offer_id_hex: offer_id_hex.clone(), + }; + + let client = reqwest::blocking::Client::new(); + let res = client + .post(format!( + "{}{}", + trader_config.coordinator_endpoint, "/submit-obligation-confirmation" + )) + .json(&request) + .send()?; + if res.status() != 200 { + return Err(anyhow!( + "Submitting trade obligations confirmation failed. Status: {}", + res.status() + )); + } + Ok(()) + } +} diff --git a/taptrade-cli-demo/trader/src/trading/mod.rs b/taptrade-cli-demo/trader/src/trading/mod.rs index 14fabc2..9056d64 100644 --- a/taptrade-cli-demo/trader/src/trading/mod.rs +++ b/taptrade-cli-demo/trader/src/trading/mod.rs @@ -8,6 +8,7 @@ use crate::{ communication::api::{ BondRequirementResponse, BondSubmissionRequest, IsOfferReadyRequest, OfferTakenRequest, OfferTakenResponse, PsbtSubmissionRequest, PublicOffer, PublicOffers, + TradeObligationsSatisfied, }, wallet::{ bond::Bond, @@ -43,7 +44,14 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> { // wait for confirmation offer.wait_on_trade_ready_confirmation(maker_config)?; - + if offer.fiat_confirmation_cli_input(maker_config)? { + TradeObligationsSatisfied::submit(&offer.offer_id_hex, maker_config)?; + println!("Waiting for other party to confirm the trade."); + // poll for other party + } else { + println!("Trade failed."); + panic!("Escrow to be implemented!"); + } Ok(()) } @@ -59,11 +67,16 @@ pub fn run_taker(taker_config: &TraderSettings) -> Result<()> { let selected_offer: &PublicOffer = available_offers.ask_user_to_select()?; // take selected offer and wait for maker to sign his input to the ecrow transaction - let accepted_offer = ActiveOffer::take(&wallet, taker_config, selected_offer)? - .wait_on_trade_ready_confirmation(taker_config)? - .wait_on_fiat_confirmation_cli_input()?; - - // .wait_on_maker_confirmation(); // here we wait for the maker to confirm the reciept of the fiat. We could go into escrow here. + let accepted_offer = ActiveOffer::take(&wallet, taker_config, selected_offer)?; + accepted_offer.wait_on_trade_ready_confirmation(taker_config)?; + if accepted_offer.fiat_confirmation_cli_input(taker_config)? { + TradeObligationsSatisfied::submit(&accepted_offer.offer_id_hex, taker_config)?; + println!("Waiting for other party to confirm the trade."); + // poll for other party + } else { + println!("Trade failed."); + panic!("Escrow to be implemented!"); + } Ok(()) } diff --git a/taptrade-cli-demo/trader/src/trading/taker_utils.rs b/taptrade-cli-demo/trader/src/trading/taker_utils.rs index 2aff2c9..b267186 100644 --- a/taptrade-cli-demo/trader/src/trading/taker_utils.rs +++ b/taptrade-cli-demo/trader/src/trading/taker_utils.rs @@ -49,18 +49,4 @@ impl ActiveOffer { escrow_psbt: Some(escrow_contract_psbt), }) } - - pub fn wait_on_fiat_confirmation_cli_input(&self) -> Result<&Self> { - // let user confirm in CLI that the fiat payment has been sent/received - println!("The escrow is now locked and the fiat exchange can begin safely."); - loop { - println!("Please confirm that the fiat payment has been sent/received. (y/N)"); - let mut input = String::new(); - std::io::stdin().read_line(&mut input)?; - if input.trim().to_lowercase() == "y" { - break; - } - } - Ok(self) - } } diff --git a/taptrade-cli-demo/trader/src/trading/utils.rs b/taptrade-cli-demo/trader/src/trading/utils.rs index f5ab2ef..eb483a3 100644 --- a/taptrade-cli-demo/trader/src/trading/utils.rs +++ b/taptrade-cli-demo/trader/src/trading/utils.rs @@ -12,8 +12,30 @@ pub struct ActiveOffer { impl ActiveOffer { // polls till the other party signed the trade transaction and it got confirmed. // once the coordinator signals OfferReady the fiat exchange can begin - pub fn wait_on_trade_ready_confirmation(self, trader_config: &TraderSettings) -> Result { + pub fn wait_on_trade_ready_confirmation( + &self, + trader_config: &TraderSettings, + ) -> Result<&Self> { IsOfferReadyRequest::poll(trader_config, &self)?; - Ok(self) + Ok(&self) + } + + pub fn fiat_confirmation_cli_input(&self, trade_settings: &TraderSettings) -> Result { + // let user confirm in CLI that the fiat payment has been sent/received + println!("The escrow is now locked and the fiat exchange can begin safely."); + if trade_settings.trade_type.is_buy_order() { + println!("Please confirm that the fiat payment has been sent or go into mediation in case of problems. (y/M)"); + } else { + println!("Please confirm that the fiat payment has been received or go into mediation in case of problems. (y/M)"); + } + loop { + let mut input = String::new(); + std::io::stdin().read_line(&mut input)?; + if input.trim().to_lowercase() == "y" { + return Ok(true); + } else if input.trim() == "M" { + return Ok(false); + } + } } } From 8a8a93e184126a8fdf91cfcd9c6fe637d14576d2 Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 24 Jun 2024 11:59:51 +0000 Subject: [PATCH 3/5] begin with coordinator --- taptrade-cli-demo/coordinator/.env | 1 + taptrade-cli-demo/coordinator/Cargo.lock | 14 +++ taptrade-cli-demo/coordinator/Cargo.toml | 7 ++ taptrade-cli-demo/coordinator/src/cli/mod.rs | 91 ------------------- .../coordinator/src/communication/mod.rs | 79 ++++++---------- taptrade-cli-demo/coordinator/src/main.rs | 23 +++-- taptrade-cli-demo/trader/Cargo.toml | 5 + .../trader/src/communication/api.rs | 5 + .../trader/src/communication/mod.rs | 81 ++++++++++++++++- .../src/communication/taker_requests.rs | 29 ------ taptrade-cli-demo/trader/src/trading/mod.rs | 8 +- taptrade-cli-demo/trader/todos.md | 3 +- 12 files changed, 159 insertions(+), 187 deletions(-) create mode 100644 taptrade-cli-demo/coordinator/.env delete mode 100755 taptrade-cli-demo/coordinator/src/cli/mod.rs diff --git a/taptrade-cli-demo/coordinator/.env b/taptrade-cli-demo/coordinator/.env new file mode 100644 index 0000000..bd8113e --- /dev/null +++ b/taptrade-cli-demo/coordinator/.env @@ -0,0 +1 @@ +ELECTRUM_BACKEND=127.0.0.1:50001 diff --git a/taptrade-cli-demo/coordinator/Cargo.lock b/taptrade-cli-demo/coordinator/Cargo.lock index dd74b5d..e074d91 100644 --- a/taptrade-cli-demo/coordinator/Cargo.lock +++ b/taptrade-cli-demo/coordinator/Cargo.lock @@ -66,6 +66,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + [[package]] name = "async-trait" version = "0.1.80" @@ -380,9 +386,11 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" name = "coordinator" version = "0.1.0" dependencies = [ + "anyhow", "axum", "bdk", "clap", + "dotenv", "frost-secp256k1", "reqwest", "serde", @@ -514,6 +522,12 @@ dependencies = [ "litrs", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "ecdsa" version = "0.16.9" diff --git a/taptrade-cli-demo/coordinator/Cargo.toml b/taptrade-cli-demo/coordinator/Cargo.toml index c48462b..9cd2299 100644 --- a/taptrade-cli-demo/coordinator/Cargo.toml +++ b/taptrade-cli-demo/coordinator/Cargo.toml @@ -4,10 +4,17 @@ version = "0.1.0" edition = "2021" [dependencies] +anyhow = "1.0.86" axum = "0.7.5" bdk = "0.29.0" clap = { version = "4.5.4", features = ["derive", "cargo"] } +dotenv = "0.15.0" frost-secp256k1 = "1.0.0" reqwest = { version = "0.12.4", features = ["blocking", "json"] } serde = "1.0.203" tokio = "1.38.0" + +[profile.release] +lto = true +opt-level = 3 +strip = true diff --git a/taptrade-cli-demo/coordinator/src/cli/mod.rs b/taptrade-cli-demo/coordinator/src/cli/mod.rs deleted file mode 100755 index 22b6a5c..0000000 --- a/taptrade-cli-demo/coordinator/src/cli/mod.rs +++ /dev/null @@ -1,91 +0,0 @@ -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::("coordinator-ep") - .expect("Coordinator endpoint not provided!").clone(), - electrum_endpoint: mode.get_one::("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() -} diff --git a/taptrade-cli-demo/coordinator/src/communication/mod.rs b/taptrade-cli-demo/coordinator/src/communication/mod.rs index be5b600..5275043 100755 --- a/taptrade-cli-demo/coordinator/src/communication/mod.rs +++ b/taptrade-cli-demo/coordinator/src/communication/mod.rs @@ -1,17 +1,14 @@ -pub mod api; +mod api; + +use super::*; +use api::{BondRequirementResponse, BondSubmissionRequest, OrderActivatedResponse, OrderRequest}; +use axum::{routing::post, Json, Router}; -use reqwest::StatusCode; -use axum::{routing::post, Json, Router, response::{IntoResponse, Response}, }; -use serde::{Deserialize, Serialize}; use std::net::SocketAddr; use tokio::net::TcpListener; -use api::{ - BondRequirementResponse, BondSubmissionRequest, OrderActivatedResponse, OrderRequest, -}; - // Handler function to process the received data -async fn receive_order(Json(order): Json)-> Json { +async fn receive_order(Json(order): Json) -> Json { // Print the received data to the console println!("Received order: {:?}", order); @@ -23,61 +20,41 @@ async fn receive_order(Json(order): Json)-> Json, + Json(payload): Json, ) -> Json { - // Process the payload - // For now, we'll just return a dummy success response - let response = OrderActivatedResponse { - bond_locked_until_timestamp: 0 as u128, - order_id_hex: "Bond submitted successfully".to_string(), - }; + // Process the payload + // For now, we'll just return a dummy success response + let response = OrderActivatedResponse { + bond_locked_until_timestamp: 0 as u128, + order_id_hex: "Bond submitted successfully".to_string(), + }; - // Create the JSON response - Json(response) + // Create the JSON response + Json(response) } -#[tokio::main] -pub async fn webserver() { - // Build our application with a single route +pub async fn api_server() -> Result<()> { let app = Router::new() .route("/create-offer", post(receive_order)) .route("/submit-maker-bond", post(submit_maker_bond)); + // add other routes here - // Run the server on localhost:3000 - let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); + // Run the server on localhost:9999 + let addr = SocketAddr::from(([127, 0, 0, 1], 9999)); println!("Listening on {}", addr); - // axum::Server::bind(&addr) - // .serve(app.into_make_service()) - // .await - // .unwrap(); + let tcp = TcpListener::bind(&addr).await.unwrap(); - axum::serve(tcp, app).await.unwrap(); + axum::serve(tcp, app).await?; + Ok(()) } - -// // use axum - -// #[get("/")] -// fn index() -> &'static str { -// "Hello, world!" -// } - -// #[launch] -// pub fn webserver() -> Rocket { -// rocket::build().mount("/", routes![index]) -// } - -// // serde to parse json -// // https://www.youtube.com/watch?v=md-ecvXBGzI BDK + Webserver video -// // https://github.com/tokio-rs/axum diff --git a/taptrade-cli-demo/coordinator/src/main.rs b/taptrade-cli-demo/coordinator/src/main.rs index e5a2939..3707613 100755 --- a/taptrade-cli-demo/coordinator/src/main.rs +++ b/taptrade-cli-demo/coordinator/src/main.rs @@ -1,14 +1,17 @@ -mod coordinator; -mod cli; mod communication; +mod coordinator; -use cli::parse_cli_args; -use communication::webserver; +use anyhow::{anyhow, Result}; +use communication::api_server; +use dotenv::dotenv; +use serde::{Deserialize, Serialize}; +use std::env; -fn main() { - webserver(); - let mode = parse_cli_args(); - dbg!(mode); +// populate .env with values before starting +#[tokio::main] +async fn main() -> Result<()> { + dotenv().ok(); + + api_server().await?; + Ok(()) } - -// test with cargo run -- trader --maker --endpoint "taptrade-coordinator.com:5432" --electrum "electrum-server.com:50002" diff --git a/taptrade-cli-demo/trader/Cargo.toml b/taptrade-cli-demo/trader/Cargo.toml index 41f664e..ff92e94 100644 --- a/taptrade-cli-demo/trader/Cargo.toml +++ b/taptrade-cli-demo/trader/Cargo.toml @@ -15,3 +15,8 @@ rand_core = "0.6.4" reqwest = { version = "0.12.4", features = ["blocking", "json"] } serde = "1.0.203" sha2 = "0.10.8" + +[profile.release] +lto = true +opt-level = "z" +strip = true diff --git a/taptrade-cli-demo/trader/src/communication/api.rs b/taptrade-cli-demo/trader/src/communication/api.rs index b15c53c..ee31cce 100644 --- a/taptrade-cli-demo/trader/src/communication/api.rs +++ b/taptrade-cli-demo/trader/src/communication/api.rs @@ -100,3 +100,8 @@ pub struct TradeObligationsSatisfied { pub robohash_hex: String, pub offer_id_hex: String, } + +#[derive(Debug, Deserialize)] +pub struct PayoutPsbtResponse { + pub payout_psbt_hex: String, +} diff --git a/taptrade-cli-demo/trader/src/communication/mod.rs b/taptrade-cli-demo/trader/src/communication/mod.rs index 016596d..f464f99 100644 --- a/taptrade-cli-demo/trader/src/communication/mod.rs +++ b/taptrade-cli-demo/trader/src/communication/mod.rs @@ -8,8 +8,9 @@ use crate::{ }; use anyhow::{anyhow, Result}; use api::{ - BondRequirementResponse, BondSubmissionRequest, OfferTakenRequest, OfferTakenResponse, - OrderActivatedResponse, OrderRequest, PsbtSubmissionRequest, TradeObligationsSatisfied, + BondRequirementResponse, BondSubmissionRequest, IsOfferReadyRequest, OfferTakenRequest, + OfferTakenResponse, OrderActivatedResponse, OrderRequest, PayoutPsbtResponse, + PsbtSubmissionRequest, TradeObligationsSatisfied, }; use bdk::bitcoin::consensus::encode::serialize_hex; use bdk::{ @@ -17,7 +18,7 @@ use bdk::{ wallet::AddressInfo, }; use serde::{Deserialize, Serialize}; -use std::{thread::sleep, time::Duration}; +use std::{str::FromStr, thread::sleep, time::Duration}; impl BondRequirementResponse { fn _format_request(trader_setup: &TraderSettings) -> OrderRequest { @@ -183,3 +184,77 @@ impl TradeObligationsSatisfied { Ok(()) } } + +impl IsOfferReadyRequest { + pub fn poll(taker_config: &TraderSettings, offer: &ActiveOffer) -> Result<()> { + let request = IsOfferReadyRequest { + robohash_hex: taker_config.robosats_robohash_hex.clone(), + offer_id_hex: offer.offer_id_hex.clone(), + }; + let client = reqwest::blocking::Client::new(); + loop { + let res = client + .post(format!( + "{}{}", + taker_config.coordinator_endpoint, "/poll-offer-status" + )) + .json(&request) + .send()?; + if res.status() == 200 { + return Ok(()); + } else if res.status() != 204 { + return Err(anyhow!( + "Requesting offer status when waiting on other party failed: {}", + res.status() + )); + } + // Sleep for 10 sec and poll again + sleep(Duration::from_secs(10)); + } + } + + pub fn poll_payout( + trader_config: &TraderSettings, + offer: &ActiveOffer, + ) -> Result> { + let request = IsOfferReadyRequest { + robohash_hex: trader_config.robosats_robohash_hex.clone(), + offer_id_hex: offer.offer_id_hex.clone(), + }; + let client = reqwest::blocking::Client::new(); + let mut res: reqwest::blocking::Response; + + loop { + // Sleep for 10 sec and poll + sleep(Duration::from_secs(10)); + + res = client + .post(format!( + "{}{}", + trader_config.coordinator_endpoint, "/poll-final-payout" + )) + .json(&request) + .send()?; + if res.status() == 200 { + // good case, psbt is returned + break; + } else if res.status() == 204 { + // still waiting, retry + continue; + } else if res.status() == 201 { + // other party initiated escrow + return Ok(None); + } else { + // unintended response + return Err(anyhow!( + "Requesting final payout when waiting on other party failed: {}", + res.status() + )); + } + } + let final_psbt = PartiallySignedTransaction::from_str( + &res.json::()?.payout_psbt_hex, + )?; + Ok(Some(final_psbt)) + } +} diff --git a/taptrade-cli-demo/trader/src/communication/taker_requests.rs b/taptrade-cli-demo/trader/src/communication/taker_requests.rs index 02c5d36..0e903ba 100644 --- a/taptrade-cli-demo/trader/src/communication/taker_requests.rs +++ b/taptrade-cli-demo/trader/src/communication/taker_requests.rs @@ -83,32 +83,3 @@ impl OfferPsbtRequest { Ok(psbt) } } - -impl IsOfferReadyRequest { - pub fn poll(taker_config: &TraderSettings, offer: &ActiveOffer) -> Result<()> { - let request = IsOfferReadyRequest { - robohash_hex: taker_config.robosats_robohash_hex.clone(), - offer_id_hex: offer.offer_id_hex.clone(), - }; - let client = reqwest::blocking::Client::new(); - loop { - let res = client - .post(format!( - "{}{}", - taker_config.coordinator_endpoint, "/poll-offer-status-taker" - )) - .json(&request) - .send()?; - if res.status() == 200 { - return Ok(()); - } else if res.status() != 201 { - return Err(anyhow!( - "Requesting offer status when waiting on maker to sign psbt failed: {}", - res.status() - )); - } - // Sleep for 10 sec and poll again - sleep(Duration::from_secs(10)); - } - } -} diff --git a/taptrade-cli-demo/trader/src/trading/mod.rs b/taptrade-cli-demo/trader/src/trading/mod.rs index 9056d64..3e4d5e3 100644 --- a/taptrade-cli-demo/trader/src/trading/mod.rs +++ b/taptrade-cli-demo/trader/src/trading/mod.rs @@ -45,9 +45,10 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> { // wait for confirmation offer.wait_on_trade_ready_confirmation(maker_config)?; if offer.fiat_confirmation_cli_input(maker_config)? { + // this represents the "confirm payment" / "confirm fiat recieved" button TradeObligationsSatisfied::submit(&offer.offer_id_hex, maker_config)?; println!("Waiting for other party to confirm the trade."); - // poll for other party + let payout_keyspend_psbt = IsOfferReadyRequest::poll_payout(maker_config, &offer)?; } else { println!("Trade failed."); panic!("Escrow to be implemented!"); @@ -71,9 +72,12 @@ pub fn run_taker(taker_config: &TraderSettings) -> Result<()> { accepted_offer.wait_on_trade_ready_confirmation(taker_config)?; if accepted_offer.fiat_confirmation_cli_input(taker_config)? { + // this represents the "confirm payment" / "confirm fiat recieved" button TradeObligationsSatisfied::submit(&accepted_offer.offer_id_hex, taker_config)?; println!("Waiting for other party to confirm the trade."); - // poll for other party + // pull for other parties confirmation, then receive the transaction to create MuSig signature for (keyspend) to payout address + let payout_keyspend_psbt = IsOfferReadyRequest::poll_payout(taker_config, &accepted_offer)?; + // here we need to handle if the other party is not cooperating } else { println!("Trade failed."); panic!("Escrow to be implemented!"); diff --git a/taptrade-cli-demo/trader/todos.md b/taptrade-cli-demo/trader/todos.md index 0601a09..6dd43f0 100644 --- a/taptrade-cli-demo/trader/todos.md +++ b/taptrade-cli-demo/trader/todos.md @@ -1 +1,2 @@ -tbd +Thinks to improve when implementing the production ready library: +* make api more generic (smaller) From ad58758e990c8c0034906d452ac01d3e8578f73b Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 24 Jun 2024 17:17:01 +0000 Subject: [PATCH 4/5] sqlite in coordinator, anyhow result in coordinator, restructuring coordinator, loading env variable, removing cli parsing with clap --- taptrade-cli-demo/coordinator/Cargo.lock | 995 +++++++++++------- taptrade-cli-demo/coordinator/Cargo.toml | 3 +- .../coordinator/src/communication/mod.rs | 102 +- taptrade-cli-demo/coordinator/src/main.rs | 21 +- 4 files changed, 689 insertions(+), 432 deletions(-) diff --git a/taptrade-cli-demo/coordinator/Cargo.lock b/taptrade-cli-demo/coordinator/Cargo.lock index e074d91..511cb36 100644 --- a/taptrade-cli-demo/coordinator/Cargo.lock +++ b/taptrade-cli-demo/coordinator/Cargo.lock @@ -18,53 +18,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] -name = "anstream" -version = "0.6.14" +name = "ahash" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", ] [[package]] -name = "anstyle" -version = "1.0.7" +name = "allocator-api2" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" - -[[package]] -name = "anstyle-parse" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "anyhow" @@ -84,12 +54,12 @@ dependencies = [ ] [[package]] -name = "atomic-polyfill" -version = "1.0.3" +name = "atoi" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" dependencies = [ - "critical-section", + "num-traits", ] [[package]] @@ -174,18 +144,18 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64" version = "0.22.1" @@ -278,6 +248,9 @@ name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +dependencies = [ + "serde", +] [[package]] name = "block-buffer" @@ -318,64 +291,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "clap" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.66", -] - -[[package]] -name = "clap_lex" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" - -[[package]] -name = "cobs" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" - -[[package]] -name = "colorchoice" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" - -[[package]] -name = "const-crc32" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68d13f542d70e5b339bf46f6f74704ac052cfd526c58cd87996bd1ef4615b9a0" - [[package]] name = "const-oid" version = "0.9.6" @@ -389,11 +304,10 @@ dependencies = [ "anyhow", "axum", "bdk", - "clap", "dotenv", - "frost-secp256k1", "reqwest", "serde", + "sqlx", "tokio", ] @@ -422,6 +336,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "crc32fast" version = "1.4.2" @@ -431,12 +360,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "critical-section" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" - [[package]] name = "crossbeam-epoch" version = "0.9.18" @@ -446,24 +369,21 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -474,12 +394,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "debugless-unwrap" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f400d0750c0c069e8493f2256cb4da6f604b6d2eeb69a0ca8863acde352f8400" - [[package]] name = "der" version = "0.7.9" @@ -487,20 +401,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", + "pem-rfc7468", "zeroize", ] -[[package]] -name = "derive-getters" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2c35ab6e03642397cdda1dd58abbc05d418aef8e36297f336d5aba060fe8df" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "digest" version = "0.10.7" @@ -513,15 +417,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "document-features" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95" -dependencies = [ - "litrs", -] - [[package]] name = "dotenv" version = "0.15.0" @@ -529,24 +424,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] -name = "ecdsa" -version = "0.16.9" +name = "dotenvy" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" [[package]] name = "either" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +dependencies = [ + "serde", +] [[package]] name = "electrum-client" @@ -567,31 +457,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "zeroize", -] - -[[package]] -name = "embedded-io" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" - [[package]] name = "encoding_rs" version = "0.8.34" @@ -617,6 +482,23 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "fastrand" version = "2.1.0" @@ -624,13 +506,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] -name = "ff" -version = "0.13.0" +name = "flume" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ - "rand_core", - "subtle", + "futures-core", + "futures-sink", + "spin", ] [[package]] @@ -663,54 +546,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "frost-core" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45d6280625f1603d160df24b23e4984a6a7286f41455ae606823d0104c32e834" -dependencies = [ - "byteorder", - "const-crc32", - "debugless-unwrap", - "derive-getters", - "document-features", - "hex", - "itertools", - "postcard", - "rand_core", - "serde", - "serdect", - "thiserror", - "visibility", - "zeroize", -] - -[[package]] -name = "frost-rerandomized" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52c58f58ea009000db490efd9a3936d0035647a2b00c7ba8f3868c2ed0306b0b" -dependencies = [ - "derive-getters", - "document-features", - "frost-core", - "rand_core", -] - -[[package]] -name = "frost-secp256k1" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0216d9edf7b792596fe44f56dca2f000881fab6f15ca446e77eab4d6e943a41b" -dependencies = [ - "document-features", - "frost-core", - "frost-rerandomized", - "k256", - "rand_core", - "sha2", -] - [[package]] name = "fs2" version = "0.4.3" @@ -737,6 +572,28 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot 0.12.3", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -788,7 +645,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -808,17 +664,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "h2" version = "0.4.5" @@ -838,40 +683,33 @@ dependencies = [ "tracing", ] -[[package]] -name = "hash32" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" -dependencies = [ - "byteorder", -] - [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] -name = "heapless" -version = "0.7.17" +name = "hashlink" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ - "atomic-polyfill", - "hash32", - "rustc_version", - "serde", - "spin", - "stable_deref_trait", + "hashbrown", ] [[package]] name = "heck" -version = "0.5.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "hermit-abi" @@ -891,6 +729,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + [[package]] name = "hmac" version = "0.12.1" @@ -900,6 +747,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "1.1.0" @@ -1038,21 +894,6 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "is_terminal_polyfill" -version = "1.70.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" - -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" @@ -1069,17 +910,12 @@ dependencies = [ ] [[package]] -name = "k256" -version = "0.13.3" +name = "lazy_static" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2", - "signature", + "spin", ] [[package]] @@ -1088,18 +924,29 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "libsqlite3-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "litrs" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" - [[package]] name = "lock_api" version = "0.4.12" @@ -1122,6 +969,16 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.7.2" @@ -1134,6 +991,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniscript" version = "10.0.0" @@ -1182,6 +1045,63 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -1259,7 +1179,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core", + "parking_lot_core 0.8.6", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core 0.9.10", ] [[package]] @@ -1271,11 +1201,39 @@ dependencies = [ "cfg-if", "instant", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "winapi", ] +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.2", + "smallvec", + "windows-targets 0.52.5", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -1314,6 +1272,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + [[package]] name = "pkcs8" version = "0.10.2" @@ -1330,18 +1299,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "postcard" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" -dependencies = [ - "cobs", - "embedded-io", - "heapless", - "serde", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1405,6 +1362,24 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +dependencies = [ + "bitflags 2.5.0", +] + [[package]] name = "reqwest" version = "0.12.4" @@ -1448,16 +1423,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "ring" version = "0.17.8" @@ -1473,21 +1438,32 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "rustix" version = "0.38.34" @@ -1576,20 +1552,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "secp256k1" version = "0.27.0" @@ -1634,12 +1596,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" - [[package]] name = "serde" version = "1.0.203" @@ -1694,13 +1650,14 @@ dependencies = [ ] [[package]] -name = "serdect" -version = "0.2.0" +name = "sha1" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ - "base16ct", - "serde", + "cfg-if", + "cpufeatures", + "digest", ] [[package]] @@ -1746,7 +1703,7 @@ dependencies = [ "fxhash", "libc", "log", - "parking_lot", + "parking_lot 0.11.2", ] [[package]] @@ -1785,16 +1742,218 @@ dependencies = [ ] [[package]] -name = "stable_deref_trait" -version = "1.2.0" +name = "sqlformat" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +checksum = "f895e3734318cc55f1fe66258926c9b910c124d47520339efecbb6c59cec7c1f" +dependencies = [ + "nom", + "unicode_categories", +] [[package]] -name = "strsim" -version = "0.11.1" +name = "sqlx" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" +dependencies = [ + "ahash", + "atoi", + "byteorder", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", +] + +[[package]] +name = "sqlx-macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-sqlite", + "syn 1.0.109", + "tempfile", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "byteorder", + "bytes", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "byteorder", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "tracing", + "url", + "urlencoding", +] + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] [[package]] name = "subtle" @@ -1942,6 +2101,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.11" @@ -1991,9 +2161,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -2036,6 +2218,24 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-properties" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4259d9d4425d9f0661581b804cb85fe66a4c631cadd8f490d1c13a35d5d9291" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + [[package]] name = "untrusted" version = "0.9.0" @@ -2054,10 +2254,10 @@ dependencies = [ ] [[package]] -name = "utf8parse" -version = "0.2.1" +name = "urlencoding" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" [[package]] name = "vcpkg" @@ -2071,17 +2271,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "visibility" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3fd98999db9227cf28e59d83e1f120f42bc233d4b152e8fab9bc87d5bb1e0f8" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "want" version = "0.3.1" @@ -2097,6 +2286,12 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -2192,6 +2387,16 @@ dependencies = [ "webpki", ] +[[package]] +name = "whoami" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" +dependencies = [ + "redox_syscall 0.4.1", + "wasite", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2364,21 +2569,27 @@ dependencies = [ ] [[package]] -name = "zeroize" -version = "1.8.1" +name = "zerocopy" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ - "zeroize_derive", + "zerocopy-derive", ] [[package]] -name = "zeroize_derive" -version = "1.4.2" +name = "zerocopy-derive" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", "syn 2.0.66", ] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/taptrade-cli-demo/coordinator/Cargo.toml b/taptrade-cli-demo/coordinator/Cargo.toml index 9cd2299..14fd4f5 100644 --- a/taptrade-cli-demo/coordinator/Cargo.toml +++ b/taptrade-cli-demo/coordinator/Cargo.toml @@ -7,11 +7,10 @@ edition = "2021" anyhow = "1.0.86" axum = "0.7.5" bdk = "0.29.0" -clap = { version = "4.5.4", features = ["derive", "cargo"] } dotenv = "0.15.0" -frost-secp256k1 = "1.0.0" reqwest = { version = "0.12.4", features = ["blocking", "json"] } serde = "1.0.203" +sqlx = { version = "0.7.4", features = ["runtime-tokio", "sqlite"] } tokio = "1.38.0" [profile.release] diff --git a/taptrade-cli-demo/coordinator/src/communication/mod.rs b/taptrade-cli-demo/coordinator/src/communication/mod.rs index 5275043..2abb8bd 100755 --- a/taptrade-cli-demo/coordinator/src/communication/mod.rs +++ b/taptrade-cli-demo/coordinator/src/communication/mod.rs @@ -2,59 +2,89 @@ mod api; use super::*; use api::{BondRequirementResponse, BondSubmissionRequest, OrderActivatedResponse, OrderRequest}; -use axum::{routing::post, Json, Router}; - +use axum::{ + http::StatusCode, response::IntoResponse, response::Response, routing::post, Extension, Json, + Router, +}; +use sqlx::sqlite::SqliteLockingMode; use std::net::SocketAddr; use tokio::net::TcpListener; // Handler function to process the received data -async fn receive_order(Json(order): Json) -> Json { - // Print the received data to the console - println!("Received order: {:?}", order); +async fn receive_order( + Extension(state): Extension>, + Json(order): Json, +) -> Result, AppError> { + // Connecting to SQLite database + let db_pool = state.db_pool.clone(); + let mut conn = db_pool.acquire().await.unwrap(); - // Access individual fields - // let robohash = &order.robohash_hex; - let amount = order.amount_satoshi; - // let order_type = &order.is_buy_order; - let bond_ratio = order.bond_ratio; - // let offer_duration= order.offer_duration_ts; + // sqlx::query!( + // "INSERT INTO orders (field1, field2) VALUES (?, ?)", + // order.field1, + // order.field2 + // ) - // Create a response struct - let response = BondRequirementResponse { - bond_address: "Order received successfully".to_string(), - // Add any other fields you want to include in your response - locking_amount_sat: (amount * bond_ratio as u64 / 100), - }; - - // Return the response as JSON - Json(response) + println!("Coordinator received new offer: {:?}", order); + Ok(Json(BondRequirementResponse { + bond_address: bond_address, + locking_amount_sat: order.amount_satoshi * order.bond_ratio as u64 / 100, + })) } -async fn submit_maker_bond( - Json(payload): Json, -) -> Json { - // Process the payload - // For now, we'll just return a dummy success response - let response = OrderActivatedResponse { - bond_locked_until_timestamp: 0 as u128, - order_id_hex: "Bond submitted successfully".to_string(), - }; +// async fn submit_maker_bond( +// Json(payload): Json, +// ) -> Result, AppError> { +// // Process the payload +// // For now, we'll just return a dummy success response +// let response = OrderActivatedResponse { +// bond_locked_until_timestamp: 0 as u128, +// order_id_hex: "Bond submitted successfully".to_string(), +// }; - // Create the JSON response - Json(response) -} +// // Create the JSON response +// Json(response) +// } -pub async fn api_server() -> Result<()> { +pub async fn api_server(coordinator: Coordinator) -> Result<()> { let app = Router::new() .route("/create-offer", post(receive_order)) - .route("/submit-maker-bond", post(submit_maker_bond)); + // .route("/submit-maker-bond", post(submit_maker_bond)); + .layer(Extension(coordinator)); // add other routes here // Run the server on localhost:9999 let addr = SocketAddr::from(([127, 0, 0, 1], 9999)); - println!("Listening on {}", addr); - let tcp = TcpListener::bind(&addr).await.unwrap(); axum::serve(tcp, app).await?; + println!("Listening on {}", addr); + Ok(()) } + +// ANYHOW ERROR HANDLING +// -------------- +// Make our own error that wraps `anyhow::Error`. +struct AppError(anyhow::Error); + +// Tell axum how to convert `AppError` into a response. +impl IntoResponse for AppError { + fn into_response(self) -> Response { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Something went wrong: {}", self.0), + ) + .into_response() + } +} + +// This enables using `?` on functions that return `Result<_, anyhow::Error>` to turn them into +// `Result<_, AppError>`. That way you don't need to do that manually. +impl From for AppError +where + E: Into, +{ + fn from(err: E) -> Self { + Self(err.into()) + } +} diff --git a/taptrade-cli-demo/coordinator/src/main.rs b/taptrade-cli-demo/coordinator/src/main.rs index 3707613..b2c9743 100755 --- a/taptrade-cli-demo/coordinator/src/main.rs +++ b/taptrade-cli-demo/coordinator/src/main.rs @@ -1,17 +1,34 @@ mod communication; mod coordinator; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Error, Result}; use communication::api_server; use dotenv::dotenv; use serde::{Deserialize, Serialize}; +use sqlx::{sqlite::SqlitePoolOptions, Pool, Sqlite}; use std::env; +use std::sync::Arc; + +#[derive(Clone, Debug)] +pub struct Coordinator { + pub db_pool: Arc>, +} // populate .env with values before starting #[tokio::main] async fn main() -> Result<()> { dotenv().ok(); + // Initialize the database pool + let db_pool = SqlitePoolOptions::new() + .connect("sqlite:./db/trades.db") + .await + .unwrap(); + let shared_db_pool: Arc> = Arc::new(db_pool); - api_server().await?; + let coordinator = Coordinator { + db_pool: shared_db_pool, + }; + + api_server(coordinator).await?; Ok(()) } From 55938c9ffca0a2607ec45e82d0d0e94f34b9791d Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 24 Jun 2024 17:19:16 +0000 Subject: [PATCH 5/5] coordinator wallet --- taptrade-cli-demo/coordinator/src/communication/mod.rs | 3 +++ taptrade-cli-demo/coordinator/src/main.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/taptrade-cli-demo/coordinator/src/communication/mod.rs b/taptrade-cli-demo/coordinator/src/communication/mod.rs index 2abb8bd..eeb5ade 100755 --- a/taptrade-cli-demo/coordinator/src/communication/mod.rs +++ b/taptrade-cli-demo/coordinator/src/communication/mod.rs @@ -25,6 +25,9 @@ async fn receive_order( // order.field2 // ) + // insert offer into sql database + // generate locking address for bond + println!("Coordinator received new offer: {:?}", order); Ok(Json(BondRequirementResponse { bond_address: bond_address, diff --git a/taptrade-cli-demo/coordinator/src/main.rs b/taptrade-cli-demo/coordinator/src/main.rs index b2c9743..bbb64f7 100755 --- a/taptrade-cli-demo/coordinator/src/main.rs +++ b/taptrade-cli-demo/coordinator/src/main.rs @@ -2,6 +2,8 @@ mod communication; mod coordinator; use anyhow::{anyhow, Error, Result}; +use bdk::database::MemoryDatabase; +use bdk::Wallet; use communication::api_server; use dotenv::dotenv; use serde::{Deserialize, Serialize}; @@ -12,6 +14,7 @@ use std::sync::Arc; #[derive(Clone, Debug)] pub struct Coordinator { pub db_pool: Arc>, + pub wallet: Arc>, // using sqlite for Wallet? } // populate .env with values before starting @@ -27,6 +30,7 @@ async fn main() -> Result<()> { let coordinator = Coordinator { db_pool: shared_db_pool, + wallet: // impl wallet }; api_server(coordinator).await?;