From 4d2beb0337d90a280906e30542b65989ead6d044 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Thu, 29 Feb 2024 14:32:36 +0100 Subject: [PATCH] Add id tag and serializations for associate chain --- src/aeser_api_encoder.erl | 24 ++++++++++++++++++------ src/aeser_id.erl | 22 +++++++++++++--------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/aeser_api_encoder.erl b/src/aeser_api_encoder.erl index b9b9a3c..61114e0 100644 --- a/src/aeser_api_encoder.erl +++ b/src/aeser_api_encoder.erl @@ -31,6 +31,7 @@ | oracle_response | account_pubkey | account_seckey + | associate_chain | signature | name | commitment @@ -39,6 +40,7 @@ | poi | state_trees | call_state_tree + | mp_tree_hash | bytearray. -type extended_type() :: known_type() | block_hash | {id_hash, [known_type()]}. @@ -161,14 +163,16 @@ sha256_hash(Bin) -> crypto:hash(sha256, Bin). -id2type(account) -> account_pubkey; -id2type(channel) -> channel; -id2type(commitment) -> commitment; -id2type(contract) -> contract_pubkey; -id2type(name) -> name; -id2type(oracle) -> oracle_pubkey. +id2type(account) -> account_pubkey; +id2type(associate_chain) -> associate_chain; +id2type(channel) -> channel; +id2type(commitment) -> commitment; +id2type(contract) -> contract_pubkey; +id2type(name) -> name; +id2type(oracle) -> oracle_pubkey. type2id(account_pubkey) -> account; +type2id(associate_chain) -> associate_chain; type2id(channel) -> channel; type2id(commitment) -> commitment; type2id(contract_pubkey) -> contract; @@ -193,6 +197,7 @@ type2enc(oracle_query_id) -> ?BASE58; type2enc(oracle_response) -> ?BASE64; type2enc(account_pubkey) -> ?BASE58; type2enc(account_seckey) -> ?BASE58; +type2enc(associate_chain) -> ?BASE58; type2enc(signature) -> ?BASE58; type2enc(commitment) -> ?BASE58; type2enc(peer_pubkey) -> ?BASE58; @@ -201,6 +206,7 @@ type2enc(state) -> ?BASE64; type2enc(poi) -> ?BASE64; type2enc(state_trees) -> ?BASE64; type2enc(call_state_tree) -> ?BASE64; +type2enc(mp_tree_hash) -> ?BASE58; type2enc(bytearray) -> ?BASE64. @@ -222,6 +228,7 @@ type2pfx(oracle_query_id) -> <<"oq">>; type2pfx(oracle_response) -> <<"or">>; type2pfx(account_pubkey) -> <<"ak">>; type2pfx(account_seckey) -> <<"sk">>; +type2pfx(associate_chain) -> <<"ac">>; type2pfx(signature) -> <<"sg">>; type2pfx(commitment) -> <<"cm">>; type2pfx(peer_pubkey) -> <<"pp">>; @@ -230,6 +237,7 @@ type2pfx(state) -> <<"st">>; type2pfx(poi) -> <<"pi">>; type2pfx(state_trees) -> <<"ss">>; type2pfx(call_state_tree) -> <<"cs">>; +type2pfx(mp_tree_hash) -> <<"mt">>; type2pfx(bytearray) -> <<"ba">>. pfx2type(<<"kh">>) -> key_block_hash; @@ -250,6 +258,7 @@ pfx2type(<<"oq">>) -> oracle_query_id; pfx2type(<<"or">>) -> oracle_response; pfx2type(<<"ak">>) -> account_pubkey; pfx2type(<<"sk">>) -> account_seckey; +pfx2type(<<"ac">>) -> associate_chain; pfx2type(<<"sg">>) -> signature; pfx2type(<<"cm">>) -> commitment; pfx2type(<<"pp">>) -> peer_pubkey; @@ -258,6 +267,7 @@ pfx2type(<<"st">>) -> state; pfx2type(<<"pi">>) -> poi; pfx2type(<<"ss">>) -> state_trees; pfx2type(<<"cs">>) -> call_state_tree; +pfx2type(<<"mt">>) -> mp_tree_hash; pfx2type(<<"ba">>) -> bytearray. -spec byte_size_for_type(known_type()) -> non_neg_integer() | not_applicable. @@ -280,6 +290,7 @@ byte_size_for_type(oracle_query_id) -> 32; byte_size_for_type(oracle_response) -> not_applicable; byte_size_for_type(account_pubkey) -> 32; byte_size_for_type(account_seckey) -> 32; +byte_size_for_type(associate_chain) -> 32; byte_size_for_type(signature) -> 64; byte_size_for_type(name) -> not_applicable; byte_size_for_type(commitment) -> 32; @@ -288,6 +299,7 @@ byte_size_for_type(state) -> 32; byte_size_for_type(poi) -> not_applicable; byte_size_for_type(state_trees) -> not_applicable; byte_size_for_type(call_state_tree) -> not_applicable; +byte_size_for_type(mp_tree_hash) -> 32; byte_size_for_type(bytearray) -> not_applicable. diff --git a/src/aeser_id.erl b/src/aeser_id.erl index 229cfda..f534044 100644 --- a/src/aeser_id.erl +++ b/src/aeser_id.erl @@ -25,7 +25,8 @@ }). -type tag() :: 'account' | 'oracle' | 'name' - | 'commitment' | 'contract' | 'channel'. + | 'commitment' | 'contract' | 'channel' + | 'associate_chain' . -type val() :: <<_:256>>. -opaque(id() :: #id{}). @@ -43,7 +44,8 @@ ___TAG___ =:= name; ___TAG___ =:= commitment; ___TAG___ =:= contract; - ___TAG___ =:= channel + ___TAG___ =:= channel; + ___TAG___ =:= associate_chain ). -define(IS_VAL(___VAL___), byte_size(___VAL___) =:= 32). @@ -94,13 +96,14 @@ decode(<>) -> %%% Internal functions %%%=================================================================== -encode_tag(account) -> 1; -encode_tag(name) -> 2; -encode_tag(commitment) -> 3; -encode_tag(oracle) -> 4; -encode_tag(contract) -> 5; -encode_tag(channel) -> 6; -encode_tag(Other) -> error({illegal_id_tag_name, Other}). +encode_tag(account) -> 1; +encode_tag(name) -> 2; +encode_tag(commitment) -> 3; +encode_tag(oracle) -> 4; +encode_tag(contract) -> 5; +encode_tag(channel) -> 6; +encode_tag(associate_chain) -> 7; +encode_tag(Other) -> error({illegal_id_tag_name, Other}). decode_tag(1) -> account; decode_tag(2) -> name; @@ -108,4 +111,5 @@ decode_tag(3) -> commitment; decode_tag(4) -> oracle; decode_tag(5) -> contract; decode_tag(6) -> channel; +decode_tag(7) -> associate_chain; decode_tag(X) -> error({illegal_id_tag, X}).