-
Notifications
You must be signed in to change notification settings - Fork 16
refactor: make XXXDecisionRoot fns return js.String
#342
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -371,37 +371,39 @@ pub fn proposerLookahead(self: *const BeaconStateView) !js.Uint32Array { | |
|
|
||
| // pub fn BeaconStateView_getShufflingAtEpoch | ||
|
|
||
| pub fn previousDecisionRoot(self: *const BeaconStateView) !js.Uint8Array { | ||
| fn rootToHexString(root: *const [32]u8) !js.String { | ||
| const env = js.env(); | ||
| var hex_buf: [66]u8 = undefined; | ||
| try @import("hex").rootIntoHex(&hex_buf, root); | ||
| return js_types.wrap(js.String, try env.createStringUtf8(&hex_buf)); | ||
| } | ||
|
|
||
| pub fn previousDecisionRoot(self: *const BeaconStateView) !js.String { | ||
| const cached_state = try self.requireState(); | ||
| const root = cached_state.previousDecisionRoot(); | ||
| return js_types.wrap(js.Uint8Array, try sszValueToNapiValue(env, ct.primitive.Root, &root)); | ||
| return rootToHexString(&root); | ||
| } | ||
|
|
||
| pub fn currentDecisionRoot(self: *const BeaconStateView) !js.Uint8Array { | ||
| const env = js.env(); | ||
| pub fn currentDecisionRoot(self: *const BeaconStateView) !js.String { | ||
| const cached_state = try self.requireState(); | ||
| const root = cached_state.currentDecisionRoot(); | ||
| return js_types.wrap(js.Uint8Array, try sszValueToNapiValue(env, ct.primitive.Root, &root)); | ||
| return rootToHexString(&root); | ||
| } | ||
|
|
||
|
Comment on lines
388
to
392
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is missing the required assertions per the repository style guide (lines 51-55). Each function should have at least two assertions to verify invariants and state. References
|
||
| /// Get the next decision root for the state. | ||
| pub fn nextDecisionRoot(self: *const BeaconStateView) !js.Uint8Array { | ||
| const env = js.env(); | ||
| pub fn nextDecisionRoot(self: *const BeaconStateView) !js.String { | ||
| const cached_state = try self.requireState(); | ||
| const root = cached_state.nextDecisionRoot(); | ||
| return js_types.wrap(js.Uint8Array, try sszValueToNapiValue(env, ct.primitive.Root, &root)); | ||
| return rootToHexString(&root); | ||
| } | ||
|
|
||
|
Comment on lines
395
to
399
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is missing the required assertions per the repository style guide (lines 51-55). References
|
||
| /// Get the shuffling decision root for a given epoch. | ||
| pub fn getShufflingDecisionRoot(self: *const BeaconStateView, epoch_arg: js.Number) !js.Uint8Array { | ||
| const env = js.env(); | ||
| pub fn getShufflingDecisionRoot(self: *const BeaconStateView, epoch_arg: js.Number) !js.String { | ||
| const cached_state = try self.requireState(); | ||
| const epoch_value: u64 = @intCast(try epoch_arg.toI64()); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. u32 autowidens to u64 when used as an arg into this is somewhat of a unrelated change to this PR but also a small change so i did a driveby |
||
| const root = st.calculateShufflingDecisionRoot(cached_state.state, epoch_value) catch { | ||
| return throwNullAs(js.Uint8Array, "STATE_ERROR", "Failed to calculate shuffling decision root"); | ||
| const root = st.calculateShufflingDecisionRoot(cached_state.state, try epoch_arg.toU32()) catch { | ||
| return throwNullAs(js.String, "STATE_ERROR", "Failed to calculate shuffling decision root"); | ||
| }; | ||
| return js_types.wrap(js.Uint8Array, try sszValueToNapiValue(env, ct.primitive.Root, &root)); | ||
| return rootToHexString(&root); | ||
| } | ||
|
|
||
| pub fn previousProposers(self: *const BeaconStateView) !?js.Array { | ||
|
Comment on lines
402
to
409
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of References
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,6 +298,7 @@ | |
| .imports = .{ | ||
| .bls, | ||
| .bls_options, | ||
| .hex, | ||
| .persistent_merkle_tree, | ||
| .ssz, | ||
| .consensus_types, | ||
|
|
||
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.
The original function signature at line 374 was not removed, resulting in a dangling signature followed by a new function definition. This will cause a compilation error. Additionally, the repository style guide (lines 51-55) requires a minimum of two assertions per function to enforce invariants and detect programmer errors. I have included suggested assertions for the helper and the function body below.
References
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.
outdated; fixed in new push