Skip to content

Commit

Permalink
Add todo to fix number of signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa committed Jan 23, 2023
1 parent d0e4182 commit 3de4199
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const useTransactionFee = ({ isValid, senderAddress, transaction }) => {
[transaction, schema, auth, isValid, isSchemaLoading]
);

// @todo Assert the returned value when all fee components are defined
return {
isLoading: isSchemaLoading || /* istanbul ignore next */ isLoading,
isFetched: isSchemaFetched && /* istanbul ignore next */ isFetched,
Expand Down
28 changes: 8 additions & 20 deletions src/modules/transaction/hooks/useTransactionFee/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { transactions } from '@liskhq/lisk-client';
import { joinModuleAndCommand } from '@transaction/utils/moduleCommand';
import { DEFAULT_SIGNATURE_BYTE_SIZE } from '@transaction/configuration/transactions';

export const ZERO_FEE = BigInt(0);

Expand All @@ -26,28 +25,17 @@ export const computeTransactionMinFee = (
) => {
if (!isTxValid || !paramsSchema || !auth || !priorities?.length) return ZERO_FEE;

const allocateEmptySignaturesWithEmptyBuffer = (signatureCount) =>
new Array(signatureCount).fill(Buffer.alloc(DEFAULT_SIGNATURE_BYTE_SIZE));

const numberOfSignatures = auth.numberOfSignatures || 1;

const numberOfEmptySignatures = 0;
// @todo define the numberOfEmptySignatures based on the auth and number
// of existing signatures in the transaction

const options = {
numberOfSignatures: auth.numberOfSignatures || 1,
numberOfEmptySignatures: 0,
};
const minFee = transactions.computeMinFee(
{
...transaction,
params: {
...transaction.params,
...(!transaction.params.signatures?.length && {
signatures: allocateEmptySignaturesWithEmptyBuffer(numberOfSignatures),
}),
},
},
transaction,
paramsSchema,
{
numberOfSignatures,
numberOfEmptySignatures,
}
options,
);

return minFee;
Expand Down

0 comments on commit 3de4199

Please sign in to comment.