mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-11-22 09:47:15 +01:00
fix capacity calculation
This commit is contained in:
parent
823545596e
commit
acc7e53b01
@ -24,7 +24,7 @@ class MerkleTree {
|
|||||||
*/
|
*/
|
||||||
constructor(levels, elements = [], { hashFunction, zeroElement = DEFAULT_ZERO } = {}) {
|
constructor(levels, elements = [], { hashFunction, zeroElement = DEFAULT_ZERO } = {}) {
|
||||||
this.levels = levels
|
this.levels = levels
|
||||||
this.capacity = 1 << levels
|
this.capacity = 2 ** levels
|
||||||
this.zeroElement = zeroElement
|
this.zeroElement = zeroElement
|
||||||
this._hash = hashFunction || defaultHash
|
this._hash = hashFunction || defaultHash
|
||||||
if (elements.length > this.capacity) {
|
if (elements.length > this.capacity) {
|
||||||
@ -177,7 +177,7 @@ class MerkleTree {
|
|||||||
static deserialize(data, hashFunction) {
|
static deserialize(data, hashFunction) {
|
||||||
const instance = Object.assign(Object.create(this.prototype), data)
|
const instance = Object.assign(Object.create(this.prototype), data)
|
||||||
instance._hash = hashFunction || defaultHash
|
instance._hash = hashFunction || defaultHash
|
||||||
instance.capacity = 1 << instance.levels
|
instance.capacity = 2 ** instance.levels
|
||||||
instance.zeroElement = instance._zeros[0]
|
instance.zeroElement = instance._zeros[0]
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user