Skip to content

Commit 78a0291

Browse files
wemeetagaintwoeths
andauthored
feat: add StableContainer (#373)
* feat: add StableContainer * fix: fix stablecontainer with variable fields * feat: add SimpleVariantType * chore: add `yarn pack` tarball for testing * chore: rename variant to profile * chore: refresh `yarn pack` tarball * chore: fix lint * fix: Shape3 StableContainerType unit tests * fix: compilation error due to zerohash * chore: extract BasicContainerTreeViewDU from ContainerTreeViewDU * fix: support StableContainerTreeViewDU.batchHashTreeRoot() * fix: more StableContainer tests * fix: more tests for Profile and fix bugs * chore: StableContainer vs Profile merkleization test * fix: StableContainer to pad false bits up to length N (BitVector[N]) * fix: StableContainer BitVector[N] for view + value * chore: refactor Optional utils to common place * feat: Profile to support OptionalType * chore: StableContainer BitVector[N] test * chore: cachePermanentRootStruct for Profile and naming refactor --------- Co-authored-by: Tuyen Nguyen <vutuyen2636@gmail.com>
1 parent 32fb35a commit 78a0291

16 files changed

+4188
-18
lines changed

packages/ssz/package.tgz

130 KB
Binary file not shown.

packages/ssz/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export {OptionalType} from "./type/optional";
1616
export {VectorBasicType} from "./type/vectorBasic";
1717
export {VectorCompositeType} from "./type/vectorComposite";
1818
export {ListUintNum64Type} from "./type/listUintNum64";
19+
export {StableContainerType} from "./type/stableContainer";
20+
export {ProfileType} from "./type/profile";
1921

2022
// Base types
2123
export {ArrayType} from "./type/array";

packages/ssz/src/type/optional.ts

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import {CompositeType, isCompositeType} from "./composite";
1515
import {addLengthNode, getLengthFromRootNode} from "./arrayBasic";
1616
/* eslint-disable @typescript-eslint/member-ordering */
1717

18+
export type NonOptionalType<T extends Type<unknown>> = T extends OptionalType<infer U> ? U : T;
19+
export type NonOptionalFields<Fields extends Record<string, Type<unknown>>> = {
20+
[K in keyof Fields]: NonOptionalType<Fields[K]>;
21+
};
22+
1823
export type OptionalOpts = {
1924
typeName?: string;
2025
};
@@ -258,3 +263,11 @@ export class OptionalType<ElementType extends Type<unknown>> extends CompositeTy
258263
return this.elementType.equals(a, b);
259264
}
260265
}
266+
267+
export function isOptionalType(type: Type<unknown>): type is OptionalType<Type<unknown>> {
268+
return type instanceof OptionalType;
269+
}
270+
271+
export function toNonOptionalType<T extends Type<unknown>>(type: T): NonOptionalType<T> {
272+
return (isOptionalType(type) ? type.elementType : type) as NonOptionalType<T>;
273+
}

0 commit comments

Comments
 (0)