From e3c54ea8189ce5bbd7e8aeff5c7b6018fa97b5b1 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Thu, 17 Feb 2022 01:05:45 +1000 Subject: [PATCH] fix: bulk insert empty elements --- package.json | 2 +- src/merkleTree.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d0bc6b3..1183adc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fixed-merkle-tree", - "version": "0.6.0", + "version": "0.6.1", "description": "Fixed depth merkle tree implementation with sequential inserts", "repository": "https://github.com/tornadocash/fixed-merkle-tree.git", "main": "src/merkleTree.js", diff --git a/src/merkleTree.js b/src/merkleTree.js index 3e6bb3b..ee93697 100644 --- a/src/merkleTree.js +++ b/src/merkleTree.js @@ -78,6 +78,10 @@ class MerkleTree { * @param {Array} elements Elements to insert */ bulkInsert(elements) { + if (!elements.length) { + return + } + if (this._layers[0].length + elements.length > this.capacity) { throw new Error('Tree is full') }