From 91b83cfb895cf53d91d1a72f246d8d84f95919a7 Mon Sep 17 00:00:00 2001 From: skkw Date: Tue, 30 Jul 2019 15:09:47 +0200 Subject: [PATCH 1/3] add subname id --- src/aeser_api_encoder.erl | 5 +++++ src/aeser_chain_objects.erl | 4 ++++ src/aeser_id.erl | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/aeser_api_encoder.erl b/src/aeser_api_encoder.erl index e66bdec..ad67ca5 100644 --- a/src/aeser_api_encoder.erl +++ b/src/aeser_api_encoder.erl @@ -32,6 +32,7 @@ | account_pubkey | signature | name + | subname | commitment | peer_pubkey | state @@ -195,6 +196,7 @@ type2enc(signature) -> ?BASE58; type2enc(commitment) -> ?BASE58; type2enc(peer_pubkey) -> ?BASE58; type2enc(name) -> ?BASE58; +type2enc(subname) -> ?BASE58; type2enc(state) -> ?BASE64; type2enc(poi) -> ?BASE64; type2enc(state_trees) -> ?BASE64; @@ -223,6 +225,7 @@ type2pfx(signature) -> <<"sg">>; type2pfx(commitment) -> <<"cm">>; type2pfx(peer_pubkey) -> <<"pp">>; type2pfx(name) -> <<"nm">>; +type2pfx(subname) -> <<"sn">>; type2pfx(state) -> <<"st">>; type2pfx(poi) -> <<"pi">>; type2pfx(state_trees) -> <<"ss">>; @@ -250,6 +253,7 @@ pfx2type(<<"sg">>) -> signature; pfx2type(<<"cm">>) -> commitment; pfx2type(<<"pp">>) -> peer_pubkey; pfx2type(<<"nm">>) -> name; +pfx2type(<<"sn">>) -> subname; pfx2type(<<"st">>) -> state; pfx2type(<<"pi">>) -> poi; pfx2type(<<"ss">>) -> state_trees; @@ -277,6 +281,7 @@ byte_size_for_type(oracle_response) -> not_applicable; byte_size_for_type(account_pubkey) -> 32; byte_size_for_type(signature) -> 64; byte_size_for_type(name) -> not_applicable; +byte_size_for_type(subname) -> not_applicable; byte_size_for_type(commitment) -> 32; byte_size_for_type(peer_pubkey) -> 32; byte_size_for_type(state) -> 32; diff --git a/src/aeser_chain_objects.erl b/src/aeser_chain_objects.erl index 7eb6e13..14d1f24 100644 --- a/src/aeser_chain_objects.erl +++ b/src/aeser_chain_objects.erl @@ -52,6 +52,8 @@ tag(name_preclaim_tx) -> 33; tag(name_update_tx) -> 34; tag(name_revoke_tx) -> 35; tag(name_transfer_tx) -> 36; +tag(subname) -> 38; +tag(subname_tx) -> 39; tag(contract) -> 40; tag(contract_call) -> 41; tag(contract_create_tx) -> 42; @@ -109,6 +111,8 @@ rev_tag(33) -> name_preclaim_tx; rev_tag(34) -> name_update_tx; rev_tag(35) -> name_revoke_tx; rev_tag(36) -> name_transfer_tx; +rev_tag(38) -> subname; +rev_tag(39) -> subname_tx; rev_tag(40) -> contract; rev_tag(41) -> contract_call; rev_tag(42) -> contract_create_tx; diff --git a/src/aeser_id.erl b/src/aeser_id.erl index 229cfda..e71fd21 100644 --- a/src/aeser_id.erl +++ b/src/aeser_id.erl @@ -24,7 +24,7 @@ , val }). --type tag() :: 'account' | 'oracle' | 'name' +-type tag() :: 'account' | 'oracle' | 'name' | 'subname' | 'commitment' | 'contract' | 'channel'. -type val() :: <<_:256>>. -opaque(id() :: #id{}). @@ -41,6 +41,7 @@ -define(IS_TAG(___TAG___), ___TAG___ =:= account; ___TAG___ =:= oracle; ___TAG___ =:= name; + ___TAG___ =:= subname; ___TAG___ =:= commitment; ___TAG___ =:= contract; ___TAG___ =:= channel -- 2.30.2 From 7994428e56b598c467cd86be9181e5d1faf2a8d6 Mon Sep 17 00:00:00 2001 From: skkw Date: Thu, 8 Aug 2019 13:02:38 +0200 Subject: [PATCH 2/3] changed encoding of subnames to base64 --- src/aeser_api_encoder.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeser_api_encoder.erl b/src/aeser_api_encoder.erl index ad67ca5..746ac9a 100644 --- a/src/aeser_api_encoder.erl +++ b/src/aeser_api_encoder.erl @@ -196,7 +196,7 @@ type2enc(signature) -> ?BASE58; type2enc(commitment) -> ?BASE58; type2enc(peer_pubkey) -> ?BASE58; type2enc(name) -> ?BASE58; -type2enc(subname) -> ?BASE58; +type2enc(subname) -> ?BASE64; type2enc(state) -> ?BASE64; type2enc(poi) -> ?BASE64; type2enc(state_trees) -> ?BASE64; -- 2.30.2 From 81d0daa9d53a254251bb2aca05f65a2da2d93b59 Mon Sep 17 00:00:00 2001 From: skkw Date: Tue, 27 Aug 2019 10:39:36 +0200 Subject: [PATCH 3/3] add support for encoding/decoding of subname id --- src/aeser_id.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/aeser_id.erl b/src/aeser_id.erl index e71fd21..2003738 100644 --- a/src/aeser_id.erl +++ b/src/aeser_id.erl @@ -37,6 +37,7 @@ -define(PUB_SIZE, 32). -define(TAG_SIZE, 1). -define(SERIALIZED_SIZE, 33). %% ?TAG_SIZE + ?PUB_SIZE +-define(SUBNAME_SERIALIZED_SIZE, 65). %% ?TAG_SIZE + ?PUB_SIZE + ?PUB_SIZE -define(IS_TAG(___TAG___), ___TAG___ =:= account; ___TAG___ =:= oracle; @@ -83,24 +84,33 @@ is_id(_) -> false. -spec encode(id()) -> binary(). encode(#id{tag = Tag, val = Val}) -> Res = <<(encode_tag(Tag)):?TAG_SIZE/unit:8, Val/binary>>, - true = ?SERIALIZED_SIZE =:= byte_size(Res), + true = serialized_size(Tag) =:= byte_size(Res), Res. -spec decode(binary()) -> id(). decode(<>) -> #id{ tag = decode_tag(Tag) + , val = Val}; +decode(<>) -> + #id{ tag = subname = decode_tag(SubnameTag) , val = Val}. + %%%=================================================================== %%% Internal functions %%%=================================================================== +serialized_size(subname) -> ?SUBNAME_SERIALIZED_SIZE; +serialized_size(_) -> ?SERIALIZED_SIZE. + + 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(subname) -> 7; encode_tag(Other) -> error({illegal_id_tag_name, Other}). decode_tag(1) -> account; @@ -109,4 +119,5 @@ decode_tag(3) -> commitment; decode_tag(4) -> oracle; decode_tag(5) -> contract; decode_tag(6) -> channel; +decode_tag(7) -> subname; decode_tag(X) -> error({illegal_id_tag, X}). -- 2.30.2