fed-sx-m1: Step 5c-populate — bootstrap:populate_registry into gen_server + 14 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
default_base/0, ends_with_sx/1,
|
||||
build_genesis/1, verify_genesis/2,
|
||||
cidhash_path/1, write_cidhash/2, read_cidhash/1,
|
||||
load_genesis/1, strip_sx_suffix/1]).
|
||||
load_genesis/1, strip_sx_suffix/1,
|
||||
populate_registry/0]).
|
||||
|
||||
%% Genesis bundle reader per design §12.2.
|
||||
%%
|
||||
@@ -185,3 +186,22 @@ take_prefix(_, 0) -> <<>>;
|
||||
take_prefix(<<H, Rest/binary>>, N) when N > 0 ->
|
||||
Tail = take_prefix(Rest, N - 1),
|
||||
<<H, Tail/binary>>.
|
||||
|
||||
%% populate_registry/0 — load the canonical genesis bundle and
|
||||
%% register every entry in the running registry gen_server. The
|
||||
%% caller is expected to have started the registry (via
|
||||
%% registry:start_link/0) before calling this. Returns the count
|
||||
%% of entries registered across all kinds.
|
||||
populate_registry() ->
|
||||
{ok, Sections} = read_genesis(),
|
||||
populate_sections(Sections, 0).
|
||||
|
||||
populate_sections([], Count) -> Count;
|
||||
populate_sections([{Kind, Entries} | Rest], Count) ->
|
||||
populate_sections(Rest, Count + populate_entries(Kind, Entries, 0)).
|
||||
|
||||
populate_entries(_, [], Count) -> Count;
|
||||
populate_entries(Kind, [{Name, Bytes} | Rest], Count) ->
|
||||
BaseName = strip_sx_suffix(Name),
|
||||
ok = registry:register(Kind, BaseName, Bytes),
|
||||
populate_entries(Kind, Rest, Count + 1).
|
||||
|
||||
Reference in New Issue
Block a user