Skip to content

Commit

Permalink
Merge pull request #5672 from BitGo/BTC-1826.use-core-output-in-utxo-…
Browse files Browse the repository at this point in the history
…staking

feat(utxo-staking): standardize CoreDAO output type
  • Loading branch information
OttoAllmendinger authored Mar 3, 2025
2 parents 08eda5f + 30902d6 commit 47c5eec
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions modules/utxo-staking/src/coreDao/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Output } from '@bitgo/utxo-core';
import { Descriptor } from '@bitgo/wasm-miniscript';

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

type StakingParams = {
amount: bigint;
descriptor: Descriptor;
index?: number;
};

/**
* Create the staking outputs for a CoreDAO staking transaction. This is the ordering
* in which to add into the transaction.
Expand All @@ -10,14 +17,10 @@ import { createCoreDaoOpReturnOutputScript, OpReturnParams } from './opReturn';
* If stakingParams.index is provided, then this is assumed to be a `derivable` descriptor.
* @param opReturnParams to create the OP_RETURN output
*/
export function createStakingOutputs(
stakingParams: {
amount: bigint;
descriptor: Descriptor;
index?: number;
},
export function createStakingOutputsCore(
stakingParams: StakingParams,
opReturnParams: OpReturnParams
): { script: Buffer; amount: bigint }[] {
): Output<bigint>[] {
if (stakingParams.descriptor.hasWildcard() && stakingParams.index === undefined) {
throw new Error('Cannot create staking outputs with a wildcard descriptor and no derivation index');
}
Expand All @@ -30,7 +33,20 @@ export function createStakingOutputs(
const opReturnScript = createCoreDaoOpReturnOutputScript(opReturnParams);

return [
{ script: outputScript, amount: stakingParams.amount },
{ script: opReturnScript, amount: BigInt(0) },
{ script: outputScript, value: stakingParams.amount },
{ script: opReturnScript, value: BigInt(0) },
];
}

type LegacyOutput = {
script: Buffer;
amount: bigint;
};

/**
* @see createStakingOutputsCore
* @deprecated - use createStakingOutputsCore instead
*/
export function createStakingOutputs(stakingParams: StakingParams, opReturnParams: OpReturnParams): LegacyOutput[] {
return createStakingOutputsCore(stakingParams, opReturnParams).map(({ value, ...o }) => ({ ...o, amount: value }));
}

0 comments on commit 47c5eec

Please sign in to comment.