diff --git a/packages/persistent-merkle-tree/src/node.ts b/packages/persistent-merkle-tree/src/node.ts index 0f6294f1..54525875 100644 --- a/packages/persistent-merkle-tree/src/node.ts +++ b/packages/persistent-merkle-tree/src/node.ts @@ -81,10 +81,6 @@ export class BranchNode extends Node { return hashObjectToUint8Array(this.rootHashObject); } - isLeaf(): boolean { - return false; - } - get left(): Node { return this._left; } @@ -92,12 +88,32 @@ export class BranchNode extends Node { get right(): Node { return this._right; } + + isLeaf(): boolean { + return false; + } } /** * An immutable binary merkle tree node that has no children */ export class LeafNode extends Node { + get rootHashObject(): HashObject { + return this; + } + + get root(): Uint8Array { + return hashObjectToUint8Array(this); + } + + get left(): Node { + throw Error("LeafNode has no left node"); + } + + get right(): Node { + throw Error("LeafNode has no right node"); + } + static fromRoot(root: Uint8Array): LeafNode { return this.fromHashObject(uint8ArrayToHashObject(root)); } @@ -130,26 +146,10 @@ export class LeafNode extends Node { return LeafNode.fromHashObject(this); } - get rootHashObject(): HashObject { - return this; - } - - get root(): Uint8Array { - return hashObjectToUint8Array(this); - } - isLeaf(): boolean { return true; } - get left(): Node { - throw Error("LeafNode has no left node"); - } - - get right(): Node { - throw Error("LeafNode has no right node"); - } - writeToBytes(data: Uint8Array, start: number, size: number): void { // TODO: Optimize data.set(this.root.slice(0, size), start); diff --git a/packages/persistent-merkle-tree/src/tree.ts b/packages/persistent-merkle-tree/src/tree.ts index 2638b1f4..fbb1997b 100644 --- a/packages/persistent-merkle-tree/src/tree.ts +++ b/packages/persistent-merkle-tree/src/tree.ts @@ -30,10 +30,10 @@ export class Tree { } /** - * Create a `Tree` from a `Proof` object + * The root hash of the tree */ - static createFromProof(proof: Proof): Tree { - return new Tree(createNodeFromProof(proof)); + get root(): Uint8Array { + return this.rootNode.root; } /** @@ -68,10 +68,10 @@ export class Tree { } /** - * The root hash of the tree + * Create a `Tree` from a `Proof` object */ - get root(): Uint8Array { - return this.rootNode.root; + static createFromProof(proof: Proof): Tree { + return new Tree(createNodeFromProof(proof)); } /** diff --git a/packages/persistent-ts/src/MutableVector.ts b/packages/persistent-ts/src/MutableVector.ts index 54cc82f7..446cb370 100644 --- a/packages/persistent-ts/src/MutableVector.ts +++ b/packages/persistent-ts/src/MutableVector.ts @@ -5,10 +5,15 @@ import {PersistentVector, TransientVector} from "./Vector.js"; */ export class MutableVector implements Iterable { public vector: PersistentVector | TransientVector; + private constructor(vector: PersistentVector) { this.vector = vector; } + get length(): number { + return this.vector.length; + } + static empty(): MutableVector { return new MutableVector(PersistentVector.empty); } @@ -31,10 +36,6 @@ export class MutableVector implements Iterable { return this; } - get length(): number { - return this.vector.length; - } - get(index: number): T | undefined { return this.vector.get(index); } diff --git a/packages/ssz/src/branchNodeStruct.ts b/packages/ssz/src/branchNodeStruct.ts index 19f65851..6debce71 100644 --- a/packages/ssz/src/branchNodeStruct.ts +++ b/packages/ssz/src/branchNodeStruct.ts @@ -26,10 +26,6 @@ export class BranchNodeStruct extends Node { return hashObjectToUint8Array(this.rootHashObject); } - isLeaf(): boolean { - return false; - } - get left(): Node { return this.valueToNode(this.value).left; } @@ -37,4 +33,8 @@ export class BranchNodeStruct extends Node { get right(): Node { return this.valueToNode(this.value).right; } + + isLeaf(): boolean { + return false; + } } diff --git a/packages/ssz/src/viewDU/bitArray.ts b/packages/ssz/src/viewDU/bitArray.ts index ea85f57a..7bdacd38 100644 --- a/packages/ssz/src/viewDU/bitArray.ts +++ b/packages/ssz/src/viewDU/bitArray.ts @@ -22,16 +22,6 @@ export class BitArrayTreeViewDU extends TreeViewDU