Compare commits

...

4 Commits

Author SHA1 Message Date
Ulf Wiger 79b43b0665 Add account_auth_update_tx tag
Gajumaru Serialization Tests / tests (push) Successful in 11s
2026-07-06 15:30:19 +02:00
Ulf Wiger a84dcc880d Add is_account/1 and account_pubkey/1 helpers
Gajumaru Serialization Tests / tests (push) Successful in 11s
Extended-auth account ids use an {account, Subtype} tag. These helpers
let callers test account membership and extract the 32-byte pubkey
without pattern-matching on specialize/1 results.
2026-07-06 12:26:38 +02:00
Ulf Wiger a368c64f7e Add missing tag for proposal_gossip_tx
Gajumaru Serialization Tests / tests (push) Successful in 11s
2026-07-06 10:55:20 +02:00
Ulf Wiger dbfc013c8a Add auth tx and account sig store
Gajumaru Serialization Tests / tests (push) Successful in 11s
2026-07-06 10:19:38 +02:00
3 changed files with 68 additions and 0 deletions
+8
View File
@@ -117,6 +117,10 @@ tag(entry_transfer_tx) -> 142;
tag(entry_destroy_tx) -> 143;
tag(account_key_store) -> 144;
tag(account_create_tx) -> 145;
tag(account_sig_store) -> 146;
tag(auth_tx) -> 147;
tag(proposal_gossip_tx) -> 148;
tag(account_auth_update_tx) -> 149;
tag(pof) -> 200.
rev_tag(10) -> account;
@@ -198,4 +202,8 @@ rev_tag(142) -> entry_transfer_tx;
rev_tag(143) -> entry_destroy_tx;
rev_tag(144) -> account_key_store;
rev_tag(145) -> account_create_tx;
rev_tag(146) -> account_sig_store;
rev_tag(147) -> auth_tx;
rev_tag(148) -> proposal_gossip_tx;
rev_tag(149) -> account_auth_update_tx;
rev_tag(200) -> pof.
+16
View File
@@ -14,6 +14,8 @@
, specialize/1
, specialize/2
, specialize_type/1
, is_account/1
, account_pubkey/1
, to_map/1
, is_id/1
]).
@@ -104,6 +106,20 @@ specialize_type(#id{tag = {Tag, _}}) when ?IS_TAG(Tag) ->
specialize_type(#id{tag = Tag}) when ?IS_TAG(Tag) ->
Tag.
-spec is_account(id() | term()) -> boolean().
is_account(#id{tag = account}) ->
true;
is_account(#id{tag = {account, _}}) ->
true;
is_account(_) ->
false.
-spec account_pubkey(id()) -> val().
account_pubkey(#id{tag = account, val = Val}) when ?IS_VAL(Val) ->
Val;
account_pubkey(#id{tag = {account, _}, val = Val}) when ?IS_VAL(Val) ->
Val.
-spec to_map(id()) -> id_map().
to_map(#id{tag = {Tag, SubType}, val = Val}) when ?IS_TAG(Tag) ->
#{ type => Tag
+44
View File
@@ -0,0 +1,44 @@
-module(gmser_id_tests).
-include_lib("eunit/include/eunit.hrl").
-define(PUBKEY, <<12345:32/unit:8>>).
is_account_test() ->
{"is_account recognizes standard and extended account ids",
fun() ->
?assert(gmser_id:is_account(gmser_id:create(account, ?PUBKEY))),
?assert(gmser_id:is_account(gmser_id:create({account, 0}, ?PUBKEY))),
?assert(gmser_id:is_account(gmser_id:create({account, 5}, ?PUBKEY))),
?assertNot(gmser_id:is_account(gmser_id:create(contract, ?PUBKEY))),
?assertNot(gmser_id:is_account(not_an_id))
end}.
account_pubkey_test() ->
{"account_pubkey returns the 32-byte account hash",
fun() ->
?assertEqual(?PUBKEY,
gmser_id:account_pubkey(gmser_id:create(account, ?PUBKEY))),
?assertEqual(?PUBKEY,
gmser_id:account_pubkey(gmser_id:create({account, 3}, ?PUBKEY))),
?assertEqual(?PUBKEY,
gmser_id:account_pubkey(gmser_id:create({account, 6}, ?PUBKEY)))
end}.
account_pubkey_matches_specialize_test() ->
{"account_pubkey agrees with specialize/2 for account ids",
fun() ->
Id = gmser_id:create({account, 2}, ?PUBKEY),
?assertEqual(gmser_id:specialize(Id, account),
gmser_id:account_pubkey(Id))
end}.
extended_account_roundtrip_test() ->
{"extended account ids round-trip through encode/decode",
fun() ->
Id = gmser_id:create({account, 4}, ?PUBKEY),
?assert(gmser_id:is_account(Id)),
Id1 = gmser_id:decode(gmser_id:encode(Id)),
?assertEqual(?PUBKEY, gmser_id:account_pubkey(Id1)),
?assertEqual(account, gmser_id:specialize_type(Id1))
end}.