Skip to content

Commit 52032dc

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 ac76231 commit 52032dc

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, verifyUserPublicKeyAsync } from '../../verifyKey';
12-
import { getPsbtTxInputs, getTxInputs } from '../fetchInputs';
1311

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

@@ -201,29 +199,9 @@ export async function verifyTransaction<TNumber extends bigint | number>(
201199
}
202200
}
203201

204-
const allOutputs = parsedTransaction.outputs;
205202
if (!txPrebuild.txHex) {
206203
throw new Error(`txPrebuild.txHex not set`);
207204
}
208-
const inputs = isPsbt
209-
? getPsbtTxInputs(txPrebuild.txHex, coin.name).map((v) => ({
210-
...v,
211-
value: toTNumber(v.value, coin.amountType),
212-
}))
213-
: await getTxInputs({ txPrebuild, bitgo, coin, disableNetworking, reqId });
214-
// coins (doge) that can exceed number limits (and thus will use bigint) will have the `valueString` field
215-
const inputAmount = inputs.reduce(
216-
(sum: bigint, i) => sum + BigInt(coin.amountType === 'bigint' ? i.valueString : i.value),
217-
BigInt(0)
218-
);
219-
const outputAmount = allOutputs.reduce((sum: bigint, o: Output) => sum + BigInt(o.amount), BigInt(0));
220-
const fee = inputAmount - outputAmount;
221-
222-
if (fee < 0) {
223-
throw new Error(
224-
`attempting to spend ${outputAmount} satoshis, which exceeds the input amount (${inputAmount} satoshis) by ${-fee}`
225-
);
226-
}
227205

228206
return true;
229207
}

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)