mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-19 17:23:26 +00:00
fix musig pubkey submission
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -5,5 +5,6 @@
|
|||||||
],
|
],
|
||||||
"nixEnvSelector.suggestion": true,
|
"nixEnvSelector.suggestion": true,
|
||||||
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
|
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix",
|
||||||
"lldb.showDisassembly": "never"
|
"lldb.showDisassembly": "never",
|
||||||
|
"vim.useSystemClipboard": true
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,6 @@ pub async fn fetch_escrow_confirmation_status(
|
|||||||
Ok(status) => status,
|
Ok(status) => status,
|
||||||
Err(e) => return Err(FetchEscrowConfirmationError::Database(e.to_string())),
|
Err(e) => return Err(FetchEscrowConfirmationError::Database(e.to_string())),
|
||||||
} {
|
} {
|
||||||
// rust smh
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
Err(FetchEscrowConfirmationError::NotFound)
|
Err(FetchEscrowConfirmationError::NotFound)
|
||||||
|
@ -32,14 +32,17 @@ impl EscrowPsbtConstructionData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aggregate_musig_pubkeys(maker_musig_pubkey: &str, taker_musig_pubkey: &str) -> Result<String> {
|
pub fn aggregate_musig_pubkeys(
|
||||||
|
maker_musig_pubkey: &str,
|
||||||
|
taker_musig_pubkey: &str,
|
||||||
|
) -> Result<String> {
|
||||||
|
debug!(
|
||||||
|
"Aggregating musig pubkeys: {} and {}",
|
||||||
|
maker_musig_pubkey, taker_musig_pubkey
|
||||||
|
);
|
||||||
let pubkeys: [MuSig2PubKey; 2] = [
|
let pubkeys: [MuSig2PubKey; 2] = [
|
||||||
maker_musig_pubkey
|
MuSig2PubKey::from_str(maker_musig_pubkey).context("Error parsing musig pk 1")?,
|
||||||
.parse()
|
MuSig2PubKey::from_str(taker_musig_pubkey).context("Error parsing musig pk 2")?,
|
||||||
.context("Error parsing musig pk 1")?,
|
|
||||||
taker_musig_pubkey
|
|
||||||
.parse()
|
|
||||||
.context("Error parsing musig pk 2")?,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let key_agg_ctx = KeyAggContext::new(pubkeys).context("Error aggregating musig pubkeys")?;
|
let key_agg_ctx = KeyAggContext::new(pubkeys).context("Error aggregating musig pubkeys")?;
|
||||||
|
@ -269,3 +269,12 @@ async fn test_build_escrow_transaction_output_descriptor() {
|
|||||||
dbg!(&result); // cargo test -- --nocapture to see the output
|
dbg!(&result); // cargo test -- --nocapture to see the output
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_aggregate_musig_pubkeys() {
|
||||||
|
let agg_pk_result = aggregate_musig_pubkeys(
|
||||||
|
"02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9",
|
||||||
|
"03DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659",
|
||||||
|
);
|
||||||
|
assert!(agg_pk_result.is_ok());
|
||||||
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
use super::{api::*, *};
|
use super::{api::*, *};
|
||||||
|
|
||||||
@ -78,10 +79,19 @@ impl OfferPsbtRequest {
|
|||||||
taker_config.coordinator_endpoint, "/submit-taker-bond"
|
taker_config.coordinator_endpoint, "/submit-taker-bond"
|
||||||
))
|
))
|
||||||
.json(&request)
|
.json(&request)
|
||||||
.send()?
|
.send()?;
|
||||||
.json::<OfferTakenResponse>()?;
|
match res.status() {
|
||||||
|
StatusCode::OK => {
|
||||||
debug!("Trader received escrow psbt");
|
debug!("Taker bond accepted");
|
||||||
Ok(res)
|
Ok(res.json::<OfferTakenResponse>()?)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
debug!(
|
||||||
|
"Taker bond submission failed: status code: {}",
|
||||||
|
res.status()
|
||||||
|
);
|
||||||
|
Err(anyhow!("Taker bond rejected"))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ impl ActiveOffer {
|
|||||||
signed_bond_hex: serialize_hex(&bond.clone().extract_tx()),
|
signed_bond_hex: serialize_hex(&bond.clone().extract_tx()),
|
||||||
payout_address: payout_address.address.to_string(),
|
payout_address: payout_address.address.to_string(),
|
||||||
musig_pub_nonce_hex: hex::encode(musig_data.nonce.get_pub_for_sharing()?.serialize()),
|
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()),
|
musig_pubkey_hex: hex::encode(musig_data.public_key.serialize()),
|
||||||
taproot_pubkey_hex: hex::encode(&trading_wallet.taproot_pubkey.serialize()),
|
taproot_pubkey_hex: hex::encode(&trading_wallet.taproot_pubkey.serialize()),
|
||||||
bdk_psbt_inputs_hex_csv: psbt_inputs_hex_csv.clone(),
|
bdk_psbt_inputs_hex_csv: psbt_inputs_hex_csv.clone(),
|
||||||
client_change_address: escrow_change_address.clone(),
|
client_change_address: escrow_change_address.clone(),
|
||||||
|
@ -32,7 +32,7 @@ impl ActiveOffer {
|
|||||||
payout_address: payout_address.address.to_string(),
|
payout_address: payout_address.address.to_string(),
|
||||||
taproot_pubkey_hex: trading_wallet.taproot_pubkey.to_string(),
|
taproot_pubkey_hex: trading_wallet.taproot_pubkey.to_string(),
|
||||||
musig_pub_nonce_hex: musig_data.nonce.get_pub_for_sharing()?.to_string(),
|
musig_pub_nonce_hex: musig_data.nonce.get_pub_for_sharing()?.to_string(),
|
||||||
musig_pubkey_hex: musig_data.public_key.to_string(),
|
musig_pubkey_hex: hex::encode(musig_data.public_key.serialize()),
|
||||||
bdk_psbt_inputs_hex_csv: bdk_psbt_inputs_hex_csv.clone(),
|
bdk_psbt_inputs_hex_csv: bdk_psbt_inputs_hex_csv.clone(),
|
||||||
client_change_address: client_change_address.clone(),
|
client_change_address: client_change_address.clone(),
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ use bond::Bond;
|
|||||||
use cli::OfferType;
|
use cli::OfferType;
|
||||||
use musig2::MuSigData;
|
use musig2::MuSigData;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::str::FromStr;
|
use std::{ops::Add, str::FromStr};
|
||||||
use wallet_utils::get_seed;
|
use wallet_utils::get_seed;
|
||||||
|
|
||||||
pub struct TradingWallet {
|
pub struct TradingWallet {
|
||||||
@ -74,7 +74,11 @@ impl TradingWallet {
|
|||||||
.x_only_public_key();
|
.x_only_public_key();
|
||||||
|
|
||||||
wallet.sync(&backend, SyncOptions::default())?;
|
wallet.sync(&backend, SyncOptions::default())?;
|
||||||
dbg!("Balance: {} SAT", wallet.get_balance()?);
|
dbg!(
|
||||||
|
"Balance: {} SAT\nnew address: {}",
|
||||||
|
wallet.get_balance()?,
|
||||||
|
wallet.get_address(AddressIndex::New)?.address
|
||||||
|
);
|
||||||
Ok(TradingWallet {
|
Ok(TradingWallet {
|
||||||
wallet,
|
wallet,
|
||||||
backend,
|
backend,
|
||||||
|
Reference in New Issue
Block a user