Skip to content

Commit

Permalink
refactor(abstract-utxo): make BaseParsedTransaction generic over TOutput
Browse files Browse the repository at this point in the history
The regular `ParsedTransaction` type was a bit silly

Issue: BTC-1450
  • Loading branch information
OttoAllmendinger committed Dec 13, 2024
1 parent 345584c commit 6120fcd
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ export interface VerifyAddressOptions<TCoinSpecific extends UtxoCoinSpecific> ex
coinSpecific?: TCoinSpecific;
}

export interface BaseOutput {
export interface BaseOutput<TAmount = string | number> {
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<TAmount = string | number> extends BaseOutput<TAmount> {
needsCustomChangeKeySignatureVerification?: boolean;
chain: number;
index: number;
}

export type Output = BaseOutput | FixedScriptWalletOutput;
export type Output<TAmount = string | number> = BaseOutput<TAmount> | FixedScriptWalletOutput<TAmount>;

export function isWalletOutput(output: Output): output is FixedScriptWalletOutput {
return (
Expand Down Expand Up @@ -224,23 +224,36 @@ export interface ParseTransactionOptions<TNumber extends number | bigint = numbe
reqId?: IRequestTracer;
}

export type ParsedTransaction<TNumber extends number | bigint = number> = {
export type BaseParsedTransaction<TNumber extends number | bigint, TOutput> = {
keychains: NamedKeychains;
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<TNumber extends number | bigint = number> = BaseParsedTransaction<TNumber, Output>;

export interface GenerateAddressOptions {
addressType?: ScriptType2Of3;
threshold?: number;
Expand Down

0 comments on commit 6120fcd

Please sign in to comment.