add subname id #20
@ -32,6 +32,7 @@
|
|||||||
| account_pubkey
|
| account_pubkey
|
||||||
| signature
|
| signature
|
||||||
| name
|
| name
|
||||||
|
| subname
|
||||||
| commitment
|
| commitment
|
||||||
| peer_pubkey
|
| peer_pubkey
|
||||||
| state
|
| state
|
||||||
@ -195,6 +196,7 @@ type2enc(signature) -> ?BASE58;
|
|||||||
type2enc(commitment) -> ?BASE58;
|
type2enc(commitment) -> ?BASE58;
|
||||||
type2enc(peer_pubkey) -> ?BASE58;
|
type2enc(peer_pubkey) -> ?BASE58;
|
||||||
type2enc(name) -> ?BASE58;
|
type2enc(name) -> ?BASE58;
|
||||||
|
type2enc(subname) -> ?BASE64;
|
||||||
type2enc(state) -> ?BASE64;
|
type2enc(state) -> ?BASE64;
|
||||||
type2enc(poi) -> ?BASE64;
|
type2enc(poi) -> ?BASE64;
|
||||||
type2enc(state_trees) -> ?BASE64;
|
type2enc(state_trees) -> ?BASE64;
|
||||||
@ -223,6 +225,7 @@ type2pfx(signature) -> <<"sg">>;
|
|||||||
type2pfx(commitment) -> <<"cm">>;
|
type2pfx(commitment) -> <<"cm">>;
|
||||||
type2pfx(peer_pubkey) -> <<"pp">>;
|
type2pfx(peer_pubkey) -> <<"pp">>;
|
||||||
type2pfx(name) -> <<"nm">>;
|
type2pfx(name) -> <<"nm">>;
|
||||||
|
type2pfx(subname) -> <<"sn">>;
|
||||||
type2pfx(state) -> <<"st">>;
|
type2pfx(state) -> <<"st">>;
|
||||||
type2pfx(poi) -> <<"pi">>;
|
type2pfx(poi) -> <<"pi">>;
|
||||||
type2pfx(state_trees) -> <<"ss">>;
|
type2pfx(state_trees) -> <<"ss">>;
|
||||||
@ -250,6 +253,7 @@ pfx2type(<<"sg">>) -> signature;
|
|||||||
pfx2type(<<"cm">>) -> commitment;
|
pfx2type(<<"cm">>) -> commitment;
|
||||||
pfx2type(<<"pp">>) -> peer_pubkey;
|
pfx2type(<<"pp">>) -> peer_pubkey;
|
||||||
pfx2type(<<"nm">>) -> name;
|
pfx2type(<<"nm">>) -> name;
|
||||||
|
pfx2type(<<"sn">>) -> subname;
|
||||||
pfx2type(<<"st">>) -> state;
|
pfx2type(<<"st">>) -> state;
|
||||||
pfx2type(<<"pi">>) -> poi;
|
pfx2type(<<"pi">>) -> poi;
|
||||||
pfx2type(<<"ss">>) -> state_trees;
|
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(account_pubkey) -> 32;
|
||||||
byte_size_for_type(signature) -> 64;
|
byte_size_for_type(signature) -> 64;
|
||||||
byte_size_for_type(name) -> not_applicable;
|
byte_size_for_type(name) -> not_applicable;
|
||||||
|
byte_size_for_type(subname) -> not_applicable;
|
||||||
byte_size_for_type(commitment) -> 32;
|
byte_size_for_type(commitment) -> 32;
|
||||||
byte_size_for_type(peer_pubkey) -> 32;
|
byte_size_for_type(peer_pubkey) -> 32;
|
||||||
byte_size_for_type(state) -> 32;
|
byte_size_for_type(state) -> 32;
|
||||||
|
@ -52,6 +52,8 @@ tag(name_preclaim_tx) -> 33;
|
|||||||
tag(name_update_tx) -> 34;
|
tag(name_update_tx) -> 34;
|
||||||
tag(name_revoke_tx) -> 35;
|
tag(name_revoke_tx) -> 35;
|
||||||
tag(name_transfer_tx) -> 36;
|
tag(name_transfer_tx) -> 36;
|
||||||
|
tag(subname) -> 38;
|
||||||
|
tag(subname_tx) -> 39;
|
||||||
tag(contract) -> 40;
|
tag(contract) -> 40;
|
||||||
tag(contract_call) -> 41;
|
tag(contract_call) -> 41;
|
||||||
tag(contract_create_tx) -> 42;
|
tag(contract_create_tx) -> 42;
|
||||||
@ -109,6 +111,8 @@ rev_tag(33) -> name_preclaim_tx;
|
|||||||
rev_tag(34) -> name_update_tx;
|
rev_tag(34) -> name_update_tx;
|
||||||
rev_tag(35) -> name_revoke_tx;
|
rev_tag(35) -> name_revoke_tx;
|
||||||
rev_tag(36) -> name_transfer_tx;
|
rev_tag(36) -> name_transfer_tx;
|
||||||
|
rev_tag(38) -> subname;
|
||||||
|
rev_tag(39) -> subname_tx;
|
||||||
rev_tag(40) -> contract;
|
rev_tag(40) -> contract;
|
||||||
rev_tag(41) -> contract_call;
|
rev_tag(41) -> contract_call;
|
||||||
rev_tag(42) -> contract_create_tx;
|
rev_tag(42) -> contract_create_tx;
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
, val
|
, val
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-type tag() :: 'account' | 'oracle' | 'name'
|
-type tag() :: 'account' | 'oracle' | 'name' | 'subname'
|
||||||
| 'commitment' | 'contract' | 'channel'.
|
| 'commitment' | 'contract' | 'channel'.
|
||||||
-type val() :: <<_:256>>.
|
-type val() :: <<_:256>>.
|
||||||
-opaque(id() :: #id{}).
|
-opaque(id() :: #id{}).
|
||||||
@ -37,10 +37,12 @@
|
|||||||
-define(PUB_SIZE, 32).
|
-define(PUB_SIZE, 32).
|
||||||
-define(TAG_SIZE, 1).
|
-define(TAG_SIZE, 1).
|
||||||
-define(SERIALIZED_SIZE, 33). %% ?TAG_SIZE + ?PUB_SIZE
|
-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;
|
-define(IS_TAG(___TAG___), ___TAG___ =:= account;
|
||||||
___TAG___ =:= oracle;
|
___TAG___ =:= oracle;
|
||||||
___TAG___ =:= name;
|
___TAG___ =:= name;
|
||||||
|
___TAG___ =:= subname;
|
||||||
___TAG___ =:= commitment;
|
___TAG___ =:= commitment;
|
||||||
___TAG___ =:= contract;
|
___TAG___ =:= contract;
|
||||||
___TAG___ =:= channel
|
___TAG___ =:= channel
|
||||||
@ -82,24 +84,33 @@ is_id(_) -> false.
|
|||||||
-spec encode(id()) -> binary().
|
-spec encode(id()) -> binary().
|
||||||
encode(#id{tag = Tag, val = Val}) ->
|
encode(#id{tag = Tag, val = Val}) ->
|
||||||
Res = <<(encode_tag(Tag)):?TAG_SIZE/unit:8, Val/binary>>,
|
Res = <<(encode_tag(Tag)):?TAG_SIZE/unit:8, Val/binary>>,
|
||||||
true = ?SERIALIZED_SIZE =:= byte_size(Res),
|
true = serialized_size(Tag) =:= byte_size(Res),
|
||||||
Res.
|
Res.
|
||||||
|
|
||||||
-spec decode(binary()) -> id().
|
-spec decode(binary()) -> id().
|
||||||
decode(<<Tag:?TAG_SIZE/unit:8, Val:?PUB_SIZE/binary>>) ->
|
decode(<<Tag:?TAG_SIZE/unit:8, Val:?PUB_SIZE/binary>>) ->
|
||||||
#id{ tag = decode_tag(Tag)
|
#id{ tag = decode_tag(Tag)
|
||||||
|
, val = Val};
|
||||||
|
decode(<<SubnameTag:?TAG_SIZE/unit:8, Val:(?PUB_SIZE+?PUB_SIZE)/binary>>) ->
|
||||||
|
#id{ tag = subname = decode_tag(SubnameTag)
|
||||||
, val = Val}.
|
, val = Val}.
|
||||||
|
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
|
serialized_size(subname) -> ?SUBNAME_SERIALIZED_SIZE;
|
||||||
|
serialized_size(_) -> ?SERIALIZED_SIZE.
|
||||||
|
|
||||||
|
|
||||||
encode_tag(account) -> 1;
|
encode_tag(account) -> 1;
|
||||||
encode_tag(name) -> 2;
|
encode_tag(name) -> 2;
|
||||||
encode_tag(commitment) -> 3;
|
encode_tag(commitment) -> 3;
|
||||||
encode_tag(oracle) -> 4;
|
encode_tag(oracle) -> 4;
|
||||||
encode_tag(contract) -> 5;
|
encode_tag(contract) -> 5;
|
||||||
encode_tag(channel) -> 6;
|
encode_tag(channel) -> 6;
|
||||||
|
encode_tag(subname) -> 7;
|
||||||
encode_tag(Other) -> error({illegal_id_tag_name, Other}).
|
encode_tag(Other) -> error({illegal_id_tag_name, Other}).
|
||||||
|
|
||||||
decode_tag(1) -> account;
|
decode_tag(1) -> account;
|
||||||
@ -108,4 +119,5 @@ decode_tag(3) -> commitment;
|
|||||||
decode_tag(4) -> oracle;
|
decode_tag(4) -> oracle;
|
||||||
decode_tag(5) -> contract;
|
decode_tag(5) -> contract;
|
||||||
decode_tag(6) -> channel;
|
decode_tag(6) -> channel;
|
||||||
|
decode_tag(7) -> subname;
|
||||||
decode_tag(X) -> error({illegal_id_tag, X}).
|
decode_tag(X) -> error({illegal_id_tag, X}).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user