Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
fix dcr fees (LedgerHQ#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzheng-ledger authored and aimxhaisse committed Mar 5, 2022
1 parent 75c1a36 commit 7499f0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/families/bitcoin/getAccountNetworkInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ export async function getAccountNetworkInfo(
if (feesPerByte.length !== 3) {
throw new Error("cardinality of feesPerByte should be exactly 3");
}
// Fix fees if suggested fee is too low, this is only for viacoin because the viacoin fees backend endpoint is broken
// Fix fees if suggested fee is too low, this is only for viacoin/decred because the fees backend endpoint is broken
if (
account.currency.id === "viacoin" &&
(account.currency.id === "viacoin" || account.currency.id === "decred") &&
feesPerByte[2].toNumber() < Math.ceil(relayFee * 100000)
) {
feesPerByte[2] = new BigNumber(Math.ceil(relayFee * 100000)).plus(1);
feesPerByte[1] = feesPerByte[2].plus(1);
feesPerByte[0] = feesPerByte[1].plus(1);
if (feesPerByte[1].plus(1).gt(feesPerByte[0])) {
feesPerByte[0] = feesPerByte[1].plus(1);
}
}
const feeItems = {
items: feesPerByte.map((feePerByte, i) => ({
Expand Down
5 changes: 4 additions & 1 deletion src/families/bitcoin/wallet-btc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ export function maxTxSize(
// Input: 32 PrevTxHash + 4 Index + 1 scriptSigLength + 4 sequence
let inputsWeight = byteSize(inputCount) * baseByte; // Number of inputs
inputsWeight += inputWeight(derivationMode) * inputCount;

// More bytes for decred, refer to https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/api_impl/BitcoinLikeTransactionApi.cpp#L162
if (currency.network.name === "Decred") {
inputsWeight += 64 * inputCount;
}
const txWeight = fixed + inputsWeight + outputsWeight;
return txWeight / 4;
}
Expand Down

0 comments on commit 7499f0a

Please sign in to comment.