mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-09-12 20:56:28 +00:00
fix bond submission/api
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -4,5 +4,6 @@
|
||||
"${workspaceFolder}/taptrade-cli-demo/trader/Cargo.toml",
|
||||
],
|
||||
"nixEnvSelector.suggestion": true,
|
||||
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix"
|
||||
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
|
||||
"lldb.showDisassembly": "never"
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ pub struct PublicOffers {
|
||||
pub struct OfferTakenResponse {
|
||||
pub escrow_psbt_hex: String,
|
||||
pub escrow_output_descriptor: String,
|
||||
pub escrow_tx_fee_address: String,
|
||||
pub escrow_amount_maker_sat: u64,
|
||||
pub escrow_amount_taker_sat: u64,
|
||||
pub escrow_fee_sat_per_participant: u64,
|
||||
|
@ -150,7 +150,6 @@ pub async fn handle_taker_bond(
|
||||
Ok(OfferTakenResponse {
|
||||
escrow_psbt_hex: escrow_output_data.escrow_psbt_hex,
|
||||
escrow_output_descriptor: escrow_output_data.escrow_output_descriptor,
|
||||
escrow_tx_fee_address: escrow_output_data.escrow_tx_fee_address,
|
||||
escrow_amount_maker_sat: escrow_output_data.escrow_amount_maker_sat,
|
||||
escrow_amount_taker_sat: escrow_output_data.escrow_amount_taker_sat,
|
||||
escrow_fee_sat_per_participant: escrow_output_data.escrow_fee_sat_per_participant,
|
||||
@ -165,7 +164,6 @@ pub async fn get_offer_status_maker(
|
||||
|
||||
let EscrowPsbt {
|
||||
escrow_output_descriptor,
|
||||
escrow_tx_fee_address,
|
||||
escrow_amount_maker_sat,
|
||||
escrow_amount_taker_sat,
|
||||
escrow_fee_sat_per_participant,
|
||||
@ -186,7 +184,6 @@ pub async fn get_offer_status_maker(
|
||||
Ok(OfferTakenResponse {
|
||||
escrow_psbt_hex,
|
||||
escrow_output_descriptor,
|
||||
escrow_tx_fee_address,
|
||||
escrow_amount_maker_sat,
|
||||
escrow_amount_taker_sat,
|
||||
escrow_fee_sat_per_participant,
|
||||
|
@ -375,9 +375,9 @@ impl CoordinatorDB {
|
||||
"INSERT OR REPLACE INTO taken_offers (offer_id, robohash_maker, robohash_taker, is_buy_order, amount_sat,
|
||||
bond_ratio, offer_duration_ts, bond_address_maker, bond_address_taker, bond_amount_sat, bond_tx_hex_maker,
|
||||
bond_tx_hex_taker, payout_address_maker, payout_address_taker, taproot_pubkey_hex_maker, taproot_pubkey_hex_taker, musig_pub_nonce_hex_maker, musig_pubkey_hex_maker,
|
||||
musig_pub_nonce_hex_taker, musig_pubkey_hex_taker, escrow_psbt_hex, escrow_output_descriptor, escrow_tx_fee_address, escrow_psbt_is_confirmed, escrow_ongoing,
|
||||
musig_pub_nonce_hex_taker, musig_pubkey_hex_taker, escrow_psbt_hex, escrow_output_descriptor, escrow_psbt_is_confirmed, escrow_ongoing,
|
||||
escrow_taproot_pk_coordinator, escrow_amount_maker_sat, escrow_amount_taker_sat, escrow_fee_per_participant)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
)
|
||||
.bind(public_offer.offer_id)
|
||||
.bind(public_offer.robohash_maker)
|
||||
@ -401,7 +401,6 @@ impl CoordinatorDB {
|
||||
.bind(trade_and_taker_info.trade_data.musig_pubkey_hex.clone())
|
||||
.bind(&escrow_tx_data.escrow_output_descriptor)
|
||||
.bind(&escrow_tx_data.escrow_psbt_hex)
|
||||
.bind(&escrow_tx_data.escrow_tx_fee_address)
|
||||
.bind(0)
|
||||
.bind(0)
|
||||
.bind(&escrow_tx_data.coordinator_xonly_escrow_pk)
|
||||
@ -419,7 +418,7 @@ impl CoordinatorDB {
|
||||
offer_id_hex: &str,
|
||||
) -> Result<Option<EscrowPsbt>> {
|
||||
let offer = sqlx::query(
|
||||
"SELECT escrow_output_descriptor, escrow_tx_fee_address, escrow_amount_maker_sat,
|
||||
"SELECT escrow_output_descriptor, escrow_amount_maker_sat,
|
||||
escrow_amount_taker_sat, escrow_fee_per_participant, escrow_taproot_pk_coordinator
|
||||
FROM taken_offers WHERE offer_id = ?",
|
||||
)
|
||||
@ -431,7 +430,6 @@ impl CoordinatorDB {
|
||||
None => return Ok(None),
|
||||
};
|
||||
let escrow_output_descriptor = offer.try_get::<String, _>("escrow_output_descriptor")?;
|
||||
let escrow_tx_fee_address = offer.try_get::<String, _>("escrow_tx_fee_address")?;
|
||||
let escrow_amount_maker_sat = offer.try_get::<i64, _>("escrow_amount_maker_sat")? as u64;
|
||||
let escrow_amount_taker_sat = offer.try_get::<i64, _>("escrow_amount_taker_sat")? as u64;
|
||||
let escrow_fee_sat_per_participant =
|
||||
@ -443,7 +441,6 @@ impl CoordinatorDB {
|
||||
Ok(Some(EscrowPsbt {
|
||||
escrow_psbt_hex,
|
||||
escrow_output_descriptor,
|
||||
escrow_tx_fee_address,
|
||||
coordinator_xonly_escrow_pk,
|
||||
escrow_amount_maker_sat,
|
||||
escrow_amount_taker_sat,
|
||||
|
@ -32,7 +32,7 @@ pub struct Coordinator {
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
env_logger::builder()
|
||||
.filter_module("coordinator", log::LevelFilter::Debug)
|
||||
.filter_module("coordinator", log::LevelFilter::Trace)
|
||||
.filter_level(log::LevelFilter::Info)
|
||||
.init();
|
||||
dotenv().ok();
|
||||
|
@ -45,7 +45,6 @@ pub struct CoordinatorWallet<D: bdk::database::BatchDatabase> {
|
||||
pub struct EscrowPsbt {
|
||||
pub escrow_psbt_hex: String,
|
||||
pub escrow_output_descriptor: String,
|
||||
pub escrow_tx_fee_address: String,
|
||||
pub coordinator_xonly_escrow_pk: String,
|
||||
pub escrow_amount_maker_sat: u64,
|
||||
pub escrow_amount_taker_sat: u64,
|
||||
@ -126,7 +125,7 @@ impl<D: bdk::database::BatchDatabase> CoordinatorWallet<D> {
|
||||
bond_tx_hex: &str,
|
||||
requirements: &BondRequirements,
|
||||
) -> Result<()> {
|
||||
debug!("Validating bond in validate_bond_tx_hex()");
|
||||
debug!("Validating bond in validate_bond_tx_hex(): {}", bond_tx_hex);
|
||||
let dummy_monitoring_bond = MonitoringBond {
|
||||
bond_tx_hex: bond_tx_hex.to_string(),
|
||||
trade_id_hex: "0".to_string(),
|
||||
@ -157,6 +156,7 @@ impl<D: bdk::database::BatchDatabase> CoordinatorWallet<D> {
|
||||
{
|
||||
let wallet = self.wallet.lock().await;
|
||||
for bond in bonds.as_ref().iter() {
|
||||
trace!("Deserializing bond in validate_bonds()");
|
||||
let tx: Transaction = deserialize(&hex::decode(&bond.bond_tx_hex)?)?;
|
||||
debug!("Validating bond in validate_bonds()");
|
||||
// we need to test this with signed and invalid/unsigned transactions
|
||||
@ -329,7 +329,6 @@ impl<D: bdk::database::BatchDatabase> CoordinatorWallet<D> {
|
||||
Ok(EscrowPsbt {
|
||||
escrow_psbt_hex: escrow_psbt.to_string(),
|
||||
escrow_output_descriptor,
|
||||
escrow_tx_fee_address: escrow_coordinator_fee_address.to_string(),
|
||||
coordinator_xonly_escrow_pk: coordinator_escrow_pk.to_string(),
|
||||
escrow_amount_maker_sat,
|
||||
escrow_amount_taker_sat,
|
||||
|
@ -43,14 +43,13 @@ pub struct OrderActivatedResponse {
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct OfferTakenRequest {
|
||||
pub robohash_hex: String,
|
||||
pub order_id_hex: String,
|
||||
pub offer_id_hex: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct OfferTakenResponse {
|
||||
pub escrow_psbt_hex: String,
|
||||
pub escrow_output_descriptor: String,
|
||||
pub escrow_tx_fee_address: String,
|
||||
pub escrow_amount_maker_sat: u64,
|
||||
pub escrow_amount_taker_sat: u64,
|
||||
pub escrow_fee_sat_per_participant: u64,
|
||||
|
@ -136,9 +136,10 @@ impl OfferTakenResponse {
|
||||
offer: &ActiveOffer,
|
||||
trader_setup: &TraderSettings,
|
||||
) -> Result<Option<OfferTakenResponse>> {
|
||||
trace!("Polling offer status from coordinator.");
|
||||
let request = OfferTakenRequest {
|
||||
robohash_hex: trader_setup.robosats_robohash_hex.clone(),
|
||||
order_id_hex: offer.offer_id_hex.clone(),
|
||||
offer_id_hex: offer.offer_id_hex.clone(),
|
||||
};
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let res = client
|
||||
|
@ -21,6 +21,7 @@ fn start_trade_pipeline(cli_input: &CliSettings) -> Result<()> {
|
||||
|
||||
fn main() -> Result<()> {
|
||||
env_logger::builder()
|
||||
.filter_module("trader", log::LevelFilter::Debug)
|
||||
.filter_level(log::LevelFilter::Info)
|
||||
.init();
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
use bdk::bitcoin::amount::serde::as_btc::opt::serialize;
|
||||
use bdk::bitcoin::consensus::encode::serialize_hex;
|
||||
use bdk::bitcoin::Transaction;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::utils::*;
|
||||
use super::*;
|
||||
|
||||
@ -14,9 +19,13 @@ impl ActiveOffer {
|
||||
let (psbt_inputs_hex_csv, escrow_change_address) =
|
||||
trading_wallet.get_escrow_psbt_inputs(offer_conditions.locking_amount_sat as i64)?;
|
||||
|
||||
debug!(
|
||||
"Submitting maker bond: {:#?}",
|
||||
hex::encode(bond.serialize())
|
||||
);
|
||||
let bond_submission_request = BondSubmissionRequest {
|
||||
robohash_hex: maker_config.robosats_robohash_hex.clone(),
|
||||
signed_bond_hex: bond.to_string(),
|
||||
signed_bond_hex: serialize_hex(&bond.clone().extract_tx()),
|
||||
payout_address: payout_address.address.to_string(),
|
||||
musig_pub_nonce_hex: hex::encode(musig_data.nonce.get_pub_for_sharing()?.serialize()),
|
||||
musig_pubkey_hex: hex::encode(musig_data.public_key.to_string()),
|
||||
|
@ -1,3 +1,4 @@
|
||||
use bdk::bitcoin::consensus::encode::serialize_hex;
|
||||
use bdk::electrum_client::Request;
|
||||
|
||||
use crate::communication::api::{IsOfferReadyRequest, OfferPsbtRequest, PsbtSubmissionRequest};
|
||||
@ -27,7 +28,7 @@ impl ActiveOffer {
|
||||
|
||||
let bond_submission_request = BondSubmissionRequest {
|
||||
robohash_hex: taker_config.robosats_robohash_hex.clone(),
|
||||
signed_bond_hex: bond.to_string(),
|
||||
signed_bond_hex: serialize_hex(&bond.clone().extract_tx()),
|
||||
payout_address: payout_address.address.to_string(),
|
||||
taproot_pubkey_hex: trading_wallet.taproot_pubkey.to_string(),
|
||||
musig_pub_nonce_hex: musig_data.nonce.get_pub_for_sharing()?.to_string(),
|
||||
|
@ -1,8 +1,9 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
|
||||
use bdk::bitcoin::amount::serde::as_btc::opt::deserialize;
|
||||
use bdk::bitcoin::psbt::PartiallySignedTransaction;
|
||||
use bdk::bitcoin::ScriptBuf;
|
||||
use bdk::bitcoin::{Address, Network};
|
||||
use bdk::bitcoin::{ScriptBuf, Transaction};
|
||||
use bdk::{
|
||||
database::MemoryDatabase, wallet::coin_selection::BranchAndBoundCoinSelection, FeeRate,
|
||||
SignOptions, Wallet,
|
||||
|
Reference in New Issue
Block a user