Skip to content

Commit

Permalink
Merge pull request #5139 from BitGo/BTC-1582
Browse files Browse the repository at this point in the history
chore(utxo-staking): pass in descriptor to create coredao outputs
  • Loading branch information
davidkaplanbitgo authored Nov 15, 2024
2 parents 0c268ee + 18f9227 commit 4e3468f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions modules/utxo-staking/src/coreDao/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createCoreDaoOpReturnOutputScript, OpReturnParams } from './opReturn';
import { Descriptor } from '@bitgo/wasm-miniscript';

import { createCoreDaoOpReturnOutputScript, OpReturnParams } from './opReturn';

/**
* Create the staking outputs for a CoreDAO staking transaction. This is the ordering
* in which to add into the transaction.
Expand All @@ -12,20 +13,19 @@ import { Descriptor } from '@bitgo/wasm-miniscript';
export function createStakingOutputs(
stakingParams: {
amount: bigint;
descriptor: string;
descriptor: Descriptor;
index?: number;
},
opReturnParams: OpReturnParams
): { script: Buffer; amount: bigint }[] {
const descriptor = Descriptor.fromString(
stakingParams.descriptor,
stakingParams.index === undefined ? 'definite' : 'derivable'
);
if (stakingParams.descriptor.hasWildcard() && stakingParams.index === undefined) {
throw new Error('Cannot create staking outputs with a wildcard descriptor and no derivation index');
}

const outputScript = Buffer.from(
stakingParams.index === undefined
? descriptor.scriptPubkey()
: descriptor.atDerivationIndex(stakingParams.index).scriptPubkey()
? stakingParams.descriptor.scriptPubkey()
: stakingParams.descriptor.atDerivationIndex(stakingParams.index).scriptPubkey()
);
const opReturnScript = createCoreDaoOpReturnOutputScript(opReturnParams);

Expand Down

0 comments on commit 4e3468f

Please sign in to comment.