Package for zomp
This commit is contained in:
parent
177bf604b2
commit
9124228ff4
1
Emakefile
Normal file
1
Emakefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"src/*", [debug_info, {i, "include/"}, {outdir, "ebin/"}]}.
|
@ -16,14 +16,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
|
||||||
@ -47,6 +48,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 aeser_chain_objects:deserialize_type_and_vsn(Binary) of
|
case aeser_chain_objects:deserialize_type_and_vsn(Binary) of
|
||||||
|
17
zomp.meta
Normal file
17
zomp.meta
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{a_email,[]}.
|
||||||
|
{author,"Hans Svensson"}.
|
||||||
|
{c_email,[]}.
|
||||||
|
{copyright,"Hans Svensson"}.
|
||||||
|
{deps,[{"otpr","eblake2",{1,0,0}}]}.
|
||||||
|
{desc,"Serialization helpers for Aeternity node."}.
|
||||||
|
{file_exts,[]}.
|
||||||
|
{key_name,none}.
|
||||||
|
{license,skip}.
|
||||||
|
{modules,[]}.
|
||||||
|
{name,"AE Serialization"}.
|
||||||
|
{package_id,{"otpr","aeserialization",{0,1,0}}}.
|
||||||
|
{prefix,none}.
|
||||||
|
{repo_url,"https://github.com/aeternity/aeserialization"}.
|
||||||
|
{tags,["blockchain","crypto","ae"]}.
|
||||||
|
{type,lib}.
|
||||||
|
{ws_url,[]}.
|
Loading…
x
Reference in New Issue
Block a user