Add a mandatory --change-address parameter to buy-xmr

Fixes #513.
This commit is contained in:
Thomas Eizinger 2021-07-06 19:17:17 +10:00
parent 683d565679
commit 5463bde4f8
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
12 changed files with 135 additions and 13 deletions

View file

@ -24,6 +24,7 @@ impl TxLock {
amount: Amount,
A: PublicKey,
B: PublicKey,
change: bitcoin::Address,
) -> Result<Self>
where
C: EstimateFeeRate,
@ -34,7 +35,9 @@ impl TxLock {
.address(wallet.get_network())
.expect("can derive address from descriptor");
let psbt = wallet.send_to_address(address, amount).await?;
let psbt = wallet
.send_to_address(address, amount, Some(change))
.await?;
Ok(Self {
inner: psbt,
@ -251,7 +254,11 @@ mod tests {
wallet: &Wallet<(), bdk::database::MemoryDatabase, StaticFeeRate>,
amount: Amount,
) -> PartiallySignedTransaction {
TxLock::new(&wallet, amount, A, B).await.unwrap().into()
let change = wallet.new_address().await.unwrap();
TxLock::new(&wallet, amount, A, B, change)
.await
.unwrap()
.into()
}
fn alice_and_bob() -> (PublicKey, PublicKey) {