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

View File

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