diff --git a/taptrade-cli-demo/coordinator/src/database/db_tests.rs b/taptrade-cli-demo/coordinator/src/database/db_tests.rs index aa99347..e7dcf80 100644 --- a/taptrade-cli-demo/coordinator/src/database/db_tests.rs +++ b/taptrade-cli-demo/coordinator/src/database/db_tests.rs @@ -205,6 +205,7 @@ async fn test_move_offer_to_active() -> Result<()> { payout_address: "1PayoutAddress".to_string(), musig_pub_nonce_hex: "musigPubNonceHex".to_string(), musig_pubkey_hex: "musigPubkeyHex".to_string(), + taproot_pubkey_hex: "taprootPubkeyHex".to_string(), }; // Call the move_offer_to_active function diff --git a/taptrade-cli-demo/coordinator/src/wallet/escrow_psbt.rs b/taptrade-cli-demo/coordinator/src/wallet/escrow_psbt.rs index f12c19e..ec57e56 100644 --- a/taptrade-cli-demo/coordinator/src/wallet/escrow_psbt.rs +++ b/taptrade-cli-demo/coordinator/src/wallet/escrow_psbt.rs @@ -15,9 +15,16 @@ pub struct EscrowPsbtConstructionData { } fn aggregate_musig_pubkeys(maker_musig_pubkey: &str, taker_musig_pubkey: &str) -> Result { - let pubkeys: [MuSig2PubKey; 2] = [maker_musig_pubkey.parse()?, taker_musig_pubkey.parse()?]; + let pubkeys: [MuSig2PubKey; 2] = [ + maker_musig_pubkey + .parse() + .context("Error parsing musig pk 1")?, + taker_musig_pubkey + .parse() + .context("Error parsing musig pk 2")?, + ]; - let key_agg_ctx = KeyAggContext::new(pubkeys)?; + let key_agg_ctx = KeyAggContext::new(pubkeys).context("Error aggregating musig pubkeys")?; let agg_pk: MuSig2PubKey = key_agg_ctx.aggregated_pubkey(); Ok(agg_pk.to_string()) @@ -39,15 +46,27 @@ pub fn build_escrow_transaction_output_descriptor( // ); let script_c: String = format!("and(pk({}),pk({}))", maker_pk, coordinator_pk); let script_d = format!("and(pk({}),pk({}))", taker_pk, coordinator_pk); - let script_e = format!("and({},after(12228))", maker_pk); - let script_f = format!("and_v(and_v(v:{},v:{}),after(2048))", maker_pk, taker_pk); + let script_e = format!("and(pk({}),after(12228))", maker_pk); + let script_f = format!("and(and(pk({}),pk({})),after(2048))", maker_pk, taker_pk); // let compiled_a = Concrete::::from_str(&script_a)?.compile::()?; // let compiled_b = Concrete::::from_str(&script_b)?.compile()?; - let compiled_c = Concrete::::from_str(&script_c)?.compile::()?; - let compiled_d = Concrete::::from_str(&script_d)?.compile::()?; - let compiled_e = Concrete::::from_str(&script_e)?.compile::()?; - let compiled_f = Concrete::::from_str(&script_f)?.compile::()?; + let compiled_c = Concrete::::from_str(&script_c) + .context("Failed to parse script_c")? + .compile::() + .context("Failed to compile script_c")?; + let compiled_d = Concrete::::from_str(&script_d) + .context("Failed to parse script_d")? + .compile::() + .context("Failed to compile script_d")?; + let compiled_e = Concrete::::from_str(&script_e) + .context("Failed to parse script_e")? + .compile::() + .context("Failed to compile script_e")?; + let compiled_f = Concrete::::from_str(&script_f) + .context("Failed to parse script_f")? + .compile::() + .context("Failed to compile script_f")?; // Create TapTree leaves // let tap_leaf_a = TapTree::Leaf(Arc::new(compiled_a)); @@ -70,7 +89,8 @@ pub fn build_escrow_transaction_output_descriptor( )?; // Create the descriptor - let descriptor = Descriptor::new_tr(internal_agg_musig_key, Some(final_tap_tree))?; + let descriptor = Descriptor::new_tr(internal_agg_musig_key, Some(final_tap_tree)) + .context("Error assembling escrow output descriptor")?; debug!("Escrow descriptor: {}", descriptor.to_string()); Ok(descriptor.to_string()) diff --git a/taptrade-cli-demo/coordinator/src/wallet/wallet_tests.rs b/taptrade-cli-demo/coordinator/src/wallet/wallet_tests.rs index 4dad8fc..627ce4c 100644 --- a/taptrade-cli-demo/coordinator/src/wallet/wallet_tests.rs +++ b/taptrade-cli-demo/coordinator/src/wallet/wallet_tests.rs @@ -1,8 +1,10 @@ +use std::collections::btree_map::Range; use std::time::Duration; use super::*; use bdk::bitcoin::Network; use bdk::database::MemoryDatabase; +use bdk::keys::GeneratableKey; use bdk::{blockchain::RpcBlockchain, Wallet}; async fn new_test_wallet(wallet_xprv: &str) -> CoordinatorWallet { dotenv().ok(); @@ -163,3 +165,36 @@ async fn test_invalid_bond_tx_low_fee_rate() { .to_string() .contains("Bond fee rate too low")); } + +#[test] +fn test_build_escrow_transaction_output_descriptor() { + // let seed: [u8; 32] = [ + // 0x1b, 0x2d, 0x3d, 0x4d, 0x5d, 0x6d, 0x7d, 0x8d, 0x9d, 0xad, 0xbd, 0xcd, 0xdd, 0xed, 0xfd, + // 0x0d, 0x1d, 0x2d, 0x3d, 0x4d, 0x5d, 0x6d, 0x8d, 0x8d, 0x9d, 0xbd, 0xbd, 0xcd, 0xdd, 0xed, + // 0xfd, 0x0d, + // ]; + // let xprv = ExtendedPrivKey::new_master(Network::Testnet, &seed).unwrap(); + // let pubkey = xprv + // .to_keypair(&secp256k1::Secp256k1::new()) + // .x_only_public_key() + // .0 + // .to_string(); + // dbg!(&pubkey); + let escrow_data = EscrowPsbtConstructionData { + taproot_pubkey_hex_maker: + "b709f64da734e04e35b129a65a7fae361cad8a9458d1abc4f0b45b7661a42fca".to_string(), + taproot_pubkey_hex_taker: + "4987f3de20a9b1fa6f76c6758934953a8d615e415f1a656f0f6563694b53107d".to_string(), + musig_pubkey_hex_maker: "b943789a0c9a16e27d7a9d27077eacd0fc664f01ff795f64e0f5fd257b4019e9" + .to_string(), + musig_pubkey_hex_taker: "a2e78a076b9ecfec8a8eb71ad5f0f29592d1559424f35ac25a0130d1a2880733" + .to_string(), + }; + let coordinator_pk = XOnlyPublicKey::from_str( + "d8e204cdaebec4c5a637311072c865858dc4f142b3848b8e6dde4143476535b5", + ) + .unwrap(); + let result = build_escrow_transaction_output_descriptor(&escrow_data, &coordinator_pk); + dbg!(&result); + assert!(result.is_ok()); +}