Skip to content

Commit 18f9227

Browse files
chore(utxo-staking): pass in descriptor to create coredao outputs
TICKET: BTC-1582
1 parent baeb72c commit 18f9227

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

modules/utxo-staking/src/coreDao/transaction.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { createCoreDaoOpReturnOutputScript, OpReturnParams } from './opReturn';
21
import { Descriptor } from '@bitgo/wasm-miniscript';
32

3+
import { createCoreDaoOpReturnOutputScript, OpReturnParams } from './opReturn';
4+
45
/**
56
* Create the staking outputs for a CoreDAO staking transaction. This is the ordering
67
* in which to add into the transaction.
@@ -12,20 +13,19 @@ import { Descriptor } from '@bitgo/wasm-miniscript';
1213
export function createStakingOutputs(
1314
stakingParams: {
1415
amount: bigint;
15-
descriptor: string;
16+
descriptor: Descriptor;
1617
index?: number;
1718
},
1819
opReturnParams: OpReturnParams
1920
): { script: Buffer; amount: bigint }[] {
20-
const descriptor = Descriptor.fromString(
21-
stakingParams.descriptor,
22-
stakingParams.index === undefined ? 'definite' : 'derivable'
23-
);
21+
if (stakingParams.descriptor.hasWildcard() && stakingParams.index === undefined) {
22+
throw new Error('Cannot create staking outputs with a wildcard descriptor and no derivation index');
23+
}
2424

2525
const outputScript = Buffer.from(
2626
stakingParams.index === undefined
27-
? descriptor.scriptPubkey()
28-
: descriptor.atDerivationIndex(stakingParams.index).scriptPubkey()
27+
? stakingParams.descriptor.scriptPubkey()
28+
: stakingParams.descriptor.atDerivationIndex(stakingParams.index).scriptPubkey()
2929
);
3030
const opReturnScript = createCoreDaoOpReturnOutputScript(opReturnParams);
3131

0 commit comments

Comments
 (0)