Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bindings/napi/BeaconStateView.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const c = @import("config");
const fork_types = @import("fork_types");
const st = @import("state_transition");
Expand Down Expand Up @@ -37,6 +37,7 @@ pub fn BeaconStateView_ctor(env: napi.Env, cb: napi.CallbackInfo(0)) !napi.Value
cached_state,
BeaconStateView_finalize,
null,
null,
Comment thread
spiral-ladder marked this conversation as resolved.
);

return cb.this();
Expand Down
32 changes: 28 additions & 4 deletions bindings/napi/blst.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains the necessary bindings for blst operations in lodestar-ts.
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const bls = @import("bls");
const builtin = @import("builtin");
const getter = @import("napi_property_descriptor.zig").getter;
Expand Down Expand Up @@ -108,7 +108,15 @@ pub fn PublicKey_finalize(_: napi.Env, pk: *PublicKey, _: ?*anyopaque) void {
pub fn PublicKey_ctor(env: napi.Env, cb: napi.CallbackInfo(0)) !napi.Value {
const pk = try allocator.create(PublicKey);
errdefer allocator.destroy(pk);
_ = try env.wrap(cb.this(), PublicKey, pk, PublicKey_finalize, null);

_ = try env.wrap(
cb.this(),
PublicKey,
pk,
PublicKey_finalize,
null, // finalize hint
null, // ref
);
return cb.this();
}
Comment thread
spiral-ladder marked this conversation as resolved.

Expand Down Expand Up @@ -218,7 +226,15 @@ pub fn Signature_finalize(_: napi.Env, sig: *Signature, _: ?*anyopaque) void {
pub fn Signature_ctor(env: napi.Env, cb: napi.CallbackInfo(0)) !napi.Value {
const sig = try allocator.create(Signature);
errdefer allocator.destroy(sig);
_ = try env.wrap(cb.this(), Signature, sig, Signature_finalize, null);

_ = try env.wrap(
cb.this(),
Signature,
sig,
Signature_finalize,
null, // finalize hint
null, // ref
);
return cb.this();
}
Comment thread
spiral-ladder marked this conversation as resolved.

Expand Down Expand Up @@ -327,7 +343,15 @@ pub fn SecretKey_finalize(_: napi.Env, sk: *SecretKey, _: ?*anyopaque) void {
pub fn SecretKey_ctor(env: napi.Env, cb: napi.CallbackInfo(0)) !napi.Value {
const sk = try allocator.create(SecretKey);
errdefer allocator.destroy(sk);
_ = try env.wrap(cb.this(), SecretKey, sk, SecretKey_finalize, null);

_ = try env.wrap(
cb.this(),
SecretKey,
sk,
SecretKey_finalize,
null, // finalize hint
null, // ref
);
return cb.this();
}
Comment thread
spiral-ladder marked this conversation as resolved.

Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/config.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const active_preset = @import("preset").active_preset;
const c = @import("config");
const BeaconConfig = @import("config").BeaconConfig;
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/metrics.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const state_transition = @import("state_transition");

var gpa: std.heap.DebugAllocator(.{}) = .init;
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/napi_property_descriptor.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");

/// Extracts a function name, without prefix, from a napi binding function.
///
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/pool.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const Node = @import("persistent_merkle_tree").Node;

/// Pool uses page allocator for internal allocations.
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/pubkeys.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const bls = @import("bls");
const blst_bindings = @import("./blst.zig");
const PubkeyIndexMap = @import("state_transition").PubkeyIndexMap;
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/root.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const pool = @import("./pool.zig");
const pubkeys = @import("./pubkeys.zig");
const config = @import("./config.zig");
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/shuffle.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const innerShuffleList = @import("state_transition").shuffle.innerShuffleList;

pub fn Shuffle_shuffleList(env: napi.Env, cb: napi.CallbackInfo(4)) !napi.Value {
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/state_transition.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const builtin = @import("builtin");
const fork_types = @import("fork_types");
const state_transition = @import("state_transition");
Expand Down
2 changes: 1 addition & 1 deletion bindings/napi/to_napi_value.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const ssz = @import("ssz");
const napi = @import("zapi:napi");
const napi = @import("zapi:zapi");
const constants = @import("constants");

pub fn sszValueToNapiValue(env: napi.Env, comptime ST: type, value: *const ST.Type) !napi.Value {
Expand Down
2 changes: 1 addition & 1 deletion bindings/test/shuffle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("innerShuffleList", () => {
const forwards = false;
expect(() => {
innerShuffleList(invalidInput as any, seed, rounds, forwards);
}).toThrow("Invalid argument");
}).toThrow("Native callback failed");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error message expectation has changed from 'Invalid argument' to 'Native callback failed'. This generic message is less descriptive and represents a regression in developer experience (Rule 207). Consider if the native bindings or the zapi library can be updated to propagate more specific error names to the JavaScript environment.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think both messages are equally vague and should be fixed on the zapi level instead of here

});

it("should fail with invalid rounds", async () => {
Expand Down
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ pub fn build(b: *std.Build) void {
module_bindings.addImport("config", module_config);
module_bindings.addImport("fork_types", module_fork_types);
module_bindings.addImport("state_transition", module_state_transition);
module_bindings.addImport("zapi:napi", dep_zapi.module("napi"));
module_bindings.addImport("zapi:zapi", dep_zapi.module("zapi"));

module_int.addImport("config", module_config);
module_int.addImport("download_era_options", options_module_download_era_options);
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
.hash = "zig_yaml-0.1.0-C1161m2NAgDhth5OvjG1o1UNKcdo-XNfO82m10J1g4Cl",
},
.zapi = .{
.url = "git+https://github.com/chainsafe/zapi#cf013457cdf0612a62a6d008d65505ff79e85596",
.hash = "napi_z-0.1.0-iqJb7-4oAgBkIQFWFEDazD0-G9NRBQZaEY0fwTB7Aqbu",
.url = "git+https://github.com/chainsafe/zapi#5a51cf21121372451bd56af97db896f474bce384",
.hash = "zapi-0.1.0-rIqzUTM-AgDqeGAe3zmoh8_y6CtuBra5RE_BJVmUFMfX",
},
.zbench = .{
.url = "git+https://github.com/hendriknielaender/zBench#d8c7dd485306b88b757d52005614ebcb0a336942",
Expand Down
4 changes: 2 additions & 2 deletions zbuild.zon
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.url = "git+https://github.com/chainsafe/zig-yaml#e0e5962579e990a66c21424416c7ac092b20b772",
},
.zapi = .{
.url = "git+https://github.com/chainsafe/zapi#cf013457cdf0612a62a6d008d65505ff79e85596",
.url = "git+https://github.com/chainsafe/zapi#5a51cf21121372451bd56af97db896f474bce384",
},
.zbench = .{
.url = "git+https://github.com/hendriknielaender/zBench#d8c7dd485306b88b757d52005614ebcb0a336942",
Expand Down Expand Up @@ -253,7 +253,7 @@
.config,
.fork_types,
.state_transition,
"zapi:napi",
"zapi:zapi",
},
},
.linkage = .dynamic,
Expand Down
Loading