Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(abstract-utxo): make BaseParsedTransaction generic over TOutput #5271

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,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 @@ -206,23 +206,42 @@ export interface ParseTransactionOptions<TNumber extends number | bigint = numbe
reqId?: IRequestTracer;
}

export type ParsedTransaction<TNumber extends number | bigint = number> = {
export type BaseParsedTransactionOutputs<TNumber extends number | bigint, TOutput> = {
/** 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<TNumber extends number | bigint, TOutput> = 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<TNumber extends number | bigint = number> = BaseParsedTransaction<TNumber, Output>;

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