This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* typos in comment * add isValidTransaction fn * refactor validateTxProofs * add serialized merkleblocks * add tests * bump version * update package lock * rename isValidTransaction to areValidTransactions * only allow tx array as param * using MerkleBlock object as input param * use correct MerkleBlocks and fix tests * move merkleBlock creation to before hook * improve jsdoc * move merkleBlock creation to beforeEach * jsdoc: instance name instead of object * refactor validateTxProofs * more precise jsdoc param definition * test with empty transactions array * jsdoc for validateTxProofs
- Loading branch information
Showing
6 changed files
with
139 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
const merkleproofs = { | ||
const DashUtil = require('@dashevo/dash-util'); | ||
|
||
validateTxProofs: (merkleBlock, transactions) => merkleBlock.validMerkleTree() | ||
&& transactions.filter(t => merkleBlock.hasTransaction(t)).length === transactions.length, | ||
const merkleproofs = { | ||
/** | ||
* validates an array of tx hashes or Transaction instances | ||
* against a merkleblock | ||
* @param {MerkleBlock} merkleBlock - a MerkleBlock instance | ||
* @param {Transaction[]|string[]} transactions | ||
* @return {boolean} | ||
*/ | ||
validateTxProofs: (merkleBlock, transactions) => { | ||
let txToFilter = transactions.slice(); | ||
if (typeof transactions[0] === 'string') { | ||
txToFilter = txToFilter.map(tx => DashUtil.toHash(tx).toString('hex')); | ||
} | ||
return merkleBlock.validMerkleTree | ||
&& txToFilter.filter(tx => merkleBlock.hasTransaction(tx)).length === transactions.length; | ||
}, | ||
}; | ||
|
||
module.exports = merkleproofs; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters