From 30902d6e152581651806a86aa3d1b2f56a1a9830 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Mon, 3 Mar 2025 11:25:06 +0100 Subject: [PATCH] feat(utxo-staking): update CoreDAO output type to use utxo-core Output Standardize staking output creation to use utxo-core Output type. Add backward compatibility wrapper. Issue: BTC-1826 --- .../utxo-staking/src/coreDao/transaction.ts | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/modules/utxo-staking/src/coreDao/transaction.ts b/modules/utxo-staking/src/coreDao/transaction.ts index c4be7bba28..ad2d8f5618 100644 --- a/modules/utxo-staking/src/coreDao/transaction.ts +++ b/modules/utxo-staking/src/coreDao/transaction.ts @@ -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. @@ -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[] { if (stakingParams.descriptor.hasWildcard() && stakingParams.index === undefined) { throw new Error('Cannot create staking outputs with a wildcard descriptor and no derivation index'); } @@ -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 })); +}