Repository navigation
feat: implement saving ENR/s to file and loading ENR/s from file #1
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
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e4bacdc
feat:init enr load from file and save to file
GrapeBaBa 4a6393c
feat:update ci and readme
GrapeBaBa 403cfd7
fix: fix wrong module expose
GrapeBaBa 5f4eea0
fix:remove auto-generated comment and throw error
GrapeBaBa c7698ed
fix:remove auto generated comment in zon file
GrapeBaBa f7572a5
fix:elimate duplicate code
GrapeBaBa 72e8c5d
fix:update install zig in CI
GrapeBaBa 247fadd
fix:elimate duplicate code in test
GrapeBaBa 95b441c
fix:remove auto generated comment
GrapeBaBa ae60122
fix:reduce stack memory used
GrapeBaBa 1f8aad4
fix:fix duplicate and add more tests
GrapeBaBa 38540b3
feat:remove discv5 dep
GrapeBaBa de1e4b1
fix:replace setup-zig
GrapeBaBa 702fc22
feat: add helper function for SignableENR
GrapeBaBa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: Enr CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| ZIG_VERSION: 0.14.1 | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Cache Zig | ||
| id: cache-zig | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/zig | ||
| key: ${{ runner.os }}-zig-${{ env.ZIG_VERSION }} | ||
|
|
||
| - name: Install Zig | ||
| if: steps.cache-zig.outputs.cache-hit != 'true' | ||
| run: | | ||
| wget https://ziglang.org/download/${{ env.ZIG_VERSION }}/zig-x86_64-linux-${{ env.ZIG_VERSION }}.tar.xz | ||
| tar -xf zig-x86_64-linux-${{ env.ZIG_VERSION }}.tar.xz | ||
| mv zig-x86_64-linux-${{ env.ZIG_VERSION }} ~/zig | ||
|
|
||
| - name: Add Zig to PATH | ||
| run: echo "${HOME}/zig" >> $GITHUB_PATH | ||
|
|
||
| - name: Cache Zig build artifacts | ||
| uses: actions/cache@v4 # Updated to v4 | ||
| with: | ||
| path: | | ||
| zig-cache | ||
| ~/.cache/zig | ||
| key: ${{ runner.os }}-zig-build-${{ hashFiles('**/*.zig') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-zig-build- | ||
|
|
||
| - name: Formatting | ||
| run: zig fmt --check --color on . | ||
|
|
||
| - name: Unit testing | ||
| run: zig build test --summary all | ||
|
|
||
| - name: Building | ||
| run: zig build -Doptimize=ReleaseSafe | ||
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 |
|---|---|---|
| @@ -1,2 +1,49 @@ | ||
| # enr | ||
| About Ethereum Node Records (ENR) | ||
| Ethereum Node Records (ENR) utility in Zig. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Zig 0.14.1 | ||
|
|
||
| ## Building | ||
|
|
||
| To build the project, run the following command in the root directory of the project: | ||
|
|
||
| ```bash | ||
| zig build -Doptimize=ReleaseSafe | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| To run the tests, run the following command in the root directory of the project: | ||
|
|
||
| ```bash | ||
| zig build test --summary all | ||
| ``` | ||
|
|
||
| ## Docs | ||
|
|
||
| To generate documentation for the project, run the following command in the root directory of the project: | ||
|
|
||
| ```bash | ||
| zig build docs | ||
| ``` | ||
|
|
||
| # Usage | ||
|
|
||
| Update `build.zig.zon`: | ||
|
|
||
| ```sh | ||
| zig fetch --save git+https://github.com/blockblaz/enr | ||
| ``` | ||
|
|
||
| In your `build.zig`: | ||
|
|
||
| ```zig | ||
| const enr_dep = b.dependency("zig_enr", .{ | ||
| .target = target, | ||
| .optimize = optimize, | ||
| }); | ||
| const enr_module = enr_dep.module("zig-enr"); | ||
| root_module.addImport("zig-enr", enr_module); | ||
| ``` |
|
GrapeBaBa marked this conversation as resolved.
|
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 @@ | ||
| const std = @import("std"); | ||
|
|
||
| // Although this function looks imperative, note that its job is to | ||
| // declaratively construct a build graph that will be executed by an external | ||
| // runner. | ||
| pub fn build(b: *std.Build) void { | ||
|
GrapeBaBa marked this conversation as resolved.
Outdated
|
||
| // Standard target options allows the person running `zig build` to choose | ||
| // what target to build for. Here we do not override the defaults, which | ||
| // means any target is allowed, and the default is native. Other options | ||
| // for restricting supported target set are available. | ||
| const target = b.standardTargetOptions(.{}); | ||
|
|
||
| // Standard optimization options allow the person running `zig build` to select | ||
| // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not | ||
| // set a preferred release mode, allowing the user to decide how to optimize. | ||
| const optimize = b.standardOptimizeOption(.{}); | ||
|
|
||
| const discv5 = b.dependency("discv5", .{}); | ||
|
|
||
| const enr_mod = discv5.module("enr"); | ||
|
|
||
| // This creates a "module", which represents a collection of source files alongside | ||
| // some compilation options, such as optimization mode and linked system libraries. | ||
| // Every executable or library we compile will be based on one or more modules. | ||
| const lib_mod = b.createModule(.{ | ||
| // `root_source_file` is the Zig "entry point" of the module. If a module | ||
| // only contains e.g. external object files, you can make this `null`. | ||
| // In this case the main source file is merely a path, however, in more | ||
| // complicated build scripts, this could be a generated file. | ||
| .root_source_file = b.path("src/root.zig"), | ||
| .target = target, | ||
| .optimize = optimize, | ||
| }); | ||
|
|
||
| lib_mod.addImport("enr", enr_mod); | ||
|
|
||
| b.modules.put(b.dupe("zig-enr"), lib_mod) catch @panic("OOM"); | ||
|
GrapeBaBa marked this conversation as resolved.
Outdated
|
||
| // Now, we will create a static library based on the module we created above. | ||
| // This creates a `std.Build.Step.Compile`, which is the build step responsible | ||
| // for actually invoking the compiler. | ||
| const lib = b.addLibrary(.{ | ||
| .linkage = .static, | ||
| .name = "enr", | ||
| .root_module = lib_mod, | ||
| }); | ||
|
|
||
| // This declares intent for the library to be installed into the standard | ||
| // location when the user invokes the "install" step (the default step when | ||
| // running `zig build`). | ||
| b.installArtifact(lib); | ||
|
|
||
| // Creates a step for unit testing. This only builds the test executable | ||
| // but does not run it. | ||
| const lib_unit_tests = b.addTest(.{ | ||
| .root_module = lib_mod, | ||
| }); | ||
|
|
||
| const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); | ||
|
|
||
| // Similar to creating the run step earlier, this exposes a `test` step to | ||
| // the `zig build --help` menu, providing a way for the user to request | ||
| // running the unit tests. | ||
| const test_step = b.step("test", "Run unit tests"); | ||
| test_step.dependOn(&run_lib_unit_tests.step); | ||
|
|
||
| const install_docs = b.addInstallDirectory(.{ | ||
| .source_dir = lib.getEmittedDocs(), | ||
| .install_dir = .prefix, | ||
| .install_subdir = "docs", | ||
| }); | ||
| const docs_step = b.step("docs", "Generate documentation"); | ||
| docs_step.dependOn(&install_docs.step); | ||
| } | ||
|
GrapeBaBa marked this conversation as resolved.
|
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,52 @@ | ||
| .{ | ||
| // This is the default name used by packages depending on this one. For | ||
| // example, when a user runs `zig fetch --save <url>`, this field is used | ||
| // as the key in the `dependencies` table. Although the user can choose a | ||
| // different name, most users will stick with this provided value. | ||
| // | ||
| // It is redundant to include "zig" in this name because it is already | ||
| // within the Zig package namespace. | ||
| .name = .zig_enr, | ||
|
|
||
| // This is a [Semantic Version](https://semver.org/). | ||
| // In a future version of Zig it will be used for package deduplication. | ||
| .version = "0.0.0", | ||
|
|
||
| // Together with name, this represents a globally unique package | ||
| // identifier. This field is generated by the Zig toolchain when the | ||
| // package is first created, and then *never changes*. This allows | ||
| // unambiguous detection of one package being an updated version of | ||
| // another. | ||
| // | ||
| // When forking a Zig project, this id should be regenerated (delete the | ||
| // field and run `zig build`) if the upstream project is still maintained. | ||
| // Otherwise, the fork is *hostile*, attempting to take control over the | ||
| // original project's identity. Thus it is recommended to leave the comment | ||
| // on the following line intact, so that it shows up in code reviews that | ||
| // modify the field. | ||
| .fingerprint = 0x499ae5d25c594f6a, // Changing this has security and trust implications. | ||
|
|
||
| // Tracks the earliest Zig version that the package considers to be a | ||
| // supported use case. | ||
| .minimum_zig_version = "0.14.1", | ||
|
|
||
| // This field is optional. | ||
| // Each dependency must either provide a `url` and `hash`, or a `path`. | ||
| // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. | ||
| // Once all dependencies are fetched, `zig build` no longer requires | ||
| // internet connectivity. | ||
| .dependencies = .{ | ||
| .discv5 = .{ | ||
| .url = "git+https://github.com/blockblaz/zig-discv5#bc96ea8e6a8c3ddc5880256a11e19df3afe37870", | ||
| .hash = "discv5-0.1.0-fkJduBNjAQCUYP7JVBtZ6A5Y79UYpyC8JHz5kzGnB-K5", | ||
| }, | ||
| }, | ||
| .paths = .{ | ||
| "build.zig", | ||
| "build.zig.zon", | ||
| "src", | ||
| // For example... | ||
| //"LICENSE", | ||
| //"README.md", | ||
| }, | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.