-
Notifications
You must be signed in to change notification settings - Fork 12
[wip] feat(bindings): align BeaconStateView with IBeaconStateView
#347
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
Draft
spiral-ladder
wants to merge
22
commits into
main
Choose a base branch
from
bing/native-stf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9038c98
refactor: make XXXDecisionRoot fns return `js.String`
spiral-ladder a7c8844
update root related tests
spiral-ladder af2072e
fmt
spiral-ladder 0b5c2a6
unabbreviate
spiral-ladder 1bcb36f
refactor: make XXXDecisionRoot fns return `js.String`
spiral-ladder aa0369f
fix: param order in BeaconBlockBody
spiral-ladder ef383d9
refactor(bindings): return js.Number from getBalance
spiral-ladder 7dc7a69
feat: align BeaconStateView to IBeaconStateView
spiral-ladder fd1c0a9
align doc comment for isExecutionEnabled
spiral-ladder 58656ce
revert(bindings): pass SSZ bytes for voluntary exit validation
spiral-ladder 0fe22ee
Fix getSingleProof param from any -> bigint
spiral-ladder aec1443
Merge branch 'main' into bing/native-stf
spiral-ladder 45c2b20
revert slot value u32
spiral-ladder 67084e3
revert: transitionOpts changes
spiral-ladder 43b2244
fix doc comment for isExecutionEnabled
spiral-ladder 0fe7152
doc: doc comment toValue stub
spiral-ladder b8e18e4
doc: doc comment CompactMultiProof type
spiral-ladder e2007c5
refactor: put `parseOptions` into `transition_opts.zig`
spiral-ladder 37ca3b8
feat: naive loadOtherState
spiral-ladder 342c1dc
fix rest of toU32 to toI64
spiral-ladder 4909369
comments
spiral-ladder 284e2bc
feat: bindings to `getExpectedWithdrawals` and native tweaks
spiral-ladder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| //! Shared parser for `TransitionOpts` from a JS options object. | ||
| //! | ||
| //! This file is intentionally not registered with `root.zig` as a module export — | ||
| //! its `pub fn` should be visible to other napi files but never auto-exposed to JS. | ||
| //! (zapi tries to export every pub fn in modules listed in `root.zig`, which would | ||
| //! fail here because `TransitionOpts` isn't a JS-convertible return type.) | ||
|
|
||
| const std = @import("std"); | ||
| const js = @import("zapi:zapi").js; | ||
| const st = @import("state_transition"); | ||
|
|
||
| /// Parse a JS options object into Zig's `TransitionOpts`. | ||
| /// | ||
| /// Recognized fields: | ||
| /// - `verifyStateRoot`, `verifyProposer`, `verifySignatures`: bool | ||
| /// - `dontTransferCache`: bool (negated to set `transfer_cache`) | ||
| /// - `executionPayloadStatus`: "valid" | "invalid" | "preMerge" | ||
| /// - `dataAvailabilityStatus`: "Available" | "PreData" | "OutOfRange" | ||
| /// | ||
| /// Throws `error.InvalidExecutionPayloadStatus` / `error.InvalidDataAvailabilityStatus` | ||
| /// for unknown enum strings. | ||
| /// | ||
| /// TODO(bing): rename `dontTransferCache` → `transferCache` to drop the double negation. | ||
| pub fn parseOptions(options: ?js.Value) !st.TransitionOpts { | ||
| var transition_opts: st.TransitionOpts = .{}; | ||
|
|
||
| if (options) |value| { | ||
| const raw = value.toValue(); | ||
| if (try raw.typeof() == .object) { | ||
| if (try raw.hasNamedProperty("verifyStateRoot")) { | ||
| transition_opts.verify_state_root = try (try raw.getNamedProperty("verifyStateRoot")).getValueBool(); | ||
| } | ||
| if (try raw.hasNamedProperty("verifyProposer")) { | ||
| transition_opts.verify_proposer = try (try raw.getNamedProperty("verifyProposer")).getValueBool(); | ||
| } | ||
| if (try raw.hasNamedProperty("verifySignatures")) { | ||
| transition_opts.verify_signatures = try (try raw.getNamedProperty("verifySignatures")).getValueBool(); | ||
| } | ||
| if (try raw.hasNamedProperty("dontTransferCache")) { | ||
| transition_opts.transfer_cache = !(try (try raw.getNamedProperty("dontTransferCache")).getValueBool()); | ||
| } | ||
| if (try raw.hasNamedProperty("executionPayloadStatus")) { | ||
| var buf: [16]u8 = undefined; | ||
| const status_str = try (try raw.getNamedProperty("executionPayloadStatus")).getValueStringUtf8(&buf); | ||
| transition_opts.block_external_data.execution_payload_status = | ||
| if (std.mem.eql(u8, status_str, "valid")) | ||
| .valid | ||
| else if (std.mem.eql(u8, status_str, "invalid")) | ||
| .invalid | ||
| else if (std.mem.eql(u8, status_str, "preMerge")) | ||
| .pre_merge | ||
| else | ||
| return error.InvalidExecutionPayloadStatus; | ||
| } | ||
| if (try raw.hasNamedProperty("dataAvailabilityStatus")) { | ||
| var buf: [16]u8 = undefined; | ||
| const da_str = try (try raw.getNamedProperty("dataAvailabilityStatus")).getValueStringUtf8(&buf); | ||
| transition_opts.block_external_data.data_availability_status = | ||
| if (std.mem.eql(u8, da_str, "Available")) | ||
| .available | ||
| else if (std.mem.eql(u8, da_str, "PreData")) | ||
| .pre_data | ||
| else if (std.mem.eql(u8, da_str, "OutOfRange")) | ||
| .out_of_range | ||
| // TODO(bing): uncomment once gloas support is in | ||
| // else if (std.mem.eql(u8, da_str, "NotRequired")) .not_required; | ||
| else | ||
| return error.InvalidDataAvailabilityStatus; | ||
| } | ||
| } | ||
| } | ||
| return transition_opts; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Reverting these fields to
js.BigIntto avoid precision loss foru64Gwei values, consistent with the feedback inBeaconStateView.zig.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.
We use
numberinIBeaconStateViewinstead of big ints