mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-29 06:03:14 +00:00
switch from println and dbg to logging
This commit is contained in:
136
taptrade-cli-demo/coordinator/Cargo.lock
generated
136
taptrade-cli-demo/coordinator/Cargo.lock
generated
@ -30,12 +30,70 @@ dependencies = [
|
|||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "allocator-api2"
|
name = "allocator-api2"
|
||||||
version = "0.2.18"
|
version = "0.2.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "0.6.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.7"
|
||||||
|
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.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
|
||||||
|
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",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.86"
|
version = "1.0.86"
|
||||||
@ -379,6 +437,12 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "const-oid"
|
name = "const-oid"
|
||||||
version = "0.9.6"
|
version = "0.9.6"
|
||||||
@ -394,8 +458,10 @@ dependencies = [
|
|||||||
"bdk",
|
"bdk",
|
||||||
"bitcoin 0.32.2",
|
"bitcoin 0.32.2",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
|
"env_logger",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"hex",
|
"hex",
|
||||||
|
"log",
|
||||||
"miniscript 12.0.0",
|
"miniscript 12.0.0",
|
||||||
"rand",
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
@ -560,6 +626,29 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_filter"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "env_logger"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"env_filter",
|
||||||
|
"humantime",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@ -940,6 +1029,12 @@ version = "1.0.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@ -1049,6 +1144,12 @@ version = "2.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.11"
|
version = "1.0.11"
|
||||||
@ -1545,6 +1646,35 @@ dependencies = [
|
|||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.12.5"
|
version = "0.12.5"
|
||||||
@ -2535,6 +2665,12 @@ version = "2.1.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
@ -21,6 +21,8 @@ serde = "1.0.203"
|
|||||||
sqlx = { version = "0.7.4", features = ["runtime-tokio", "sqlite"] }
|
sqlx = { version = "0.7.4", features = ["runtime-tokio", "sqlite"] }
|
||||||
tokio = { version = "1.38.0", features = ["full"] }
|
tokio = { version = "1.38.0", features = ["full"] }
|
||||||
tower = "0.4.13"
|
tower = "0.4.13"
|
||||||
|
log = "0.4.22"
|
||||||
|
env_logger = "0.11.3"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
@ -38,7 +38,7 @@ async fn receive_order(
|
|||||||
database
|
database
|
||||||
.insert_new_maker_request(&order, &bond_requirements)
|
.insert_new_maker_request(&order, &bond_requirements)
|
||||||
.await?;
|
.await?;
|
||||||
println!("Coordinator received new offer: {:?}", order);
|
debug!("Coordinator received new offer: {:?}", order);
|
||||||
Ok(Json(bond_requirements))
|
Ok(Json(bond_requirements))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ async fn submit_maker_bond(
|
|||||||
Extension(wallet): Extension<Arc<CoordinatorWallet>>,
|
Extension(wallet): Extension<Arc<CoordinatorWallet>>,
|
||||||
Json(payload): Json<BondSubmissionRequest>,
|
Json(payload): Json<BondSubmissionRequest>,
|
||||||
) -> Result<Response, AppError> {
|
) -> Result<Response, AppError> {
|
||||||
println!("\n\nReceived maker bond: {:?}", payload);
|
debug!("\n\nReceived maker bond: {:?}", payload);
|
||||||
let bond_requirements = if let Ok(requirements) = database
|
let bond_requirements = if let Ok(requirements) = database
|
||||||
.fetch_bond_requirements(&payload.robohash_hex)
|
.fetch_bond_requirements(&payload.robohash_hex)
|
||||||
.await
|
.await
|
||||||
@ -68,7 +68,7 @@ async fn submit_maker_bond(
|
|||||||
return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("\nBond validation successful");
|
trace!("\nBond validation successful");
|
||||||
let offer_id_hex: String = generate_random_order_id(16); // 16 bytes random offer id, maybe a different system makes more sense later on? (uuid or increasing counter...)
|
let offer_id_hex: String = generate_random_order_id(16); // 16 bytes random offer id, maybe a different system makes more sense later on? (uuid or increasing counter...)
|
||||||
// create address for taker bond
|
// create address for taker bond
|
||||||
let new_taker_bond_address = wallet.get_new_address().await.context(format!(
|
let new_taker_bond_address = wallet.get_new_address().await.context(format!(
|
||||||
@ -236,7 +236,7 @@ pub async fn api_server(coordinator: Arc<Coordinator>) -> Result<()> {
|
|||||||
let port: u16 = env::var("PORT")
|
let port: u16 = env::var("PORT")
|
||||||
.unwrap_or_else(|_| "9999".to_string())
|
.unwrap_or_else(|_| "9999".to_string())
|
||||||
.parse()?;
|
.parse()?;
|
||||||
println!("Listening on {}", port);
|
info!("Listening on {}", port);
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], port));
|
let addr = SocketAddr::from(([127, 0, 0, 1], port));
|
||||||
let tcp = TcpListener::bind(&addr).await.unwrap();
|
let tcp = TcpListener::bind(&addr).await.unwrap();
|
||||||
axum::serve(tcp, app).await?;
|
axum::serve(tcp, app).await?;
|
||||||
|
@ -97,7 +97,7 @@ async fn create_script(
|
|||||||
|
|
||||||
// Create the descriptor
|
// Create the descriptor
|
||||||
let descriptor = Descriptor::new_tr(dummy_internal_key, Some(tap_tree))?;
|
let descriptor = Descriptor::new_tr(dummy_internal_key, Some(tap_tree))?;
|
||||||
println!("{}", descriptor);
|
debug!("{}", descriptor);
|
||||||
|
|
||||||
Ok(descriptor)
|
Ok(descriptor)
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ pub async fn create_psbt(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Step 2: Print the first address
|
// Step 2: Print the first address
|
||||||
println!(
|
info!(
|
||||||
"Deposit funds here: {:?}",
|
"Deposit funds here: {:?}",
|
||||||
wallet.get_address(AddressIndex::New)?
|
wallet.get_address(AddressIndex::New)?
|
||||||
);
|
);
|
||||||
@ -129,7 +129,7 @@ pub async fn create_psbt(
|
|||||||
// Step 4: Print balance
|
// Step 4: Print balance
|
||||||
let blockchain = EsploraBlockchain::new("https://blockstream.info/testnet/api", 20);
|
let blockchain = EsploraBlockchain::new("https://blockstream.info/testnet/api", 20);
|
||||||
wallet.sync(&blockchain, SyncOptions::default())?;
|
wallet.sync(&blockchain, SyncOptions::default())?;
|
||||||
println!("{:#?}", wallet.get_balance()?);
|
info!("{:#?}", wallet.get_balance()?);
|
||||||
|
|
||||||
let maker_utxos = vec![/* UTXO details here */];
|
let maker_utxos = vec![/* UTXO details here */];
|
||||||
let taker_utxos = vec![/* UTXO details here */];
|
let taker_utxos = vec![/* UTXO details here */];
|
||||||
@ -149,7 +149,7 @@ pub async fn create_psbt(
|
|||||||
.policy_path(BTreeMap::new(), KeychainKind::External);
|
.policy_path(BTreeMap::new(), KeychainKind::External);
|
||||||
|
|
||||||
let (psbt, tx_details) = tx_builder.finish()?;
|
let (psbt, tx_details) = tx_builder.finish()?;
|
||||||
println!("PSBT: {:?}", psbt);
|
debug!("PSBT: {:?}", psbt);
|
||||||
Ok(psbt)
|
Ok(psbt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ fn taker_unresponsive(
|
|||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Maker signs the PSBT
|
// Maker signs the PSBT
|
||||||
let maker_signed_psbt = wallet.sign(&mut psbt.clone(), SignOptions::default())?;
|
let maker_signed_psbt = wallet.sign(&mut psbt.clone(), SignOptions::default())?;
|
||||||
println!("Maker signed PSBT: {:?}", maker_signed_psbt);
|
debug!("Maker signed PSBT: {:?}", maker_signed_psbt);
|
||||||
|
|
||||||
// If taker is unresponsive, coordinator signs using alternative path
|
// If taker is unresponsive, coordinator signs using alternative path
|
||||||
let taker_responsive = false; // Assume taker is unresponsive
|
let taker_responsive = false; // Assume taker is unresponsive
|
||||||
@ -187,7 +187,7 @@ fn taker_unresponsive(
|
|||||||
|
|
||||||
let (coordinator_psbt, _details) = coordinator_tx_builder.finish()?;
|
let (coordinator_psbt, _details) = coordinator_tx_builder.finish()?;
|
||||||
let coordinator_signed_psbt = wallet.sign(&mut coordinator_psbt, SignOptions::default())?;
|
let coordinator_signed_psbt = wallet.sign(&mut coordinator_psbt, SignOptions::default())?;
|
||||||
println!("Coordinator signed PSBT: {:?}", coordinator_signed_psbt);
|
debug!("Coordinator signed PSBT: {:?}", coordinator_signed_psbt);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ impl CoordinatorDB {
|
|||||||
)
|
)
|
||||||
.collect();
|
.collect();
|
||||||
if available_offers.is_empty() {
|
if available_offers.is_empty() {
|
||||||
println!("empty");
|
debug!("No available offers in db...");
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
Ok(Some(available_offers))
|
Ok(Some(available_offers))
|
||||||
|
@ -9,6 +9,7 @@ use coordinator::monitoring::monitor_bonds;
|
|||||||
use coordinator::monitoring::*;
|
use coordinator::monitoring::*;
|
||||||
use database::CoordinatorDB;
|
use database::CoordinatorDB;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
use log::{debug, error, info, trace, warn};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use std::{env, sync::Arc};
|
use std::{env, sync::Arc};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
@ -22,6 +23,9 @@ pub struct Coordinator {
|
|||||||
// populate .env with values before starting
|
// populate .env with values before starting
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
env_logger::builder()
|
||||||
|
.filter_level(log::LevelFilter::Info)
|
||||||
|
.init();
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
// Initialize the database pool
|
// Initialize the database pool
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod taker_requests;
|
pub mod taker_requests;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{OfferType, TraderSettings},
|
cli::{OfferType, TraderSettings},
|
||||||
trading::utils::ActiveOffer,
|
trading::utils::ActiveOffer,
|
||||||
@ -40,13 +41,19 @@ impl BondRequirementResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch(trader_setup: &TraderSettings) -> Result<BondRequirementResponse> {
|
pub fn fetch(trader_setup: &TraderSettings) -> Result<BondRequirementResponse> {
|
||||||
|
trace!("Fetching bond requirements from coordinator. (create-offer)");
|
||||||
let client = reqwest::blocking::Client::new();
|
let client = reqwest::blocking::Client::new();
|
||||||
let endpoint = format!("{}{}", trader_setup.coordinator_endpoint, "/create-offer");
|
let endpoint = format!("{}{}", trader_setup.coordinator_endpoint, "/create-offer");
|
||||||
let res = client
|
let res = match client
|
||||||
.post(endpoint)
|
.post(endpoint)
|
||||||
.json(&Self::_format_request(trader_setup))
|
.json(&Self::_format_request(trader_setup))
|
||||||
.send()?;
|
.send()
|
||||||
|
{
|
||||||
|
Ok(res) => res,
|
||||||
|
Err(e) => return Err(anyhow!("Error calling /create-offer: {}", e)),
|
||||||
|
};
|
||||||
let status_code = res.status();
|
let status_code = res.status();
|
||||||
|
debug!("/create-offer Response status code: {}", status_code);
|
||||||
match res.json::<BondRequirementResponse>() {
|
match res.json::<BondRequirementResponse>() {
|
||||||
Ok(response) => Ok(response),
|
Ok(response) => Ok(response),
|
||||||
Err(e) => Err(anyhow!(
|
Err(e) => Err(anyhow!(
|
||||||
|
@ -6,7 +6,7 @@ mod wallet;
|
|||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use cli::CliSettings;
|
use cli::CliSettings;
|
||||||
use core::panic;
|
use log::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
fn start_trade_pipeline(cli_input: &CliSettings) -> Result<()> {
|
fn start_trade_pipeline(cli_input: &CliSettings) -> Result<()> {
|
||||||
match cli_input {
|
match cli_input {
|
||||||
@ -20,10 +20,12 @@ fn start_trade_pipeline(cli_input: &CliSettings) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// env_logger::builder().filter_level(log::LevelFilter::Debug).init(); // enable to show extended BDK debug messages
|
env_logger::builder()
|
||||||
|
.filter_level(log::LevelFilter::Info)
|
||||||
|
.init();
|
||||||
|
|
||||||
let mode = CliSettings::parse_cli_args()?;
|
let mode = CliSettings::parse_cli_args()?;
|
||||||
dbg!("CLI input :", &mode);
|
info!("CLI input : {:#?}", &mode);
|
||||||
start_trade_pipeline(&mode)?;
|
start_trade_pipeline(&mode)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -7,13 +7,7 @@ impl ActiveOffer {
|
|||||||
maker_config: &TraderSettings,
|
maker_config: &TraderSettings,
|
||||||
) -> Result<ActiveOffer> {
|
) -> Result<ActiveOffer> {
|
||||||
let offer_conditions = BondRequirementResponse::fetch(maker_config)?;
|
let offer_conditions = BondRequirementResponse::fetch(maker_config)?;
|
||||||
// let offer_conditions = OfferCreationResponse {
|
debug!("Offer conditions fetched: {:#?}", &offer_conditions);
|
||||||
// // hardcoded for testing, locking_address is owned by .env xprv
|
|
||||||
// locking_amount_sat: 90000,
|
|
||||||
// bond_address: "tb1pfdvgfzwp8vhmelpv8w9kezz7nsmxw68jz6yehgze6mzx0t6r9t2qv9ynmm"
|
|
||||||
// .to_string(),
|
|
||||||
// };
|
|
||||||
|
|
||||||
let (bond, mut musig_data, payout_address) =
|
let (bond, mut musig_data, payout_address) =
|
||||||
trading_wallet.trade_onchain_assembly(&offer_conditions, maker_config)?;
|
trading_wallet.trade_onchain_assembly(&offer_conditions, maker_config)?;
|
||||||
let submission_result = BondSubmissionRequest::send_maker(
|
let submission_result = BondSubmissionRequest::send_maker(
|
||||||
|
@ -3,6 +3,7 @@ pub mod taker_utils;
|
|||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
use self::utils::ActiveOffer;
|
use self::utils::ActiveOffer;
|
||||||
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::TraderSettings,
|
cli::TraderSettings,
|
||||||
communication::api::{
|
communication::api::{
|
||||||
@ -16,7 +17,6 @@ use crate::{
|
|||||||
TradingWallet,
|
TradingWallet,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
|
||||||
use bdk::{
|
use bdk::{
|
||||||
bitcoin::{amount::serde::as_btc::deserialize, psbt::PartiallySignedTransaction},
|
bitcoin::{amount::serde::as_btc::deserialize, psbt::PartiallySignedTransaction},
|
||||||
database::MemoryDatabase,
|
database::MemoryDatabase,
|
||||||
@ -28,7 +28,7 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
|
|||||||
let wallet = TradingWallet::load_wallet(maker_config)?; // initialize the wallet with xprv
|
let wallet = TradingWallet::load_wallet(maker_config)?; // initialize the wallet with xprv
|
||||||
|
|
||||||
let offer = ActiveOffer::create(&wallet, maker_config)?;
|
let offer = ActiveOffer::create(&wallet, maker_config)?;
|
||||||
dbg!(&offer);
|
info!("Maker offer created: {:#?}", &offer);
|
||||||
|
|
||||||
let mut escrow_contract_psbt = offer.wait_until_taken(maker_config)?;
|
let mut escrow_contract_psbt = offer.wait_until_taken(maker_config)?;
|
||||||
wallet
|
wallet
|
||||||
@ -47,10 +47,10 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
|
|||||||
if offer.fiat_confirmation_cli_input(maker_config)? {
|
if offer.fiat_confirmation_cli_input(maker_config)? {
|
||||||
// this represents the "confirm payment" / "confirm fiat recieved" button
|
// this represents the "confirm payment" / "confirm fiat recieved" button
|
||||||
TradeObligationsSatisfied::submit(&offer.offer_id_hex, maker_config)?;
|
TradeObligationsSatisfied::submit(&offer.offer_id_hex, maker_config)?;
|
||||||
println!("Waiting for other party to confirm the trade.");
|
info!("Waiting for other party to confirm the trade.");
|
||||||
let payout_keyspend_psbt = IsOfferReadyRequest::poll_payout(maker_config, &offer)?;
|
let payout_keyspend_psbt = IsOfferReadyRequest::poll_payout(maker_config, &offer)?;
|
||||||
} else {
|
} else {
|
||||||
println!("Trade failed.");
|
error!("Trade failed.");
|
||||||
panic!("Escrow to be implemented!");
|
panic!("Escrow to be implemented!");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Reference in New Issue
Block a user