Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a221b905c2 | |||
| 749f7943d8 | |||
| ece32da3e8 | |||
| 6fae7b4119 | |||
| 295799435b | |||
| 7046b9625d | |||
| 670fe59a21 | |||
| f37cec34da | |||
| e24ddef246 | |||
| 9124228ff4 |
+1
-1
@@ -7,7 +7,7 @@ _*
|
|||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
.erlang.cookie
|
.erlang.cookie
|
||||||
ebin
|
ebin/*.beam
|
||||||
log
|
log
|
||||||
erl_crash.dump
|
erl_crash.dump
|
||||||
.rebar
|
.rebar
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{application,gmserialization,
|
||||||
|
[{description,"Serialization of data for the Gajumaru"},
|
||||||
|
{vsn,"0.1.2"},
|
||||||
|
{registered,[]},
|
||||||
|
{applications,[kernel,stdlib,crypto,base58]},
|
||||||
|
{env,[]},
|
||||||
|
{modules,[gmser_api_encoder,gmser_chain_objects,
|
||||||
|
gmser_contract_code,gmser_delegation,gmser_id,
|
||||||
|
gmser_rlp,gmserialization]},
|
||||||
|
{licenses,[]},
|
||||||
|
{links,[]}]}.
|
||||||
+9
-3
@@ -1,4 +1,10 @@
|
|||||||
{erl_opts, [debug_info]}.
|
{erl_opts, [debug_info]}.
|
||||||
{deps, [ {base58, {git, "https://git.qpq.swiss/QPQ-AG/erl-base58.git", {ref, "b6c41ff2f86f679675b95a780bfc6475e973d796"}}}
|
{deps,
|
||||||
, {enacl, {git, "https://git.qpq.swiss/QPQ-AG/enacl.git", {ref, "4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}}
|
[{base58,
|
||||||
]}.
|
{git,
|
||||||
|
"https://git.qpq.swiss/QPQ-AG/erl-base58.git",
|
||||||
|
{ref, "7290fa23664b4134d15da353061ac97aa158b332"}}},
|
||||||
|
{enacl,
|
||||||
|
{git,
|
||||||
|
"https://git.qpq.swiss/QPQ-AG/enacl.git",
|
||||||
|
{ref, "4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}}]}.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[{<<"base58">>,
|
[{<<"base58">>,
|
||||||
{git,"https://git.qpq.swiss/QPQ-AG/erl-base58.git",
|
{git,"https://git.qpq.swiss/QPQ-AG/erl-base58.git",
|
||||||
{ref,"b6c41ff2f86f679675b95a780bfc6475e973d796"}},
|
{ref,"7290fa23664b4134d15da353061ac97aa158b332"}},
|
||||||
0},
|
0},
|
||||||
{<<"enacl">>,
|
{<<"enacl">>,
|
||||||
{git,"https://git.qpq.swiss/QPQ-AG/enacl.git",
|
{git,"https://git.qpq.swiss/QPQ-AG/enacl.git",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(gmser_api_encoder).
|
-module(gmser_api_encoder).
|
||||||
|
-vsn("0.1.2").
|
||||||
|
|
||||||
-export([encode/2,
|
-export([encode/2,
|
||||||
decode/1,
|
decode/1,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(gmser_chain_objects).
|
-module(gmser_chain_objects).
|
||||||
|
-vsn("0.1.2").
|
||||||
|
|
||||||
-export([ serialize/4
|
-export([ serialize/4
|
||||||
, deserialize/4
|
, deserialize/4
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(gmser_contract_code).
|
-module(gmser_contract_code).
|
||||||
|
-vsn("0.1.2").
|
||||||
|
|
||||||
-include("gmser_contract_code.hrl").
|
-include("gmser_contract_code.hrl").
|
||||||
|
|
||||||
@@ -17,14 +18,15 @@
|
|||||||
serialize(CodeMap) ->
|
serialize(CodeMap) ->
|
||||||
serialize(CodeMap, ?SOPHIA_CONTRACT_VSN_3).
|
serialize(CodeMap, ?SOPHIA_CONTRACT_VSN_3).
|
||||||
|
|
||||||
|
|
||||||
-spec serialize(map(), non_neg_integer()) -> binary().
|
-spec serialize(map(), non_neg_integer()) -> binary().
|
||||||
serialize(CodeMap = #{ byte_code := ByteCode
|
serialize(CodeMap = #{ byte_code := ByteCode
|
||||||
, type_info := TypeInfo }, SophiaContractVersion) ->
|
, type_info := TypeInfo }, SophiaContractVersion) ->
|
||||||
%% Source hash
|
%% Source hash
|
||||||
SourceHash = case CodeMap of
|
SourceHash =
|
||||||
|
case CodeMap of
|
||||||
#{ source_hash := SHash } -> SHash;
|
#{ source_hash := SHash } -> SHash;
|
||||||
#{ contract_source := SrcStr } ->
|
#{ contract_source := SrcStr } -> blake2(32, list_to_binary(SrcStr))
|
||||||
enacl:generichash(32, list_to_binary(SrcStr))
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
%% Compiler version
|
%% Compiler version
|
||||||
@@ -48,6 +50,21 @@ serialize(CodeMap = #{ byte_code := ByteCode
|
|||||||
serialization_template(SophiaContractVersion),
|
serialization_template(SophiaContractVersion),
|
||||||
Fields).
|
Fields).
|
||||||
|
|
||||||
|
% NOTE:
|
||||||
|
% This form significantly favors the presence of enacl and slows fallback
|
||||||
|
% invokation of eblake2. `try' is really fast; the error throwing machinery
|
||||||
|
% is comparatively slow. The assumption here is that in cases where you want
|
||||||
|
% eblake2 performance isn't the problem you're solving (you're probably not
|
||||||
|
% syncing a new node, for example).
|
||||||
|
blake2(Size, Bin) ->
|
||||||
|
try
|
||||||
|
enacl:generichash(Size, Bin)
|
||||||
|
catch error:undef ->
|
||||||
|
{ok, Hash} = eblake2:blake2b(Size, Bin),
|
||||||
|
Hash
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
-spec deserialize(binary()) -> map().
|
-spec deserialize(binary()) -> map().
|
||||||
deserialize(Binary) ->
|
deserialize(Binary) ->
|
||||||
case gmser_chain_objects:deserialize_type_and_vsn(Binary) of
|
case gmser_chain_objects:deserialize_type_and_vsn(Binary) of
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(gmser_delegation).
|
-module(gmser_delegation).
|
||||||
|
-vsn("0.1.2").
|
||||||
|
|
||||||
-export([ aens_preclaim_sig/3
|
-export([ aens_preclaim_sig/3
|
||||||
, aens_name_sig/4
|
, aens_name_sig/4
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(gmser_id).
|
-module(gmser_id).
|
||||||
|
-vsn("0.1.2").
|
||||||
|
|
||||||
-export([ create/2
|
-export([ create/2
|
||||||
, specialize/1
|
, specialize/1
|
||||||
|
|||||||
@@ -4,12 +4,15 @@
|
|||||||
%%% @doc
|
%%% @doc
|
||||||
%%% Implementation of the Recursive Length Prefix.
|
%%% Implementation of the Recursive Length Prefix.
|
||||||
%%%
|
%%%
|
||||||
|
%%% https://zxq9.com/archives/2749
|
||||||
%%% https://github.com/ethereum/wiki/wiki/RLP
|
%%% https://github.com/ethereum/wiki/wiki/RLP
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(gmser_rlp).
|
-module(gmser_rlp).
|
||||||
|
-vsn("0.1.2").
|
||||||
|
|
||||||
-export([ decode/1
|
-export([ decode/1
|
||||||
, decode_one/1
|
, decode_one/1
|
||||||
, encode/1
|
, encode/1
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
|
|
||||||
-module(gmserialization).
|
-module(gmserialization).
|
||||||
|
-vsn("0.1.2").
|
||||||
|
|
||||||
-export([ decode_fields/2
|
-export([ decode_fields/2
|
||||||
, deserialize/5
|
, deserialize/5
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{name,"Gajumaru Serialization"}.
|
||||||
|
{type,lib}.
|
||||||
|
{modules,[]}.
|
||||||
|
{prefix,none}.
|
||||||
|
{author,"Hans Svensson"}.
|
||||||
|
{desc,"Serialization helpers for the Gajumaru."}.
|
||||||
|
{package_id,{"otpr","gmserialization",{0,1,2}}}.
|
||||||
|
{deps,[{"otpr","base58",{0,1,1}},{"otpr","eblake2",{1,0,0}}]}.
|
||||||
|
{key_name,none}.
|
||||||
|
{a_email,[]}.
|
||||||
|
{c_email,[]}.
|
||||||
|
{copyright,"QPQ AG"}.
|
||||||
|
{file_exts,[]}.
|
||||||
|
{license,skip}.
|
||||||
|
{repo_url,"https://git.qpq.swiss/QPQ-AG/gmserialization"}.
|
||||||
|
{tags,["blockchain","crypto","gm", "gajumaru"]}.
|
||||||
|
{ws_url,[]}.
|
||||||
Reference in New Issue
Block a user