mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-08-10 12:00:08 +00:00
working on escrow psbt creation
This commit is contained in:
@ -64,6 +64,9 @@ pub struct PublicOffers {
|
|||||||
pub struct OfferTakenResponse {
|
pub struct OfferTakenResponse {
|
||||||
pub escrow_output_descriptor: String,
|
pub escrow_output_descriptor: String,
|
||||||
pub escrow_tx_fee_address: 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
// request to receive the escrow psbt to sign for the specified offer to take it
|
// request to receive the escrow psbt to sign for the specified offer to take it
|
||||||
|
@ -48,6 +48,9 @@ pub struct OfferTakenRequest {
|
|||||||
pub struct OfferTakenResponse {
|
pub struct OfferTakenResponse {
|
||||||
pub escrow_output_descriptor: String,
|
pub escrow_output_descriptor: String,
|
||||||
pub escrow_tx_fee_address: 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taker structures //
|
// Taker structures //
|
||||||
|
@ -14,16 +14,16 @@ use bdk::{
|
|||||||
bip32::ExtendedPrivKey,
|
bip32::ExtendedPrivKey,
|
||||||
key::{KeyPair, Secp256k1, XOnlyPublicKey},
|
key::{KeyPair, Secp256k1, XOnlyPublicKey},
|
||||||
psbt::PartiallySignedTransaction,
|
psbt::PartiallySignedTransaction,
|
||||||
Network,
|
Address, Network,
|
||||||
},
|
},
|
||||||
blockchain::ElectrumBlockchain,
|
blockchain::ElectrumBlockchain,
|
||||||
database::MemoryDatabase,
|
database::{Database, MemoryDatabase},
|
||||||
electrum_client::Client,
|
electrum_client::Client,
|
||||||
keys::DescriptorPublicKey,
|
keys::DescriptorPublicKey,
|
||||||
miniscript::Descriptor,
|
miniscript::{descriptor::Tr, Descriptor},
|
||||||
template::{Bip86, DescriptorTemplate},
|
template::{Bip86, DescriptorTemplate},
|
||||||
wallet::AddressInfo,
|
wallet::{AddressIndex, AddressInfo},
|
||||||
KeychainKind, SignOptions, SyncOptions, Wallet,
|
FeeRate, KeychainKind, SignOptions, SyncOptions, Wallet,
|
||||||
};
|
};
|
||||||
use bond::Bond;
|
use bond::Bond;
|
||||||
use musig2::MuSigData;
|
use musig2::MuSigData;
|
||||||
@ -92,12 +92,33 @@ impl TradingWallet {
|
|||||||
&self,
|
&self,
|
||||||
escrow_psbt_requirements: OfferTakenResponse,
|
escrow_psbt_requirements: OfferTakenResponse,
|
||||||
trader_config: &TraderSettings,
|
trader_config: &TraderSettings,
|
||||||
|
escrow_amount: u64,
|
||||||
|
coordinator_fee_amount: u64,
|
||||||
) -> Result<PartiallySignedTransaction> {
|
) -> Result<PartiallySignedTransaction> {
|
||||||
let fee_address = escrow_psbt_requirements.escrow_tx_fee_address;
|
let fee_output = Address::from_str(&escrow_psbt_requirements.escrow_tx_fee_address)?
|
||||||
let output_descriptor = escrow_psbt_requirements.escrow_output_descriptor;
|
.assume_checked()
|
||||||
|
.script_pubkey();
|
||||||
|
let escrow_output = {
|
||||||
|
let temp_wallet = Wallet::new(
|
||||||
|
&escrow_psbt_requirements.escrow_output_descriptor,
|
||||||
|
None,
|
||||||
|
Network::Regtest,
|
||||||
|
MemoryDatabase::new(),
|
||||||
|
)?;
|
||||||
|
temp_wallet.get_address(AddressIndex::New)?.script_pubkey()
|
||||||
|
};
|
||||||
self.wallet.sync(&self.backend, SyncOptions::default())?;
|
self.wallet.sync(&self.backend, SyncOptions::default())?;
|
||||||
Ok(())
|
let (mut psbt, details) = {
|
||||||
|
let mut builder = self.wallet.build_tx();
|
||||||
|
builder
|
||||||
|
.add_recipient(escrow_output, escrow_amount)
|
||||||
|
.add_recipient(fee_output, coordinator_fee_amount)
|
||||||
|
.fee_rate(FeeRate::from_sat_per_vb(10.0));
|
||||||
|
builder.finish()?
|
||||||
|
};
|
||||||
|
debug!("Signing escrow psbt.");
|
||||||
|
self.wallet.sign(&mut psbt, SignOptions::default())?;
|
||||||
|
Ok(psbt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate that the taker psbt references the correct inputs and amounts
|
// validate that the taker psbt references the correct inputs and amounts
|
||||||
|
Reference in New Issue
Block a user