Skip to content

Commit

Permalink
feat: add StableContainer (#373)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
wemeetagain and twoeths authored Oct 9, 2024
1 parent 32fb35a commit 78a0291
Show file tree
Hide file tree
Showing 16 changed files with 4,188 additions and 18 deletions.
Binary file added packages/ssz/package.tgz
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/ssz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export {OptionalType} from "./type/optional";
export {VectorBasicType} from "./type/vectorBasic";
export {VectorCompositeType} from "./type/vectorComposite";
export {ListUintNum64Type} from "./type/listUintNum64";
export {StableContainerType} from "./type/stableContainer";
export {ProfileType} from "./type/profile";

// Base types
export {ArrayType} from "./type/array";
Expand Down
13 changes: 13 additions & 0 deletions packages/ssz/src/type/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {CompositeType, isCompositeType} from "./composite";
import {addLengthNode, getLengthFromRootNode} from "./arrayBasic";
/* eslint-disable @typescript-eslint/member-ordering */

export type NonOptionalType<T extends Type<unknown>> = T extends OptionalType<infer U> ? U : T;
export type NonOptionalFields<Fields extends Record<string, Type<unknown>>> = {
[K in keyof Fields]: NonOptionalType<Fields[K]>;
};

export type OptionalOpts = {
typeName?: string;
};
Expand Down Expand Up @@ -258,3 +263,11 @@ export class OptionalType<ElementType extends Type<unknown>> extends CompositeTy
return this.elementType.equals(a, b);
}
}

export function isOptionalType(type: Type<unknown>): type is OptionalType<Type<unknown>> {
return type instanceof OptionalType;
}

export function toNonOptionalType<T extends Type<unknown>>(type: T): NonOptionalType<T> {
return (isOptionalType(type) ? type.elementType : type) as NonOptionalType<T>;
}
Loading

0 comments on commit 78a0291

Please sign in to comment.