Skip to content

feat(sdk-coin-btc): add option to force fee from non-ordinal unspents #6405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/ts/btc/ordinals/move-individual-ordinal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ async function transferIndividualOrdinal() {

// Build the transaction to send the ordinal
// Note that you can configure the structure of the transaction by passing in additional parameters
const buildResult = await inscriptionBuilder.prepareTransfer(satPoint, recipient, feeRateSatKb, {});
const buildResult = await inscriptionBuilder.prepareTransfer(satPoint, recipient, feeRateSatKb, {
forceFeeFromOtherUnspent: true,
});

const sent = await inscriptionBuilder.signAndSendTransfer(walletPassphrase, buildResult);
console.log('sent ' + JSON.stringify(sent, null, 2));
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-btc/src/inscriptionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class InscriptionBuilder implements IInscriptionBuilder {
inscriptionConstraints = DefaultInscriptionConstraints,
changeAddressType = 'p2wsh',
txFormat = 'psbt',
forceFeeFromOtherUnspent = false,
}: {
signer?: utxolib.bitgo.KeyName;
cosigner?: utxolib.bitgo.KeyName;
Expand All @@ -152,6 +153,7 @@ export class InscriptionBuilder implements IInscriptionBuilder {
};
changeAddressType?: utxolib.bitgo.outputScripts.ScriptType2Of3;
txFormat?: 'psbt' | 'legacy';
forceFeeFromOtherUnspent?: boolean; // If true, will try to use unspents other than the inscription unspent to pay for the fee
}
): Promise<PrebuildTransactionResult> {
assert(isSatPoint(satPoint));
Expand All @@ -174,6 +176,9 @@ export class InscriptionBuilder implements IInscriptionBuilder {
};

for (const supplementaryUnspentsMinValue of SUPPLEMENTARY_UNSPENTS_MIN_VALUE_SATS) {
if (forceFeeFromOtherUnspent && supplementaryUnspentsMinValue === 0) {
continue; // Skip the attempt with 0
}
try {
return await this.prepareTransferWithExtraInputs(
satPoint,
Expand Down