Skip to content

Commit f56dda5

Browse files
refactor(abstract-utxo): make BaseParsedTransaction generic over TOutput
The regular `ParsedTransaction` type was a bit silly Issue: BTC-1450
1 parent f166895 commit f56dda5

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,21 @@ export interface VerifyAddressOptions<TCoinSpecific extends UtxoCoinSpecific> ex
125125
coinSpecific?: TCoinSpecific;
126126
}
127127

128-
export interface BaseOutput {
128+
export interface BaseOutput<TAmount = string | number> {
129129
address: string;
130-
amount: string | number;
130+
amount: TAmount;
131131
// Even though this external flag is redundant with the chain property, it is necessary for backwards compatibility
132132
// with legacy transaction format.
133133
external?: boolean;
134134
}
135135

136-
export interface FixedScriptWalletOutput extends BaseOutput {
136+
export interface FixedScriptWalletOutput<TAmount = string | number> extends BaseOutput<TAmount> {
137137
needsCustomChangeKeySignatureVerification?: boolean;
138138
chain: number;
139139
index: number;
140140
}
141141

142-
export type Output = BaseOutput | FixedScriptWalletOutput;
142+
export type Output<TAmount = string | number> = BaseOutput<TAmount> | FixedScriptWalletOutput<TAmount>;
143143

144144
export function isWalletOutput(output: Output): output is FixedScriptWalletOutput {
145145
return (
@@ -206,23 +206,36 @@ export interface ParseTransactionOptions<TNumber extends number | bigint = numbe
206206
reqId?: IRequestTracer;
207207
}
208208

209-
export type ParsedTransaction<TNumber extends number | bigint = number> = {
209+
export type BaseParsedTransaction<TNumber extends number | bigint, TOutput> = {
210210
keychains: UtxoNamedKeychains;
211211
keySignatures: {
212212
backupPub?: string;
213213
bitgoPub?: string;
214214
};
215-
outputs: Output[];
216-
missingOutputs: Output[];
217-
explicitExternalOutputs: Output[];
218-
implicitExternalOutputs: Output[];
219-
changeOutputs: Output[];
215+
/** all transaction outputs */
216+
outputs: TOutput[];
217+
/** transaction outputs that were specified as recipients but are missing from the transaction */
218+
missingOutputs: TOutput[];
219+
/** transaction outputs that were specified as recipients and are present in the transaction */
220+
explicitExternalOutputs: TOutput[];
221+
/** transaction outputs that were not specified as recipients but are present in the transaction */
222+
implicitExternalOutputs: TOutput[];
223+
/** transaction outputs that are change outputs */
224+
changeOutputs: TOutput[];
225+
/** sum of all explicit external outputs */
220226
explicitExternalSpendAmount: TNumber;
227+
/** sum of all implicit external outputs */
221228
implicitExternalSpendAmount: TNumber;
222229
needsCustomChangeKeySignatureVerification: boolean;
223230
customChange?: CustomChangeOptions;
224231
};
225232

233+
/**
234+
* This type is a bit silly because it allows the type for the aggregate amounts to be different from the type of
235+
* individual amounts.
236+
*/
237+
export type ParsedTransaction<TNumber extends number | bigint = number> = BaseParsedTransaction<TNumber, Output>;
238+
226239
export interface GenerateAddressOptions {
227240
addressType?: ScriptType2Of3;
228241
threshold?: number;

0 commit comments

Comments
 (0)