mirror of
https://github.com/tornadocash/fixed-merkle-tree.git
synced 2024-12-27 15:17:56 +01:00
implementing getTreeSlices types
This commit is contained in:
parent
bc533ede2d
commit
d11c5c168a
@ -1,4 +1,13 @@
|
||||
import { Element, HashFunction, MerkleTreeOptions, ProofPath, SerializedTreeState, simpleHash, TreeEdge } from './'
|
||||
import {
|
||||
Element,
|
||||
HashFunction,
|
||||
MerkleTreeOptions,
|
||||
ProofPath,
|
||||
SerializedTreeState,
|
||||
simpleHash,
|
||||
TreeEdge,
|
||||
TreeSlice,
|
||||
} from './'
|
||||
|
||||
const defaultHash = (left: Element, right: Element): string => simpleHash([left, right])
|
||||
|
||||
@ -199,11 +208,11 @@ export default class MerkleTree {
|
||||
* 🪓
|
||||
* @param count
|
||||
*/
|
||||
getTreeSlices(count = 4): { edge: TreeEdge, elements: Element[] }[] {
|
||||
getTreeSlices(count = 4): TreeSlice[] {
|
||||
const length = this._layers[0].length
|
||||
let size = Math.ceil(length / count)
|
||||
if (size % 2) size++
|
||||
const slices = []
|
||||
const slices: TreeSlice[] = []
|
||||
for (let i = 0; i < length; i += size) {
|
||||
const edgeLeft = i
|
||||
const edgeRight = i + size
|
||||
|
@ -40,5 +40,7 @@ export type TreeEdge = {
|
||||
edgeIndex: number;
|
||||
edgeElementsCount: number;
|
||||
}
|
||||
|
||||
export type TreeSlice = { edge: TreeEdge, elements: Element[] }
|
||||
export type LeafWithIndex = { index: number, data: Element }
|
||||
|
||||
|
@ -198,6 +198,11 @@ describe('PartialMerkleTree', () => {
|
||||
const zeros = partialTree.zeros
|
||||
should().not.equal(zeros, partialTree.zeros)
|
||||
})
|
||||
|
||||
it('should return edge leaf', () => {
|
||||
const { partialTree } = getTestTrees(10, [1, 2, 3, 4, 5], 2)
|
||||
should().equal(partialTree.edgeElement, 3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#path', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user