diff --git a/modules/abstract-utxo/src/abstractUtxoCoin.ts b/modules/abstract-utxo/src/abstractUtxoCoin.ts index 6182ee05df..b5db01a20c 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,42 @@ export interface ParseTransactionOptions = { +export type BaseParsedTransactionOutputs = { + /** 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; +}; + +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; }; - outputs: Output[]; - missingOutputs: Output[]; - explicitExternalOutputs: Output[]; - implicitExternalOutputs: Output[]; - changeOutputs: Output[]; - explicitExternalSpendAmount: TNumber; - 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;