Skip to content

Commit

Permalink
feat(utxo-staking): update CoreDAO output type to use utxo-core Output
Browse files Browse the repository at this point in the history
Standardize staking output creation to use utxo-core Output type. Add
backward compatibility wrapper.

Issue: BTC-1826
  • Loading branch information
OttoAllmendinger committed Mar 3, 2025
1 parent a7fb0ac commit 30902d6
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 30902d6

Please sign in to comment.