Skip to content

Commit b088a74

Browse files
refactor(abstract-utxo): eliminate fetchInputs by reusing explainPsbtWasm inputAmount
The legacy getTxInputs branch is unreachable (decodeTransaction throws ErrorDeprecatedTxFormat for non-PSBT input), and getPsbtTxInputs's only remaining caller in verifyTransaction just sums input values to check fee >= 0. explainPsbtWasm already returns inputAmount, so reuse that and delete fetchInputs.ts entirely. Refs: T1-3279
1 parent f3ecc52 commit b088a74

3 files changed

Lines changed: 1 addition & 110 deletions

File tree

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

Lines changed: 0 additions & 86 deletions
This file was deleted.

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import { BitGoBase, TxIntentMismatchError, IBaseCoin } from '@bitgo/sdk-core';
55
import { hasPsbtMagic } from '@bitgo/wasm-utxo';
66

77
import { AbstractUtxoCoin, VerifyTransactionOptions } from '../../abstractUtxoCoin';
8-
import { Output, ParsedTransaction } from '../types';
9-
import { toTNumber } from '../../tnumber';
8+
import { ParsedTransaction } from '../types';
109
import { stringToBufferTryFormats } from '../decode';
1110
import { verifyCustomChangeKeySignatures, verifyKeySignature, verifyUserPublicKey } from '../../verifyKey';
12-
import { getPsbtTxInputs, getTxInputs } from '../fetchInputs';
1311

1412
const debug = buildDebug('bitgo:abstract-utxo:verifyTransaction');
1513

@@ -190,29 +188,9 @@ export async function verifyTransaction<TNumber extends bigint | number>(
190188
}
191189
}
192190

193-
const allOutputs = parsedTransaction.outputs;
194191
if (!txPrebuild.txHex) {
195192
throw new Error(`txPrebuild.txHex not set`);
196193
}
197-
const inputs = isPsbt
198-
? getPsbtTxInputs(txPrebuild.txHex, coin.name).map((v) => ({
199-
...v,
200-
value: toTNumber(v.value, coin.amountType),
201-
}))
202-
: await getTxInputs({ txPrebuild, bitgo, coin, disableNetworking, reqId });
203-
// coins (doge) that can exceed number limits (and thus will use bigint) will have the `valueString` field
204-
const inputAmount = inputs.reduce(
205-
(sum: bigint, i) => sum + BigInt(coin.amountType === 'bigint' ? i.valueString : i.value),
206-
BigInt(0)
207-
);
208-
const outputAmount = allOutputs.reduce((sum: bigint, o: Output) => sum + BigInt(o.amount), BigInt(0));
209-
const fee = inputAmount - outputAmount;
210-
211-
if (fee < 0) {
212-
throw new Error(
213-
`attempting to spend ${outputAmount} satoshis, which exceeds the input amount (${inputAmount} satoshis) by ${-fee}`
214-
);
215-
}
216194

217195
return true;
218196
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from './recipient';
33
export { explainTx } from './explainTransaction';
44
export { parseTransaction } from './parseTransaction';
55
export { verifyTransaction } from './verifyTransaction';
6-
export * from './fetchInputs';
76
export * as bip322 from './bip322';
87
export { decodePsbt } from './decode';
98
export * from './fixedScript';

0 commit comments

Comments
 (0)