Skip to content

Commit 36bca5b

Browse files
feat(abstract-utxo): implement explainTx for descriptor wallets
Issue: BTC-1450
1 parent e3e384f commit 36bca5b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import * as utxolib from '@bitgo/utxo-lib';
33
import { TransactionExplanation } from '../abstractUtxoCoin';
44

55
import * as fixedScript from './fixedScript';
6+
import * as descriptor from './descriptor';
67

7-
import { IWallet } from '@bitgo/sdk-core';
8-
import { isDescriptorWallet } from '../descriptor';
8+
import { isTriple, IWallet } from '@bitgo/sdk-core';
9+
import { getDescriptorMapFromWallet, isDescriptorWallet } from '../descriptor';
10+
import { toBip32Triple } from '../keychains';
11+
import { getPolicyForEnv } from '../descriptor/validatePolicy';
912

1013
/**
1114
* Decompose a raw transaction into useful information, such as the total amounts,
@@ -22,7 +25,20 @@ export function explainTx<TNumber extends number | bigint>(
2225
network: utxolib.Network
2326
): TransactionExplanation {
2427
if (params.wallet && isDescriptorWallet(params.wallet)) {
25-
throw new Error('Descriptor wallets are not supported');
28+
if (tx instanceof utxolib.bitgo.UtxoPsbt) {
29+
if (!params.pubs || !isTriple(params.pubs)) {
30+
throw new Error('pub triple is required for descriptor wallets');
31+
}
32+
const walletKeys = toBip32Triple(params.pubs);
33+
const descriptors = getDescriptorMapFromWallet(
34+
params.wallet,
35+
walletKeys,
36+
getPolicyForEnv(params.wallet.bitgo.env)
37+
);
38+
return descriptor.explainPsbt(tx, descriptors);
39+
}
40+
41+
throw new Error('legacy transactions are not supported for descriptor wallets');
2642
}
2743
if (tx instanceof utxolib.bitgo.UtxoPsbt) {
2844
return fixedScript.explainPsbt(tx, params, network);

0 commit comments

Comments
 (0)