apply new psbt flow to trader, update trader api endpoint

This commit is contained in:
f321x
2024-08-02 12:59:55 +02:00
parent ab193da25a
commit e0c0bd3abc
4 changed files with 26 additions and 15 deletions

View File

@ -21,8 +21,8 @@ impl ActiveOffer {
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.to_string()),
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, bdk_psbt_inputs_hex_csv: psbt_inputs_hex_csv.clone(),
client_change_address: escrow_change_address, client_change_address: escrow_change_address.clone(),
}; };
let submission_result = bond_submission_request.send_maker(maker_config)?; let submission_result = bond_submission_request.send_maker(maker_config)?;

View File

@ -34,7 +34,7 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
let mut escrow_psbt = let mut escrow_psbt =
PartiallySignedTransaction::from_str(escrow_psbt_requirements.escrow_psbt_hex.as_str())?; PartiallySignedTransaction::from_str(escrow_psbt_requirements.escrow_psbt_hex.as_str())?;
let signed_escrow_psbt = wallet let signed_escrow_psbt = wallet
.validate_maker_psbt(&escrow_psbt)? .validate_escrow_psbt(&escrow_psbt)?
.sign_escrow_psbt(&mut escrow_psbt)?; .sign_escrow_psbt(&mut escrow_psbt)?;
// submit signed escrow psbt back to coordinator // submit signed escrow psbt back to coordinator

View File

@ -22,23 +22,32 @@ impl ActiveOffer {
// now we submit the signed bond transaction to the coordinator and receive the escrow PSBT we have to sign // now we submit the signed bond transaction to the coordinator and receive the escrow PSBT we have to sign
// in exchange // in exchange
let bond_submission_request = BondSubmissionRequest::prepare_bond_request( let (bdk_psbt_inputs_hex_csv, client_change_address) =
&bond, trading_wallet.get_escrow_psbt_inputs(bond_requirements.locking_amount_sat as i64)?;
&payout_address,
&mut musig_data, let bond_submission_request = BondSubmissionRequest {
taker_config, robohash_hex: taker_config.robosats_robohash_hex.clone(),
&trading_wallet.taproot_pubkey, signed_bond_hex: bond.to_string(),
)?; 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(),
musig_pubkey_hex: musig_data.public_key.to_string(),
bdk_psbt_inputs_hex_csv: bdk_psbt_inputs_hex_csv.clone(),
client_change_address: client_change_address.clone(),
};
let escrow_contract_requirements = let escrow_contract_requirements =
OfferPsbtRequest::taker_request(offer, bond_submission_request, taker_config)?; OfferPsbtRequest::taker_request(offer, bond_submission_request, taker_config)?;
let mut escrow_psbt =
PartiallySignedTransaction::from_str(&escrow_contract_requirements.escrow_psbt_hex)?;
// now we have to verify, sign and submit the escrow psbt again // now we have to verify, sign and submit the escrow psbt again
let escrow_contract_psbt = trading_wallet
trading_wallet.get_escrow_psbt(escrow_contract_requirements, taker_config)?; .validate_escrow_psbt(&escrow_psbt)?
.sign_escrow_psbt(&mut escrow_psbt)?;
// submit signed escrow psbt back to coordinator // submit signed escrow psbt back to coordinator
PsbtSubmissionRequest::submit_escrow_psbt( PsbtSubmissionRequest::submit_escrow_psbt(
&escrow_contract_psbt, &escrow_psbt,
offer.offer_id_hex.clone(), offer.offer_id_hex.clone(),
taker_config, taker_config,
)?; )?;
@ -48,7 +57,9 @@ impl ActiveOffer {
used_musig_config: musig_data, used_musig_config: musig_data,
used_bond: bond, used_bond: bond,
expected_payout_address: payout_address, expected_payout_address: payout_address,
escrow_psbt: Some(escrow_contract_psbt), escrow_psbt: Some(escrow_psbt),
psbt_inputs_hex_csv: bdk_psbt_inputs_hex_csv,
escrow_change_address: client_change_address,
}) })
} }
} }

View File

@ -186,7 +186,7 @@ impl TradingWallet {
} }
// validate amounts, escrow output // validate amounts, escrow output
pub fn validate_maker_psbt(&self, psbt: &PartiallySignedTransaction) -> Result<&Self> { pub fn validate_escrow_psbt(&self, psbt: &PartiallySignedTransaction) -> Result<&Self> {
warn!("IMPLEMENT MAKER PSBT VALIDATION for production use!"); warn!("IMPLEMENT MAKER PSBT VALIDATION for production use!");
// validate: change output address, amounts, fee // validate: change output address, amounts, fee
// tbd once the trade psbt is implemented on coordinator side // tbd once the trade psbt is implemented on coordinator side