Skip to content

Commit

Permalink
Merge pull request #143 from snapdao/fix-tx-fee-zero-issue
Browse files Browse the repository at this point in the history
Fix Transaction fee is zero issue
  • Loading branch information
leonbit2022 authored Dec 22, 2023
2 parents 7bad370 + 80f6e25 commit 9a7c7f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/example/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const composePsbt = (

const psbt = new Psbt({ network: networkConfig });

if (!inputs) throw new Error('Utxo selections error please retry');
if (!inputs) throw new Error('No suitable UTXOs available for constructing the transaction');

inputs.forEach((each) => {
const commonFields = {
Expand Down
6 changes: 3 additions & 3 deletions packages/example/src/lib/psbtValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ interface ValidateTxData {

export const validateTx = ({ psbt, utxoAmount, changeAddressPath }: ValidateTxData) => {
return isChangeAddressBelongsToCurrentAccount(psbt, changeAddressPath) &&
!isFeeTooHigh(psbt, utxoAmount) &&
isFeeValid(psbt, utxoAmount) &&
!hasDustOutput(psbt);
};

const isFeeTooHigh = (psbt: Psbt, utxoAmount: number) => {
const isFeeValid = (psbt: Psbt, utxoAmount: number) => {
const outputAmount = psbt.txOutputs.reduce((amount, output) => amount + output.value, 0);
const fee = utxoAmount - outputAmount;
return fee >= MAX_FEE;
return fee > 0 && fee < MAX_FEE;
};

const isChangeAddressBelongsToCurrentAccount = (psbt: Psbt, changeAddressPath: string) => {
Expand Down

0 comments on commit 9a7c7f2

Please sign in to comment.