From e611791f817fe67ff2f62b38bb82cbdfc7af5224 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Fri, 13 Dec 2024 16:30:01 +0100 Subject: [PATCH] refactor(abstract-utxo): make BaseParsedTransaction generic over TOutput The regular `ParsedTransaction` type was a bit silly Issue: BTC-1450 --- modules/abstract-utxo/src/abstractUtxoCoin.ts | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/modules/abstract-utxo/src/abstractUtxoCoin.ts b/modules/abstract-utxo/src/abstractUtxoCoin.ts index 8b990b8f3e..c68e4f3cb5 100644 --- a/modules/abstract-utxo/src/abstractUtxoCoin.ts +++ b/modules/abstract-utxo/src/abstractUtxoCoin.ts @@ -125,21 +125,21 @@ export interface VerifyAddressOptions ex coinSpecific?: TCoinSpecific; } -export interface BaseOutput { +export interface BaseOutput { address: string; - amount: string | number; + amount: TAmount; // Even though this external flag is redundant with the chain property, it is necessary for backwards compatibility // with legacy transaction format. external?: boolean; } -export interface FixedScriptWalletOutput extends BaseOutput { +export interface FixedScriptWalletOutput extends BaseOutput { needsCustomChangeKeySignatureVerification?: boolean; chain: number; index: number; } -export type Output = BaseOutput | FixedScriptWalletOutput; +export type Output = BaseOutput | FixedScriptWalletOutput; export function isWalletOutput(output: Output): output is FixedScriptWalletOutput { return ( @@ -223,23 +223,36 @@ export interface ParseTransactionOptions = { +export type BaseParsedTransaction = { keychains: UtxoNamedKeychains; keySignatures: { backupPub?: string; bitgoPub?: string; }; - outputs: Output[]; - missingOutputs: Output[]; - explicitExternalOutputs: Output[]; - implicitExternalOutputs: Output[]; - changeOutputs: Output[]; + /** all transaction outputs */ + outputs: TOutput[]; + /** transaction outputs that were specified as recipients but are missing from the transaction */ + missingOutputs: TOutput[]; + /** transaction outputs that were specified as recipients and are present in the transaction */ + explicitExternalOutputs: TOutput[]; + /** transaction outputs that were not specified as recipients but are present in the transaction */ + implicitExternalOutputs: TOutput[]; + /** transaction outputs that are change outputs */ + changeOutputs: TOutput[]; + /** sum of all explicit external outputs */ explicitExternalSpendAmount: TNumber; + /** sum of all implicit external outputs */ implicitExternalSpendAmount: TNumber; needsCustomChangeKeySignatureVerification: boolean; customChange?: CustomChangeOptions; }; +/** + * This type is a bit silly because it allows the type for the aggregate amounts to be different from the type of + * individual amounts. + */ +export type ParsedTransaction = BaseParsedTransaction; + export interface GenerateAddressOptions { addressType?: ScriptType2Of3; threshold?: number;