fix: prevent dust change output

This commit is contained in:
c4605
2025-04-27 12:07:30 +02:00
parent f37bd42398
commit 5d5ce2ac85
2 changed files with 24 additions and 8 deletions

View File

@@ -723,12 +723,17 @@ async function constructBRC20Transaction(
}> { }> {
const txOptions = await prepareBRC20Transaction(sdkContext, info) const txOptions = await prepareBRC20Transaction(sdkContext, info)
const recipients =
txOptions.changeAmount > 0n
? txOptions.recipients.concat({
addressScriptPubKey: info.networkFeeChangeAddressScriptPubKey,
satsAmount: txOptions.changeAmount,
})
: txOptions.recipients
const tx = createTransaction( const tx = createTransaction(
txOptions.inputs, txOptions.inputs,
txOptions.recipients.concat({ recipients,
addressScriptPubKey: info.networkFeeChangeAddressScriptPubKey,
satsAmount: txOptions.changeAmount,
}),
txOptions.opReturnScripts ?? [], txOptions.opReturnScripts ?? [],
) )
@@ -812,6 +817,7 @@ export type PrepareBRC20TransactionInput = KnownRoute_FromBRC20 & {
* * Peg-in order data * * Peg-in order data
* * Bridge fee (optional) * * Bridge fee (optional)
* * Hard linkage (optional) * * Hard linkage (optional)
* * ...extra outputs
* * BTC change (optional) * * BTC change (optional)
* *
* (with bridge fee example tx) https://mempool.space/testnet/tx/e127a2d3c343675a1cde8ca8d10ae5621b40d309ce44b4f45bedc10499f8d596 * (with bridge fee example tx) https://mempool.space/testnet/tx/e127a2d3c343675a1cde8ca8d10ae5621b40d309ce44b4f45bedc10499f8d596

View File

@@ -669,12 +669,17 @@ async function constructRunesTransaction(
info, info,
) )
const recipients =
txOptions.changeAmount > 0n
? txOptions.recipients.concat({
addressScriptPubKey: info.networkFeeChangeAddressScriptPubKey,
satsAmount: txOptions.changeAmount,
})
: txOptions.recipients
const tx = createTransaction( const tx = createTransaction(
txOptions.inputs, txOptions.inputs,
txOptions.recipients.concat({ recipients,
addressScriptPubKey: info.networkFeeChangeAddressScriptPubKey,
satsAmount: txOptions.changeAmount,
}),
txOptions.opReturnScripts ?? [], txOptions.opReturnScripts ?? [],
) )
@@ -760,6 +765,7 @@ export type PrepareRunesTransactionInput = KnownRoute_FromRunes & {
* * Bridge fee (optional) * * Bridge fee (optional)
* * Hard linkage (optional) * * Hard linkage (optional)
* * Peg-in Rune tokens * * Peg-in Rune tokens
* * ...extra outputs
* * BTC change (optional) * * BTC change (optional)
* * Runestone * * Runestone
* *
@@ -943,6 +949,10 @@ export async function prepareRunesTransaction(
}), }),
), ),
}, },
...info.extraOutputs.map(o => ({
addressScriptPubKey: o.address.scriptPubKey,
satsAmount: o.satsAmount,
})),
], ],
changeAddressScriptPubKey: info.networkFeeChangeAddressScriptPubKey, changeAddressScriptPubKey: info.networkFeeChangeAddressScriptPubKey,
feeRate: info.networkFeeRate, feeRate: info.networkFeeRate,