-
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor codebase #82
Conversation
f9d9759
to
4e2cb4b
Compare
src/backings/tree.ts
Outdated
*/ | ||
hashTreeRoot(): Uint8Array; | ||
|
||
createProof(paths: Path[]): Proof; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be supper awesome if we could make path typesafe. But it would require some recursive keyof and wouldn't work with arrays right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does! This compiles
function gett<
T,
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3]
>(val: T, k1: K1, k2: K2, k3: K3, k4: K4) {}
type State = {
a: {
b: {
c: {
d: string;
};
}[];
};
};
gett({} as State, "a", "b", 1, "c");
* @param offset | ||
*/ | ||
validateBytes(data: Uint8Array, offset: number): void { | ||
bytes_validate(data: Uint8Array, offset: number): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why no camelcase?
I've used https://www.npmjs.com/package/madge to generate: Ugh, this is a bit annoying. abstract <-> proxy is easy to resolve. Just create ITreeValue interface in interface.ts with properties required by proxy. Circular references between proxy and implementations I'm not sure. It might work if abstract doesn't depend on proxy :/ |
Could we prioritize merging the PR and then finding a way to split tree in multiple files? Would be really nice to have this merged |
I'm going to fully integrate with lodestar and run spec tests before merging. |
- Move all struct and tree logic to the Type - Rename all underlying struct and tree logic with struct_* and tree_* - Simplify tree-backed proxy logic
07ca859
to
890e7bc
Compare
Integrated with Lodestar, passing all tests - unit, e2e, sim, spec, etc. |
Type
struct_*
andtree_*
getMaxSerializedLength
)struct_*
methods operate on structs, using type information + get/set to perform ssz operationstree_*
methods operate onTree
s, using type information to perform ssz operationstree_getProperty
andtree_setProperty
are high level methods that may either return a primitive or aTree
, depending on the property typeBasicArrayType
(which always gets/sets primitives),CompositeArrayType
(which always gets/sets trees), andContainerType
(which gets/sets primitives or trees depending on the property type)TreeValue
and its subclasses create a convenience wrapper around low levelType.tree_*
functions, are wrapped in a proxy for convenient get/setcreateTreeBacked(type: CompositeType<T>, tree: Tree): TreeBacked<T>
function to createTreeBacked
objectsBenefits/tradeoffs of this refactor:
this._type.structural.foo()
type.tree
previouslyreadOnlyMap
replaced withreadonlyValues
iteratorExample code: