Skip to content

Commit

Permalink
chore: use addLengthNode() api
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Sep 12, 2024
1 parent db0e5b6 commit 6efe578
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/ssz/src/type/partialListComposite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {PartialListCompositeTreeViewDU} from "../viewDU/partialListComposite";
import {Snapshot} from "../util/types";
import {byteArrayEquals} from "../util/byteArray";
import {zeroSnapshot} from "../util/snapshot";
import {addLengthNode} from "./arrayBasic";

/**
* Similar to ListCompositeType, this is mainly used to create a PartialListCompositeTreeViewDU from a snapshot.
Expand Down Expand Up @@ -47,8 +48,7 @@ export class PartialListCompositeType<
*/
toPartialViewDU(snapshot: Snapshot): PartialListCompositeTreeViewDU<ElementType> {
const chunksNode = fromSnapshot(snapshot, this.chunkDepth);
// old root node could be whatever, so leave zeroNode(0) here
const rootNode = this.tree_setChunksNode(zeroNode(0), chunksNode, snapshot.count);
const rootNode = addLengthNode(chunksNode, snapshot.count);

if (!byteArrayEquals(rootNode.root, snapshot.root)) {
throw new Error(`Snapshot root is incorrect, expected ${snapshot.root}, got ${rootNode.root}`);
Expand All @@ -61,8 +61,7 @@ export class PartialListCompositeType<
* Creates a PartialListCompositeTreeViewDU from a zero snapshot.
*/
defaultPartialViewDU(): PartialListCompositeTreeViewDU<ElementType> {
// old root node could be whatever, so leave zeroNode(0) here
const rootNode = this.tree_setChunksNode(zeroNode(0), zeroNode(this.chunkDepth), 0);
const rootNode = addLengthNode(zeroNode(this.chunkDepth), 0);

return new PartialListCompositeTreeViewDU(this, rootNode, zeroSnapshot(this.chunkDepth));
}
Expand Down

0 comments on commit 6efe578

Please sign in to comment.