Skip to content

Commit 7fe2609

Browse files
feat(bindings): expose more APIs for STF (#444)
these two missing APIs are required for fast confirmation rule spec tests on `lodestar`, see ChainSafe/lodestar#9516 spec tests failures
1 parent f932b1c commit 7fe2609

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

bindings/napi/BeaconStateView.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,23 @@ pub fn getNextShuffling(self: *const BeaconStateView) !js.Value {
13511351
return js_types.wrap(js.Value, try shufflingToNapi(shuffling));
13521352
}
13531353

1354+
pub fn getBeaconCommittee(self: *const BeaconStateView, slot_arg: js.Number, index: js.Number) !js.Array {
1355+
const env = js.env();
1356+
const cached_state = try self.requireState();
1357+
const slot_: u64 = @intCast(try slot_arg.toI64());
1358+
const index_: u64 = @intCast(try index.toI64());
1359+
1360+
const committee = try cached_state.epoch_cache.getBeaconCommittee(slot_, index_);
1361+
return .{ .val = try numberSliceToNapiValue(env, u64, committee, .{}) };
1362+
}
1363+
1364+
pub fn getBeaconCommitteeCountPerSlot(self: *const BeaconStateView, epoch_arg: js.Number) !js.Number {
1365+
const cached_state = try self.requireState();
1366+
const epoch_: u64 = @intCast(try epoch_arg.toI64());
1367+
1368+
return js.Number.from(try cached_state.epoch_cache.getCommitteeCountPerSlot(epoch_));
1369+
}
1370+
13541371
pub fn getShufflingAtEpoch(self: *const BeaconStateView, epoch_arg: js.Number) !js.Value {
13551372
const cached_state = try self.requireState();
13561373
const epoch_value: u64 = @intCast(try epoch_arg.toI64());

bindings/src/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ export declare class BeaconStateView {
250250
getPreviousShuffling(): EpochShuffling;
251251
getCurrentShuffling(): EpochShuffling;
252252
getNextShuffling(): EpochShuffling;
253+
getBeaconCommittee(): number[];
254+
getBeaconCommitteeCountPerSlot(): number;
253255
previousDecisionRoot: string;
254256
currentDecisionRoot: string;
255257
nextDecisionRoot: string;

0 commit comments

Comments
 (0)