Skip to content

Commit 89fad6b

Browse files
OttoAllmendingerllm-git
andcommitted
feat(utxo-core): support custom input sequence in transaction creation
Allow specifying sequence number per transaction input rather than globally, while maintaining backward compatibility. Issue: BTC-1966 Co-authored-by: llm-git <[email protected]>
1 parent e95315f commit 89fad6b

File tree

4 files changed

+700
-12
lines changed

4 files changed

+700
-12
lines changed

modules/utxo-core/src/descriptor/psbt/createPsbt.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ export type PsbtParams = {
4848
sequence?: number;
4949
};
5050

51+
export type DerivedDescriptorTransactionInput = DerivedDescriptorWalletOutput & {
52+
sequence?: number;
53+
};
54+
5155
export function createPsbt(
5256
params: PsbtParams,
53-
inputs: DerivedDescriptorWalletOutput[],
57+
inputs: DerivedDescriptorTransactionInput[],
5458
outputs: WithOptDescriptor<Output>[]
5559
): utxolib.bitgo.UtxoPsbt {
5660
const psbt = utxolib.bitgo.UtxoPsbt.createPsbt({ network: params.network });
5761
psbt.setVersion(params.version ?? 2);
5862
psbt.setLocktime(params.locktime ?? 0);
59-
psbt.addInputs(inputs.map((i) => ({ ...i, sequence: params.sequence ?? MAX_BIP125_RBF_SEQUENCE })));
63+
psbt.addInputs(inputs.map((i) => ({ ...i, sequence: i.sequence ?? params.sequence ?? MAX_BIP125_RBF_SEQUENCE })));
6064
psbt.addOutputs(outputs);
6165
updateInputsWithDescriptors(
6266
psbt,

modules/utxo-core/src/testutil/descriptor/mock.utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { Descriptor } from '@bitgo/wasm-miniscript';
22
import * as utxolib from '@bitgo/utxo-lib';
33

4-
import { PsbtParams, createPsbt, createScriptPubKeyFromDescriptor } from '../../descriptor';
5-
import { DerivedDescriptorWalletOutput } from '../../descriptor/Output';
4+
import {
5+
PsbtParams,
6+
createPsbt,
7+
createScriptPubKeyFromDescriptor,
8+
DerivedDescriptorTransactionInput,
9+
} from '../../descriptor';
610

711
import { DescriptorTemplate, getDefaultXPubs, getDescriptor } from './descriptors';
812

@@ -12,6 +16,7 @@ type BaseMockDescriptorOutputParams = {
1216
id?: MockOutputIdParams;
1317
index?: number;
1418
value?: bigint;
19+
sequence?: number;
1520
};
1621

1722
function mockOutputId(id?: MockOutputIdParams): {
@@ -26,7 +31,7 @@ function mockOutputId(id?: MockOutputIdParams): {
2631
export function mockDerivedDescriptorWalletOutput(
2732
descriptor: Descriptor,
2833
outputParams: BaseMockDescriptorOutputParams = {}
29-
): DerivedDescriptorWalletOutput {
34+
): DerivedDescriptorTransactionInput {
3035
const { value = BigInt(1e6) } = outputParams;
3136
const { hash, vout } = mockOutputId(outputParams.id);
3237
return {
@@ -37,6 +42,7 @@ export function mockDerivedDescriptorWalletOutput(
3742
value,
3843
},
3944
descriptor,
45+
sequence: outputParams.sequence,
4046
};
4147
}
4248

0 commit comments

Comments
 (0)