Skip to content

Commit 0912ec0

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): make TransactionExplanation more flexible
Adjust TransactionExplanation interface to allow for undefined locktime and parameterized fee type to support both string and undefined return types. This change helps with different use cases across the codebase. Issue: BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent 6229861 commit 0912ec0

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ export function isWalletOutput(output: Output): output is FixedScriptWalletOutpu
200200
);
201201
}
202202

203-
export interface TransactionExplanation extends BaseTransactionExplanation<string, string> {
204-
locktime: number;
203+
export interface TransactionExplanation<TFee = string> extends BaseTransactionExplanation<TFee, string> {
204+
locktime?: number;
205205
/** NOTE: this actually only captures external outputs */
206206
outputs: Output[];
207207
changeOutputs: Output[];
@@ -872,7 +872,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
872872
*/
873873
async explainTransaction<TNumber extends number | bigint = number>(
874874
params: ExplainTransactionOptions<TNumber>
875-
): Promise<TransactionExplanation> {
875+
): Promise<TransactionExplanation<string | undefined>> {
876876
return explainTx(this.decodeTransactionFromPrebuild(params), params, this.network);
877877
}
878878

modules/abstract-utxo/src/impl/doge/doge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class Doge extends AbstractUtxoCoin {
114114

115115
async explainTransaction<TNumber extends number | bigint = bigint>(
116116
params: ExplainTransactionOptions<TNumber> | (ExplainTransactionOptions<TNumber> & { txInfo: TransactionInfoJSON })
117-
): Promise<TransactionExplanation> {
117+
): Promise<TransactionExplanation<string | undefined>> {
118118
return super.explainTransaction({
119119
...params,
120120
txInfo: params.txInfo ? parseTransactionInfo(params.txInfo as TransactionInfoJSON) : undefined,

modules/abstract-utxo/src/offlineVault/TransactionExplanation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ export interface ExplanationOutput {
88
amount: string | number;
99
}
1010

11-
export interface TransactionExplanation {
11+
export interface TransactionExplanation<TFee> {
1212
outputs: ExplanationOutput[];
1313
changeOutputs: ExplanationOutput[];
1414
fee: {
1515
/* network fee */
16-
fee: string | number;
16+
fee: TFee;
1717
payGoFeeString: string | number | undefined;
1818
payGoFeeAddress: string | undefined;
1919
};
2020
}
2121

22-
export function getTransactionExplanation(coin: string, tx: unknown): TransactionExplanation {
22+
export function getTransactionExplanation(coin: string, tx: unknown): TransactionExplanation<string> {
2323
if (!OfflineVaultSignable.is(tx)) {
2424
throw new Error('not a signable transaction');
2525
}

modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function getHalfSignedPsbt(
4545
export function getTransactionExplanationFromPsbt(
4646
tx: DescriptorTransaction,
4747
network: utxolib.Network
48-
): TransactionExplanation {
48+
): TransactionExplanation<string> {
4949
const psbt = utxolib.bitgo.createPsbtDecode(tx.coinSpecific.txHex, network);
5050
const descriptorMap = getDescriptorsFromDescriptorTransaction(tx);
5151
const { outputs, changeOutputs, fee } = explainPsbt(psbt, descriptorMap);

modules/abstract-utxo/src/transaction/descriptor/explainPsbt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getInputSignatures(psbt: utxolib.bitgo.UtxoPsbt): number[] {
3434
export function explainPsbt(
3535
psbt: utxolib.bitgo.UtxoPsbt,
3636
descriptors: coreDescriptors.DescriptorMap
37-
): TransactionExplanation {
37+
): TransactionExplanation<string> {
3838
const parsedTransaction = coreDescriptors.parse(psbt, descriptors, psbt.network);
3939
const { inputs, outputs } = parsedTransaction;
4040
const externalOutputs = outputs.filter((o) => o.scriptId === undefined);

modules/abstract-utxo/src/transaction/explainTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function explainTx<TNumber extends number | bigint>(
2222
changeInfo?: fixedScript.ChangeAddressInfo[];
2323
},
2424
network: utxolib.Network
25-
): TransactionExplanation {
25+
): TransactionExplanation<string | undefined> {
2626
if (params.wallet && isDescriptorWallet(params.wallet)) {
2727
if (tx instanceof utxolib.bitgo.UtxoPsbt) {
2828
if (!params.pubs || !isTriple(params.pubs)) {

modules/abstract-utxo/src/transaction/fixedScript/explainTransaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export function explainPsbt(
345345
inputSignatures: inputSignaturesCount,
346346
signatures: inputSignaturesCount.reduce((prev, curr) => (curr > prev ? curr : prev), 0),
347347
messages,
348-
} as TransactionExplanation;
348+
};
349349
}
350350

351351
export function explainLegacyTx<TNumber extends number | bigint>(
@@ -356,12 +356,12 @@ export function explainLegacyTx<TNumber extends number | bigint>(
356356
changeInfo?: { address: string; chain: number; index: number }[];
357357
},
358358
network: utxolib.Network
359-
): TransactionExplanation {
359+
): TransactionExplanation<string | undefined> {
360360
const common = explainCommon(tx, params, network);
361361
const inputSignaturesCount = getTxInputSignaturesCount(tx, params, network);
362362
return {
363363
...common,
364364
inputSignatures: inputSignaturesCount,
365365
signatures: inputSignaturesCount.reduce((prev, curr) => (curr > prev ? curr : prev), 0),
366-
} as TransactionExplanation;
366+
};
367367
}

modules/abstract-utxo/src/transaction/fixedScript/parseTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function parseTransaction<TNumber extends bigint | number>(
5353
}
5454

5555
// obtain all outputs
56-
const explanation: TransactionExplanation = await coin.explainTransaction<TNumber>({
56+
const explanation: TransactionExplanation<string | undefined> = await coin.explainTransaction<TNumber>({
5757
txHex: txPrebuild.txHex,
5858
txInfo: txPrebuild.txInfo,
5959
pubs: keychainArray.map((k) => k.pub) as Triple<string>,

0 commit comments

Comments
 (0)