Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 0 additions & 86 deletions modules/abstract-utxo/src/transaction/fetchInputs.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import { BitGoBase, TxIntentMismatchError, IBaseCoin } from '@bitgo/sdk-core';
import { hasPsbtMagic } from '@bitgo/wasm-utxo';

import { AbstractUtxoCoin, VerifyTransactionOptions } from '../../abstractUtxoCoin';
import { Output, ParsedTransaction } from '../types';
import { toTNumber } from '../../tnumber';
import { ParsedTransaction } from '../types';
import { stringToBufferTryFormats } from '../decode';
import { verifyCustomChangeKeySignatures, verifyKeySignature, verifyUserPublicKey } from '../../verifyKey';
import { getPsbtTxInputs, getTxInputs } from '../fetchInputs';

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

Expand Down Expand Up @@ -190,29 +188,9 @@ export async function verifyTransaction<TNumber extends bigint | number>(
}
}

const allOutputs = parsedTransaction.outputs;
if (!txPrebuild.txHex) {
throw new Error(`txPrebuild.txHex not set`);
}
const inputs = isPsbt
? getPsbtTxInputs(txPrebuild.txHex, coin.name).map((v) => ({
...v,
value: toTNumber(v.value, coin.amountType),
}))
: await getTxInputs({ txPrebuild, bitgo, coin, disableNetworking, reqId });
// coins (doge) that can exceed number limits (and thus will use bigint) will have the `valueString` field
const inputAmount = inputs.reduce(
(sum: bigint, i) => sum + BigInt(coin.amountType === 'bigint' ? i.valueString : i.value),
BigInt(0)
);
const outputAmount = allOutputs.reduce((sum: bigint, o: Output) => sum + BigInt(o.amount), BigInt(0));
const fee = inputAmount - outputAmount;

if (fee < 0) {
throw new Error(
`attempting to spend ${outputAmount} satoshis, which exceeds the input amount (${inputAmount} satoshis) by ${-fee}`
);
}

return true;
}
1 change: 0 additions & 1 deletion modules/abstract-utxo/src/transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './recipient';
export { explainTx } from './explainTransaction';
export { parseTransaction } from './parseTransaction';
export { verifyTransaction } from './verifyTransaction';
export * from './fetchInputs';
export * as bip322 from './bip322';
export { decodePsbt } from './decode';
export * from './fixedScript';