From f56dda5107a80da20abcab1df38d22fd5360b812 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Fri, 13 Dec 2024 16:30:01 +0100 Subject: [PATCH 1/2] 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 6182ee05df..2e4a31f270 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 ( @@ -206,23 +206,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; From c2216a0e64a5af5d724f6dd9e2710a1dc7f3c6b4 Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Mon, 16 Dec 2024 15:40:37 +0100 Subject: [PATCH 2/2] refactor(abstract-utxo): split off BaseParsedTransactionOutputs Issue: BTC-1450 --- modules/abstract-utxo/src/abstractUtxoCoin.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/abstract-utxo/src/abstractUtxoCoin.ts b/modules/abstract-utxo/src/abstractUtxoCoin.ts index 2e4a31f270..b5db01a20c 100644 --- a/modules/abstract-utxo/src/abstractUtxoCoin.ts +++ b/modules/abstract-utxo/src/abstractUtxoCoin.ts @@ -206,12 +206,7 @@ export interface ParseTransactionOptions = { - keychains: UtxoNamedKeychains; - keySignatures: { - backupPub?: string; - bitgoPub?: string; - }; +export type BaseParsedTransactionOutputs = { /** all transaction outputs */ outputs: TOutput[]; /** transaction outputs that were specified as recipients but are missing from the transaction */ @@ -226,6 +221,17 @@ export type BaseParsedTransaction = { explicitExternalSpendAmount: TNumber; /** sum of all implicit external outputs */ implicitExternalSpendAmount: TNumber; +}; + +export type BaseParsedTransaction = BaseParsedTransactionOutputs< + TNumber, + TOutput +> /** Some extra properties that have nothing to do with an individual transaction */ & { + keychains: UtxoNamedKeychains; + keySignatures: { + backupPub?: string; + bitgoPub?: string; + }; needsCustomChangeKeySignatureVerification: boolean; customChange?: CustomChangeOptions; };