Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b4acaac6e | |||
| c2ccd39c39 | |||
| 1229471ce0 | |||
| fc5c9f2d3d | |||
| 67fc399b31 | |||
| ed8c08bf62 | |||
| 3421d3dca3 | |||
| 0e5ac7f68f | |||
| c5a968cca3 | |||
| dc460ddd75 | |||
| 23856166fd | |||
| 82f10b76c5 | |||
| cd6f7b5751 | |||
| 9d2ecc00d3 | |||
| 356d86cd72 | |||
| f3da241917 | |||
| 2db9ea6134 | |||
| 4b5cfcb67a | |||
| d5eb3ad0fb | |||
| d28e63693c | |||
| f4999b6c2f | |||
| b5929e4d2e | |||
| 664f1f0c44 | |||
| 9cb67eeb98 | |||
| 7457d027fd | |||
| c31bcac249 | |||
| c0bf7b5b74 | |||
| 5139f130f5 | |||
| 8336d8113c | |||
| db7a9f62f2 | |||
| 8346df41f2 | |||
| 2488ff3978 | |||
| da8308821c | |||
| 213589ad9f | |||
| 270ebecc57 | |||
| 893ebb69f6 | |||
| 05c4f87619 | |||
| 91d6159ebd | |||
| 177bf604b2 | |||
| 95d248aa0c | |||
| 0f9dbe9f52 | |||
| eb68fe331b |
@@ -1,37 +0,0 @@
|
||||
version: 2.1
|
||||
|
||||
executors:
|
||||
aebuilder:
|
||||
docker:
|
||||
- image: aeternity/builder
|
||||
user: builder
|
||||
working_directory: ~/src
|
||||
|
||||
jobs:
|
||||
build:
|
||||
executor: aebuilder
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
keys:
|
||||
- dialyzer-cache-v1-{{ .Branch }}-{{ .Revision }}
|
||||
- dialyzer-cache-v1-{{ .Branch }}-
|
||||
- dialyzer-cache-v1-
|
||||
- run:
|
||||
name: Build
|
||||
command: rebar3 compile
|
||||
- run:
|
||||
name: Static Analysis
|
||||
command: rebar3 dialyzer
|
||||
- run:
|
||||
name: Eunit
|
||||
command: rebar3 eunit
|
||||
- run:
|
||||
name: Common Tests
|
||||
command: rebar3 ct
|
||||
- save_cache:
|
||||
key: dialyzer-cache-v1-{{ .Branch }}-{{ .Revision }}
|
||||
paths:
|
||||
- _build/default/rebar3_20.3.8_plt
|
||||
- store_artifacts:
|
||||
path: _build/test/logs
|
||||
@@ -0,0 +1,14 @@
|
||||
name: Gajumaru Serialization Tests
|
||||
run-name: ${{ gitea.actor }} testing Gajumaru Serialization
|
||||
on: [push, workflow_dispatch]
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: linux_amd64
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
- name: eunit
|
||||
run: |
|
||||
. /home/act_runner/.erts/27.2.1/activate
|
||||
./rebar3 eunit
|
||||
+1
-1
@@ -7,7 +7,7 @@ _*
|
||||
*.swp
|
||||
*.swo
|
||||
.erlang.cookie
|
||||
ebin
|
||||
ebin/*.beam
|
||||
log
|
||||
erl_crash.dump
|
||||
.rebar
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2025, QPQ AG
|
||||
Copyright (c) 2017, aeternity developers
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
aeserialization
|
||||
GM Serialization
|
||||
=====
|
||||
|
||||
Serialization helpers for Aeternity node.
|
||||
Serialization helpers for the Gajumaru.
|
||||
|
||||
Build
|
||||
-----
|
||||
|
||||
$ rebar3 compile
|
||||
|
||||
|
||||
Test
|
||||
----
|
||||
|
||||
$ rebar3 eunit
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{application,gmserialization,
|
||||
[{description,"Serialization helpers for the Gajumaru."},
|
||||
{vsn,"0.1.2"},
|
||||
{registered,[]},
|
||||
{applications,[kernel,stdlib,crypto,base58]},
|
||||
{env,[]},
|
||||
{modules,[base58,timing,enacl_eqc,enacl_ext_eqc,enacl,enacl_ext,
|
||||
enacl_nif,enacl_SUITE,pc,pc_compilation,pc_port_env,
|
||||
pc_port_specs,pc_prv_clean,pc_prv_compile,pc_util,
|
||||
base58,timing,enacl_eqc,enacl_ext_eqc,enacl,enacl_ext,
|
||||
enacl_nif,enacl_SUITE,gmser_api_encoder,
|
||||
gmser_chain_objects,gmser_contract_code,
|
||||
gmser_delegation,gmser_id,gmser_rlp,gmserialization,
|
||||
gmser_api_encoder_tests,gmser_chain_objects_tests,
|
||||
gmser_contract_code_tests,gmser_delegation_tests,
|
||||
gmser_rlp_tests,pc,pc_compilation,pc_port_env,
|
||||
pc_port_specs,pc_prv_clean,pc_prv_compile,pc_util,
|
||||
gmser_api_encoder,gmser_chain_objects,
|
||||
gmser_contract_code,gmser_delegation,gmser_id,
|
||||
gmser_rlp,gmserialization,gmser_api_encoder_tests,
|
||||
gmser_chain_objects_tests,gmser_contract_code_tests,
|
||||
gmser_delegation_tests,gmser_rlp_tests]},
|
||||
{licenses,[]},
|
||||
{links,[]}]}.
|
||||
+6
-3
@@ -1,4 +1,7 @@
|
||||
{erl_opts, [debug_info]}.
|
||||
{deps, [ {base58, {git, "https://github.com/aeternity/erl-base58.git", {ref, "60a3356"}}}
|
||||
, {enacl, {git, "https://github.com/aeternity/enacl.git", {ref, "793ddb5"}}}
|
||||
]}.
|
||||
{deps,
|
||||
[{base58,
|
||||
{git,
|
||||
"https://git.qpq.swiss/QPQ-AG/erl-base58.git",
|
||||
{ref, "e6aa62eeae3d4388311401f06e4b939bf4e94b9c"}}},
|
||||
{eblake2, "1.0.0"}]}.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[{<<"base58">>,
|
||||
{git,"https://git.qpq.swiss/QPQ-AG/erl-base58.git",
|
||||
{ref,"e6aa62eeae3d4388311401f06e4b939bf4e94b9c"}},
|
||||
0},
|
||||
{<<"eblake2">>,
|
||||
{pkg,<<"eblake2">>,<<"1.0.0">>},0}].
|
||||
@@ -1,10 +1,12 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% API encoding for the Aeternity node.
|
||||
%%% API encoding for the Gajumaru
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(aeser_api_encoder).
|
||||
-module(gmser_api_encoder).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-export([encode/2,
|
||||
decode/1,
|
||||
@@ -18,26 +20,29 @@
|
||||
| block_pof_hash
|
||||
| block_tx_hash
|
||||
| block_state_hash
|
||||
| block_witness_hash
|
||||
| channel
|
||||
| contract_bytearray
|
||||
| contract_pubkey
|
||||
| contract_store_key
|
||||
| contract_store_value
|
||||
| contract_source
|
||||
| transaction
|
||||
| tx_hash
|
||||
| oracle_pubkey
|
||||
| oracle_query
|
||||
| oracle_query_id
|
||||
| oracle_response
|
||||
| account_pubkey
|
||||
| account_seckey
|
||||
| associate_chain
|
||||
| entry
|
||||
| signature
|
||||
| name
|
||||
| native_token
|
||||
| commitment
|
||||
| peer_pubkey
|
||||
| state
|
||||
| poi
|
||||
| state_trees
|
||||
| call_state_tree
|
||||
| mp_tree_hash
|
||||
| bytearray.
|
||||
|
||||
-type extended_type() :: known_type() | block_hash | {id_hash, [known_type()]}.
|
||||
@@ -49,9 +54,9 @@
|
||||
-define(BASE58, 1).
|
||||
-define(BASE64, 2).
|
||||
|
||||
-spec encode(known_type(), payload() | aeser_id:id()) -> encoded().
|
||||
-spec encode(known_type(), payload() | gmser_id:id()) -> encoded().
|
||||
encode(id_hash, Payload) ->
|
||||
{IdType, Val} = aeser_id:specialize(Payload),
|
||||
{IdType, Val} = gmser_id:specialize(Payload),
|
||||
encode(id2type(IdType), Val);
|
||||
encode(Type, Payload) ->
|
||||
Pfx = type2pfx(Type),
|
||||
@@ -87,14 +92,14 @@ type_size_check(Type, Bin) ->
|
||||
end
|
||||
end.
|
||||
|
||||
-spec safe_decode(extended_type(), encoded()) -> {'ok', payload() | aeser_id:id()}
|
||||
-spec safe_decode(extended_type(), encoded()) -> {'ok', payload() | gmser_id:id()}
|
||||
| {'error', atom()}.
|
||||
safe_decode({id_hash, AllowedTypes}, Enc) ->
|
||||
try decode(Enc) of
|
||||
{ActualType, Dec} ->
|
||||
case lists:member(ActualType, AllowedTypes) of
|
||||
true ->
|
||||
try {ok, aeser_id:create(type2id(ActualType), Dec)}
|
||||
try {ok, gmser_id:create(type2id(ActualType), Dec)}
|
||||
catch error:_ -> {error, invalid_prefix}
|
||||
end;
|
||||
false ->
|
||||
@@ -160,45 +165,55 @@ 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(contract_source) -> contract_source;
|
||||
id2type(name) -> name;
|
||||
id2type(native_token) -> native_token;
|
||||
id2type(entry) -> entry.
|
||||
|
||||
type2id(account_pubkey) -> account;
|
||||
type2id(associate_chain) -> associate_chain;
|
||||
type2id(channel) -> channel;
|
||||
type2id(commitment) -> commitment;
|
||||
type2id(contract_pubkey) -> contract;
|
||||
type2id(contract_source) -> contract_source;
|
||||
type2id(name) -> name;
|
||||
type2id(oracle_pubkey) -> oracle.
|
||||
type2id(native_token) -> native_token;
|
||||
type2id(entry) -> entry.
|
||||
|
||||
type2enc(key_block_hash) -> ?BASE58;
|
||||
type2enc(micro_block_hash) -> ?BASE58;
|
||||
type2enc(block_pof_hash) -> ?BASE58;
|
||||
type2enc(block_tx_hash) -> ?BASE58;
|
||||
type2enc(block_state_hash) -> ?BASE58;
|
||||
type2enc(block_witness_hash) -> ?BASE58;
|
||||
type2enc(channel) -> ?BASE58;
|
||||
type2enc(contract_pubkey) -> ?BASE58;
|
||||
type2enc(contract_bytearray) -> ?BASE64;
|
||||
type2enc(contract_store_key) -> ?BASE64;
|
||||
type2enc(contract_store_value) -> ?BASE64;
|
||||
type2enc(contract_source) -> ?BASE64;
|
||||
type2enc(transaction) -> ?BASE64;
|
||||
type2enc(tx_hash) -> ?BASE58;
|
||||
type2enc(oracle_pubkey) -> ?BASE58;
|
||||
type2enc(oracle_query) -> ?BASE64;
|
||||
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;
|
||||
type2enc(name) -> ?BASE58;
|
||||
type2enc(native_token) -> ?BASE58;
|
||||
type2enc(state) -> ?BASE64;
|
||||
type2enc(poi) -> ?BASE64;
|
||||
type2enc(state_trees) -> ?BASE64;
|
||||
type2enc(call_state_tree) -> ?BASE64;
|
||||
type2enc(mp_tree_hash) -> ?BASE58;
|
||||
type2enc(hash) -> ?BASE58;
|
||||
type2enc(entry) -> ?BASE64;
|
||||
type2enc(bytearray) -> ?BASE64.
|
||||
|
||||
|
||||
@@ -207,26 +222,30 @@ type2pfx(micro_block_hash) -> <<"mh">>;
|
||||
type2pfx(block_pof_hash) -> <<"bf">>;
|
||||
type2pfx(block_tx_hash) -> <<"bx">>;
|
||||
type2pfx(block_state_hash) -> <<"bs">>;
|
||||
type2pfx(block_witness_hash) -> <<"ws">>;
|
||||
type2pfx(channel) -> <<"ch">>;
|
||||
type2pfx(contract_pubkey) -> <<"ct">>;
|
||||
type2pfx(contract_bytearray) -> <<"cb">>;
|
||||
type2pfx(contract_store_key) -> <<"ck">>;
|
||||
type2pfx(contract_store_value) -> <<"cv">>;
|
||||
type2pfx(contract_source) -> <<"cx">>;
|
||||
type2pfx(transaction) -> <<"tx">>;
|
||||
type2pfx(tx_hash) -> <<"th">>;
|
||||
type2pfx(oracle_pubkey) -> <<"ok">>;
|
||||
type2pfx(oracle_query) -> <<"ov">>;
|
||||
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">>;
|
||||
type2pfx(name) -> <<"nm">>;
|
||||
type2pfx(native_token) -> <<"nt">>;
|
||||
type2pfx(state) -> <<"st">>;
|
||||
type2pfx(poi) -> <<"pi">>;
|
||||
type2pfx(state_trees) -> <<"ss">>;
|
||||
type2pfx(call_state_tree) -> <<"cs">>;
|
||||
type2pfx(mp_tree_hash) -> <<"mt">>;
|
||||
type2pfx(hash) -> <<"hs">>;
|
||||
type2pfx(entry) -> <<"en">>;
|
||||
type2pfx(bytearray) -> <<"ba">>.
|
||||
|
||||
pfx2type(<<"kh">>) -> key_block_hash;
|
||||
@@ -234,26 +253,30 @@ pfx2type(<<"mh">>) -> micro_block_hash;
|
||||
pfx2type(<<"bf">>) -> block_pof_hash;
|
||||
pfx2type(<<"bx">>) -> block_tx_hash;
|
||||
pfx2type(<<"bs">>) -> block_state_hash;
|
||||
pfx2type(<<"ws">>) -> block_witness_hash;
|
||||
pfx2type(<<"ch">>) -> channel;
|
||||
pfx2type(<<"cb">>) -> contract_bytearray;
|
||||
pfx2type(<<"ck">>) -> contract_store_key;
|
||||
pfx2type(<<"cv">>) -> contract_store_value;
|
||||
pfx2type(<<"ct">>) -> contract_pubkey;
|
||||
pfx2type(<<"cx">>) -> contract_source;
|
||||
pfx2type(<<"tx">>) -> transaction;
|
||||
pfx2type(<<"th">>) -> tx_hash;
|
||||
pfx2type(<<"ok">>) -> oracle_pubkey;
|
||||
pfx2type(<<"ov">>) -> oracle_query;
|
||||
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;
|
||||
pfx2type(<<"nm">>) -> name;
|
||||
pfx2type(<<"nt">>) -> native_token;
|
||||
pfx2type(<<"st">>) -> state;
|
||||
pfx2type(<<"pi">>) -> poi;
|
||||
pfx2type(<<"ss">>) -> state_trees;
|
||||
pfx2type(<<"cs">>) -> call_state_tree;
|
||||
pfx2type(<<"mt">>) -> mp_tree_hash;
|
||||
pfx2type(<<"hs">>) -> hash;
|
||||
pfx2type(<<"en">>) -> entry;
|
||||
pfx2type(<<"ba">>) -> bytearray.
|
||||
|
||||
-spec byte_size_for_type(known_type()) -> non_neg_integer() | not_applicable.
|
||||
@@ -263,26 +286,30 @@ byte_size_for_type(micro_block_hash) -> 32;
|
||||
byte_size_for_type(block_pof_hash) -> 32;
|
||||
byte_size_for_type(block_tx_hash) -> 32;
|
||||
byte_size_for_type(block_state_hash) -> 32;
|
||||
byte_size_for_type(block_witness_hash) -> 32;
|
||||
byte_size_for_type(channel) -> 32;
|
||||
byte_size_for_type(contract_pubkey) -> 32;
|
||||
byte_size_for_type(contract_bytearray) -> not_applicable;
|
||||
byte_size_for_type(contract_store_key) -> not_applicable;
|
||||
byte_size_for_type(contract_store_value) -> not_applicable;
|
||||
byte_size_for_type(contract_source) -> not_applicable;
|
||||
byte_size_for_type(transaction) -> not_applicable;
|
||||
byte_size_for_type(tx_hash) -> 32;
|
||||
byte_size_for_type(oracle_pubkey) -> 32;
|
||||
byte_size_for_type(oracle_query) -> not_applicable;
|
||||
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(native_token) -> 32;
|
||||
byte_size_for_type(commitment) -> 32;
|
||||
byte_size_for_type(peer_pubkey) -> 32;
|
||||
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(hash) -> 32;
|
||||
byte_size_for_type(entry) -> not_applicable;
|
||||
byte_size_for_type(bytearray) -> not_applicable.
|
||||
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Functions for serializing chain objects to binary format.
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeser_chain_objects).
|
||||
-module(gmser_chain_objects).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-export([ serialize/4
|
||||
, deserialize/4
|
||||
, deserialize_type_and_vsn/1
|
||||
]).
|
||||
|
||||
-type template() :: aeserialization:template().
|
||||
-type fields() :: aeserialization:fields().
|
||||
-type template() :: gmserialization:template().
|
||||
-type fields() :: gmserialization:fields().
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
@@ -22,15 +24,15 @@
|
||||
|
||||
-spec serialize(atom(), non_neg_integer(), template(), fields()) -> binary().
|
||||
serialize(Type, Vsn, Template, Fields) ->
|
||||
aeserialization:serialize(tag(Type), Vsn, Template, Fields).
|
||||
gmserialization:serialize(tag(Type), Vsn, Template, Fields).
|
||||
|
||||
deserialize_type_and_vsn(Binary) ->
|
||||
{Tag, Vsn, Fields} = aeserialization:deserialize_tag_and_vsn(Binary),
|
||||
{Tag, Vsn, Fields} = gmserialization:deserialize_tag_and_vsn(Binary),
|
||||
{rev_tag(Tag), Vsn, Fields}.
|
||||
|
||||
-spec deserialize(atom(), non_neg_integer(), template(), binary()) -> fields().
|
||||
deserialize(Type, Vsn, Template, Binary) ->
|
||||
aeserialization:deserialize(Type, tag(Type), Vsn, Template, Binary).
|
||||
gmserialization:deserialize(Type, tag(Type), Vsn, Template, Binary).
|
||||
|
||||
%%%===================================================================
|
||||
%%% Internal functions
|
||||
@@ -39,12 +41,7 @@ deserialize(Type, Vsn, Template, Binary) ->
|
||||
tag(account) -> 10;
|
||||
tag(signed_tx) -> 11;
|
||||
tag(spend_tx) -> 12;
|
||||
tag(oracle) -> 20;
|
||||
tag(oracle_query) -> 21;
|
||||
tag(oracle_register_tx) -> 22;
|
||||
tag(oracle_query_tx) -> 23;
|
||||
tag(oracle_response_tx) -> 24;
|
||||
tag(oracle_extend_tx) -> 25;
|
||||
tag(data_extend_tx) -> 13;
|
||||
tag(name) -> 30;
|
||||
tag(name_commitment) -> 31;
|
||||
tag(name_claim_tx) -> 32;
|
||||
@@ -57,8 +54,10 @@ tag(contract) -> 40;
|
||||
tag(contract_call) -> 41;
|
||||
tag(contract_create_tx) -> 42;
|
||||
tag(contract_call_tx) -> 43;
|
||||
tag(contract_source) -> 44;
|
||||
tag(channel_create_tx) -> 50;
|
||||
tag(channel_set_delegates_tx) -> 501;
|
||||
tag(channel_delegates) -> 502;
|
||||
tag(channel_deposit_tx) -> 51;
|
||||
tag(channel_withdraw_tx) -> 52;
|
||||
tag(channel_force_progress_tx) -> 521;
|
||||
@@ -85,26 +84,43 @@ tag(contracts_mtree) -> 621;
|
||||
tag(calls_mtree) -> 622;
|
||||
tag(channels_mtree) -> 623;
|
||||
tag(nameservice_mtree) -> 624;
|
||||
tag(oracles_mtree) -> 625;
|
||||
tag(accounts_mtree) -> 626;
|
||||
tag(acs_mtree) -> 627;
|
||||
tag(entries_mtree) -> 628;
|
||||
tag(compiler_sophia) -> 70;
|
||||
tag(ga_attach_tx) -> 80;
|
||||
tag(ga_meta_tx) -> 81;
|
||||
tag(paying_for_tx) -> 82;
|
||||
tag(ga_meta_tx_auth_data) -> 810;
|
||||
tag(associate_chain) -> 90;
|
||||
tag(ac_state) -> 91;
|
||||
tag(ac_burn) -> 92;
|
||||
tag(ac_create_tx) -> 93;
|
||||
tag(ac_deposit_tx) -> 94;
|
||||
tag(ac_update_cops_tx) -> 95;
|
||||
tag(ac_rollup_tx) -> 96;
|
||||
tag(ac_proposal_tx) -> 97;
|
||||
tag(key_block) -> 100;
|
||||
tag(micro_block) -> 101;
|
||||
tag(light_micro_block) -> 102;
|
||||
tag(testimony) -> 110;
|
||||
tag(testimony_tx) -> 111;
|
||||
tag(nt_native_token) -> 120;
|
||||
tag(nt_create_tx) -> 121;
|
||||
tag(nt_mint_tx) -> 122;
|
||||
tag(nt_finalize_tx) -> 123;
|
||||
tag(nt_trade_tx) -> 124;
|
||||
tag(nt_burn_tx) -> 125;
|
||||
tag(entry) -> 140;
|
||||
tag(entry_create_tx) -> 141;
|
||||
tag(entry_transfer_tx) -> 142;
|
||||
tag(entry_destroy_tx) -> 143;
|
||||
tag(pof) -> 200.
|
||||
|
||||
rev_tag(10) -> account;
|
||||
rev_tag(11) -> signed_tx;
|
||||
rev_tag(12) -> spend_tx;
|
||||
rev_tag(20) -> oracle;
|
||||
rev_tag(21) -> oracle_query;
|
||||
rev_tag(22) -> oracle_register_tx;
|
||||
rev_tag(23) -> oracle_query_tx;
|
||||
rev_tag(24) -> oracle_response_tx;
|
||||
rev_tag(25) -> oracle_extend_tx;
|
||||
rev_tag(13) -> data_extend_tx;
|
||||
rev_tag(30) -> name;
|
||||
rev_tag(31) -> name_commitment;
|
||||
rev_tag(32) -> name_claim_tx;
|
||||
@@ -117,8 +133,10 @@ rev_tag(40) -> contract;
|
||||
rev_tag(41) -> contract_call;
|
||||
rev_tag(42) -> contract_create_tx;
|
||||
rev_tag(43) -> contract_call_tx;
|
||||
rev_tag(44) -> contract_source;
|
||||
rev_tag(50) -> channel_create_tx;
|
||||
rev_tag(501) -> channel_set_delegates_tx;
|
||||
rev_tag(502) -> channel_delegates;
|
||||
rev_tag(51) -> channel_deposit_tx;
|
||||
rev_tag(52) -> channel_withdraw_tx;
|
||||
rev_tag(521) -> channel_force_progress_tx;
|
||||
@@ -145,13 +163,35 @@ rev_tag(621) -> contracts_mtree;
|
||||
rev_tag(622) -> calls_mtree;
|
||||
rev_tag(623) -> channels_mtree;
|
||||
rev_tag(624) -> nameservice_mtree;
|
||||
rev_tag(625) -> oracles_mtree;
|
||||
rev_tag(626) -> accounts_mtree;
|
||||
rev_tag(627) -> acs_mtree;
|
||||
rev_tag(628) -> entries_mtree;
|
||||
rev_tag(70) -> compiler_sophia;
|
||||
rev_tag(80) -> ga_attach_tx;
|
||||
rev_tag(81) -> ga_meta_tx;
|
||||
rev_tag(82) -> paying_for_tx;
|
||||
rev_tag(810) -> ga_meta_tx_auth_data;
|
||||
rev_tag(90) -> associate_chain;
|
||||
rev_tag(91) -> ac_state;
|
||||
rev_tag(92) -> ac_burn;
|
||||
rev_tag(93) -> ac_create_tx;
|
||||
rev_tag(94) -> ac_deposit_tx;
|
||||
rev_tag(95) -> ac_update_cops_tx;
|
||||
rev_tag(96) -> ac_rollup_tx;
|
||||
rev_tag(97) -> ac_proposal_tx;
|
||||
rev_tag(100) -> key_block;
|
||||
rev_tag(101) -> micro_block;
|
||||
rev_tag(102) -> light_micro_block;
|
||||
rev_tag(110) -> testimony;
|
||||
rev_tag(111) -> testimony_tx;
|
||||
rev_tag(120) -> nt_native_token;
|
||||
rev_tag(121) -> nt_create_tx;
|
||||
rev_tag(122) -> nt_mint_tx;
|
||||
rev_tag(123) -> nt_finalize_tx;
|
||||
rev_tag(124) -> nt_trade_tx;
|
||||
rev_tag(125) -> nt_burn_tx;
|
||||
rev_tag(140) -> entry;
|
||||
rev_tag(141) -> entry_create_tx;
|
||||
rev_tag(142) -> entry_transfer_tx;
|
||||
rev_tag(143) -> entry_destroy_tx;
|
||||
rev_tag(200) -> pof.
|
||||
@@ -1,12 +1,14 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2019, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Serialization of contract code
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(aeser_contract_code).
|
||||
-module(gmser_contract_code).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-include("aeser_contract_code.hrl").
|
||||
-include("gmser_contract_code.hrl").
|
||||
|
||||
-export([ deserialize/1
|
||||
, serialize/1
|
||||
@@ -16,15 +18,16 @@
|
||||
serialize(CodeMap) ->
|
||||
serialize(CodeMap, ?SOPHIA_CONTRACT_VSN_3).
|
||||
|
||||
|
||||
-spec serialize(map(), non_neg_integer()) -> binary().
|
||||
serialize(CodeMap = #{ byte_code := ByteCode
|
||||
, type_info := TypeInfo }, SophiaContractVersion) ->
|
||||
%% Source hash
|
||||
SourceHash = case CodeMap of
|
||||
#{ source_hash := SHash } -> SHash;
|
||||
#{ contract_source := SrcStr } ->
|
||||
enacl:generichash(32, list_to_binary(SrcStr))
|
||||
end,
|
||||
SourceHash =
|
||||
case CodeMap of
|
||||
#{ source_hash := SHash } -> SHash;
|
||||
#{ contract_source := SrcStr } -> blake2(32, list_to_binary(SrcStr))
|
||||
end,
|
||||
|
||||
%% Compiler version
|
||||
Version = maps:get(compiler_version, CodeMap, <<"unknown">>),
|
||||
@@ -42,20 +45,35 @@ serialize(CodeMap = #{ byte_code := ByteCode
|
||||
|| SophiaContractVersion > ?SOPHIA_CONTRACT_VSN_1 ] ++
|
||||
[ {payable, Payable}
|
||||
|| SophiaContractVersion > ?SOPHIA_CONTRACT_VSN_2 ],
|
||||
aeser_chain_objects:serialize(compiler_sophia,
|
||||
gmser_chain_objects:serialize(compiler_sophia,
|
||||
SophiaContractVersion,
|
||||
serialization_template(SophiaContractVersion),
|
||||
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().
|
||||
deserialize(Binary) ->
|
||||
case aeser_chain_objects:deserialize_type_and_vsn(Binary) of
|
||||
case gmser_chain_objects:deserialize_type_and_vsn(Binary) of
|
||||
{compiler_sophia = Type, ?SOPHIA_CONTRACT_VSN_1 = Vsn, _Rest} ->
|
||||
Template = serialization_template(Vsn),
|
||||
[ {source_hash, Hash}
|
||||
, {type_info, TypeInfo}
|
||||
, {byte_code, ByteCode}
|
||||
] = aeser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||
] = gmser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||
#{ source_hash => Hash
|
||||
, type_info => TypeInfo
|
||||
, byte_code => ByteCode
|
||||
@@ -68,7 +86,7 @@ deserialize(Binary) ->
|
||||
, {type_info, TypeInfo}
|
||||
, {byte_code, ByteCode}
|
||||
, {compiler_version, CompilerVersion}
|
||||
] = aeser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||
] = gmser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||
#{ source_hash => Hash
|
||||
, type_info => TypeInfo
|
||||
, byte_code => ByteCode
|
||||
@@ -83,7 +101,7 @@ deserialize(Binary) ->
|
||||
, {byte_code, ByteCode}
|
||||
, {compiler_version, CompilerVersion}
|
||||
, {payable, Payable}
|
||||
] = aeser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||
] = gmser_chain_objects:deserialize(Type, Vsn, Template, Binary),
|
||||
#{ source_hash => Hash
|
||||
, type_info => TypeInfo
|
||||
, byte_code => ByteCode
|
||||
@@ -0,0 +1,65 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2023, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Serialization of delegation signatures
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(gmser_delegation).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-export([ aens_preclaim_sig/3
|
||||
, aens_name_sig/4
|
||||
, aens_sig/3
|
||||
]).
|
||||
|
||||
%% Delegation signatures are prefixed with a unique tag, ensuring not to
|
||||
%% collide with serialized transactions.
|
||||
-define(DELEGATION_TAG, 16#1a01).
|
||||
|
||||
-define(TYPE_AENS, 1).
|
||||
-define(TYPE_AENS_NAME, 2).
|
||||
-define(TYPE_AENS_PRECLAIM, 3).
|
||||
-define(TYPE_ORACLE, 4).
|
||||
-define(TYPE_ORACLE_RESPONSE, 5).
|
||||
|
||||
-define(VSN, 1).
|
||||
|
||||
-type sig_data() :: binary().
|
||||
|
||||
-spec aens_preclaim_sig(binary(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
||||
aens_preclaim_sig(NetworkId, Account, Contract) ->
|
||||
assert_id(account, Account),
|
||||
assert_id(contract, Contract),
|
||||
Template = [{account, id}, {contract, id}],
|
||||
Fields = [{account, Account}, {contract, Contract}],
|
||||
serialize(?TYPE_AENS_PRECLAIM, NetworkId, Template, Fields).
|
||||
|
||||
-spec aens_name_sig(binary(), gmser_id:id(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
||||
aens_name_sig(NetworkId, Account, Name, Contract) ->
|
||||
assert_id(account, Account),
|
||||
assert_id(name, Name),
|
||||
assert_id(contract, Contract),
|
||||
Template = [{account, id}, {name, id}, {contract, id}],
|
||||
Fields = [{account, Account}, {name, Name}, {contract, Contract}],
|
||||
serialize(?TYPE_AENS_NAME, NetworkId, Template, Fields).
|
||||
|
||||
-spec aens_sig(binary(), gmser_id:id(), gmser_id:id()) -> sig_data().
|
||||
aens_sig(NetworkId, Account, Contract) ->
|
||||
assert_id(account, Account),
|
||||
assert_id(contract, Contract),
|
||||
Template = [{account, id}, {contract, id}],
|
||||
Fields = [{account, Account}, {contract, Contract}],
|
||||
serialize(?TYPE_AENS, NetworkId, Template, Fields).
|
||||
|
||||
|
||||
%% ------------------------------------------------------------------------
|
||||
%% -- Internal functions
|
||||
%% ------------------------------------------------------------------------
|
||||
|
||||
serialize(Type, NetworkId, Template, Fields) ->
|
||||
Data = gmserialization:serialize(Type, ?VSN, Template, Fields),
|
||||
<<?DELEGATION_TAG:16, NetworkId/binary, Data/binary>>.
|
||||
|
||||
assert_id(Type, AeserId) ->
|
||||
Type = gmser_id:specialize_type(AeserId).
|
||||
@@ -1,12 +1,14 @@
|
||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% ADT for identifiers
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeser_id).
|
||||
-module(gmser_id).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-export([ create/2
|
||||
, specialize/1
|
||||
@@ -24,8 +26,9 @@
|
||||
, val
|
||||
}).
|
||||
|
||||
-type tag() :: 'account' | 'oracle' | 'name'
|
||||
| 'commitment' | 'contract' | 'channel'.
|
||||
-type tag() :: 'account' | 'name'
|
||||
| 'commitment' | 'contract' | 'channel'
|
||||
| 'associate_chain' | 'entry' .
|
||||
-type val() :: <<_:256>>.
|
||||
-opaque(id() :: #id{}).
|
||||
|
||||
@@ -39,11 +42,12 @@
|
||||
-define(SERIALIZED_SIZE, 33). %% ?TAG_SIZE + ?PUB_SIZE
|
||||
|
||||
-define(IS_TAG(___TAG___), ___TAG___ =:= account;
|
||||
___TAG___ =:= oracle;
|
||||
___TAG___ =:= name;
|
||||
___TAG___ =:= commitment;
|
||||
___TAG___ =:= contract;
|
||||
___TAG___ =:= channel
|
||||
___TAG___ =:= channel;
|
||||
___TAG___ =:= associate_chain;
|
||||
___TAG___ =:= entry
|
||||
).
|
||||
-define(IS_VAL(___VAL___), byte_size(___VAL___) =:= 32).
|
||||
|
||||
@@ -94,18 +98,22 @@ decode(<<Tag:?TAG_SIZE/unit:8, Val:?PUB_SIZE/binary>>) ->
|
||||
%%% 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(contract) -> 5;
|
||||
encode_tag(channel) -> 6;
|
||||
encode_tag(associate_chain) -> 7;
|
||||
encode_tag(native_token) -> 8;
|
||||
encode_tag(entry) -> 9;
|
||||
encode_tag(Other) -> error({illegal_id_tag_name, Other}).
|
||||
|
||||
decode_tag(1) -> account;
|
||||
decode_tag(2) -> name;
|
||||
decode_tag(3) -> commitment;
|
||||
decode_tag(4) -> oracle;
|
||||
decode_tag(5) -> contract;
|
||||
decode_tag(6) -> channel;
|
||||
decode_tag(7) -> associate_chain;
|
||||
decode_tag(8) -> native_token;
|
||||
decode_tag(9) -> entry;
|
||||
decode_tag(X) -> error({illegal_id_tag, X}).
|
||||
@@ -1,14 +1,18 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Implementation of the Recursive Length Prefix.
|
||||
%%%
|
||||
%%% https://zxq9.com/archives/2749
|
||||
%%% https://github.com/ethereum/wiki/wiki/RLP
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeser_rlp).
|
||||
-module(gmser_rlp).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-export([ decode/1
|
||||
, decode_one/1
|
||||
, encode/1
|
||||
@@ -1,5 +1,5 @@
|
||||
{application, aeserialization,
|
||||
[{description, "Serialization of data for Aeternity"},
|
||||
{application, gmserialization,
|
||||
[{description, "Serialization of data for the Gajumaru"},
|
||||
{vsn, "0.1.0"},
|
||||
{registered, []},
|
||||
{applications,
|
||||
@@ -1,11 +1,13 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Functions for serializing generic objects to/from binary format.
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeserialization).
|
||||
-module(gmserialization).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-export([ decode_fields/2
|
||||
, deserialize/5
|
||||
@@ -28,14 +30,16 @@
|
||||
| 'binary'
|
||||
| 'id' %% As defined in aec_id.erl
|
||||
| [type()] %% Length one in the type. This means a list of any length.
|
||||
| #{items := [{field_name(), type()}]} %% Record with named fields represented as a map. Encoded as a list in the given order.
|
||||
| tuple(). %% Any arity, containing type(). This means a static size array.
|
||||
|
||||
-type encodable_term() :: non_neg_integer()
|
||||
| binary()
|
||||
| boolean()
|
||||
| [encodable_term()] %% Of any length
|
||||
| #{atom() => encodable_term()}
|
||||
| tuple() %% Any arity, containing encodable_term().
|
||||
| aeser_id:id().
|
||||
| gmser_id:id().
|
||||
|
||||
-type fields() :: [{field_name(), encodable_term()}].
|
||||
|
||||
@@ -47,13 +51,13 @@
|
||||
serialize(Tag, Vsn, Template, Fields) ->
|
||||
List = encode_fields([{tag, int}, {vsn, int}|Template],
|
||||
[{tag, Tag}, {vsn, Vsn}|Fields]),
|
||||
aeser_rlp:encode(List).
|
||||
gmser_rlp:encode(List).
|
||||
|
||||
%% Type isn't strictly necessary, but will give a better error reason
|
||||
-spec deserialize(atom(), non_neg_integer(), non_neg_integer(),
|
||||
template(), binary()) -> fields().
|
||||
deserialize(Type, Tag, Vsn, Template0, Binary) ->
|
||||
Decoded = aeser_rlp:decode(Binary),
|
||||
Decoded = gmser_rlp:decode(Binary),
|
||||
Template = [{tag, int}, {vsn, int}|Template0],
|
||||
case decode_fields(Template, Decoded) of
|
||||
[{tag, Tag}, {vsn, Vsn}|Left] ->
|
||||
@@ -66,7 +70,7 @@ deserialize(Type, Tag, Vsn, Template0, Binary) ->
|
||||
-spec deserialize_tag_and_vsn(binary()) ->
|
||||
{non_neg_integer(), non_neg_integer(), fields()}.
|
||||
deserialize_tag_and_vsn(Binary) ->
|
||||
[TagBin, VsnBin|Fields] = aeser_rlp:decode(Binary),
|
||||
[TagBin, VsnBin|Fields] = gmser_rlp:decode(Binary),
|
||||
Template = [{tag, int}, {vsn, int}],
|
||||
[{tag, Tag}, {vsn, Vsn}] = decode_fields(Template, [TagBin, VsnBin]),
|
||||
{Tag, Vsn, Fields}.
|
||||
@@ -101,6 +105,12 @@ decode_fields(Template, Values) ->
|
||||
|
||||
encode_field([Type], L) when is_list(L) ->
|
||||
[encode_field(Type, X) || X <- L];
|
||||
encode_field(#{items := Items}, Map) ->
|
||||
lists:map(
|
||||
fun({K, Type}) ->
|
||||
V = maps:get(K, Map),
|
||||
encode_field(Type, V)
|
||||
end, Items);
|
||||
encode_field(Type, T) when tuple_size(Type) =:= tuple_size(T) ->
|
||||
Zipped = lists:zip(tuple_to_list(Type), tuple_to_list(T)),
|
||||
[encode_field(X, Y) || {X, Y} <- Zipped];
|
||||
@@ -110,13 +120,20 @@ encode_field(binary, X) when is_binary(X) -> X;
|
||||
encode_field(bool, true) -> <<1:8>>;
|
||||
encode_field(bool, false) -> <<0:8>>;
|
||||
encode_field(id, Val) ->
|
||||
try aeser_id:encode(Val)
|
||||
try gmser_id:encode(Val)
|
||||
catch _:_ -> error({illegal, id, Val})
|
||||
end;
|
||||
encode_field(Type, Val) -> error({illegal, Type, Val}).
|
||||
|
||||
decode_field([Type], List) when is_list(List) ->
|
||||
[decode_field(Type, X) || X <- List];
|
||||
decode_field(#{items := Items}, List) when length(List) =:= length(Items) ->
|
||||
Zipped = lists:zip(Items, List),
|
||||
lists:foldl(
|
||||
fun({{K, Type}, V}, Map) ->
|
||||
maps:is_key(K, Map) andalso error(badarg, duplicate_field),
|
||||
Map#{ K => decode_field(Type, V) }
|
||||
end, #{}, Zipped);
|
||||
decode_field(Type, List) when length(List) =:= tuple_size(Type) ->
|
||||
Zipped = lists:zip(tuple_to_list(Type), List),
|
||||
list_to_tuple([decode_field(X, Y) || {X, Y} <- Zipped]);
|
||||
@@ -127,7 +144,7 @@ decode_field(binary, X) when is_binary(X) -> X;
|
||||
decode_field(bool, <<1:8>>) -> true;
|
||||
decode_field(bool, <<0:8>>) -> false;
|
||||
decode_field(id, Val) ->
|
||||
try aeser_id:decode(Val)
|
||||
try gmser_id:decode(Val)
|
||||
catch _:_ -> error({illegal, id, Val})
|
||||
end;
|
||||
decode_field(Type, X) -> error({illegal, Type, X}).
|
||||
@@ -1,12 +1,13 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeser_api_encoder_tests).
|
||||
-module(gmser_api_encoder_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(TEST_MODULE, aeser_api_encoder).
|
||||
-define(TEST_MODULE, gmser_api_encoder).
|
||||
-define(TYPES, [ {key_block_hash , 32}
|
||||
, {micro_block_hash , 32}
|
||||
, {block_tx_hash , 32}
|
||||
@@ -15,11 +16,10 @@
|
||||
, {contract_pubkey , 32}
|
||||
, {transaction , not_applicable}
|
||||
, {tx_hash , 32}
|
||||
, {oracle_pubkey , 32}
|
||||
, {oracle_query_id , 32}
|
||||
, {account_pubkey , 32}
|
||||
, {signature , 64}
|
||||
, {name , not_applicable}
|
||||
, {native_token , 32}
|
||||
, {commitment , 32}
|
||||
, {peer_pubkey , 32}
|
||||
, {state , 32}
|
||||
@@ -1,11 +1,12 @@
|
||||
%%% -*- erlang-indent-level:4; indent-tabs-mode: nil -*-
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2018, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% EUnit tests for aeser_chain_objects
|
||||
%%% EUnit tests for gmser_chain_objects
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(aeser_chain_objects_tests).
|
||||
-module(gmser_chain_objects_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
@@ -78,10 +79,10 @@ deserialize(Template, Bin) ->
|
||||
deserialize(Template, Bin, ?DEFAULT_TAG, ?DEFAULT_VERSION).
|
||||
|
||||
deserialize(Template, Bin, Tag, Vsn) ->
|
||||
aeser_chain_objects:deserialize(Tag, Vsn, Template, Bin).
|
||||
gmser_chain_objects:deserialize(Tag, Vsn, Template, Bin).
|
||||
|
||||
serialize(Template, Bin) ->
|
||||
serialize(Template, Bin, ?DEFAULT_TAG, ?DEFAULT_VERSION).
|
||||
|
||||
serialize(Template, Bin, Tag, Vsn) ->
|
||||
aeser_chain_objects:serialize(Tag, Vsn, Template, Bin).
|
||||
gmser_chain_objects:serialize(Tag, Vsn, Template, Bin).
|
||||
@@ -1,7 +1,11 @@
|
||||
-module(aeser_contract_code_tests).
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(gmser_contract_code_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include("aeser_contract_code.hrl").
|
||||
-include("gmser_contract_code.hrl").
|
||||
|
||||
-define(DUMMY_CODE_MAP_1,
|
||||
#{ byte_code => <<"DUMMY CODE">>
|
||||
@@ -22,14 +26,14 @@
|
||||
, payable => true} ).
|
||||
|
||||
vsn_1_test() ->
|
||||
aeser_contract_code:deserialize(
|
||||
aeser_contract_code:serialize(?DUMMY_CODE_MAP_1, ?SOPHIA_CONTRACT_VSN_1)).
|
||||
gmser_contract_code:deserialize(
|
||||
gmser_contract_code:serialize(?DUMMY_CODE_MAP_1, ?SOPHIA_CONTRACT_VSN_1)).
|
||||
|
||||
vsn_2_test() ->
|
||||
aeser_contract_code:deserialize(
|
||||
aeser_contract_code:serialize(?DUMMY_CODE_MAP_2, ?SOPHIA_CONTRACT_VSN_2)).
|
||||
gmser_contract_code:deserialize(
|
||||
gmser_contract_code:serialize(?DUMMY_CODE_MAP_2, ?SOPHIA_CONTRACT_VSN_2)).
|
||||
|
||||
vsn_3_test() ->
|
||||
aeser_contract_code:deserialize(
|
||||
aeser_contract_code:serialize(?DUMMY_CODE_MAP_3, ?SOPHIA_CONTRACT_VSN_3)).
|
||||
gmser_contract_code:deserialize(
|
||||
gmser_contract_code:serialize(?DUMMY_CODE_MAP_3, ?SOPHIA_CONTRACT_VSN_3)).
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2023, Aeternity Anstalt
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(gmser_delegation_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(TEST_MODULE, gmser_delegation).
|
||||
|
||||
-define(ACCOUNT, gmser_id:create(account, <<1:256>>)).
|
||||
-define(CONTRACT, gmser_id:create(contract, <<2:256>>)).
|
||||
-define(NAME, gmser_id:create(name, <<3:256>>)).
|
||||
|
||||
-define(NETWORK_ID, <<"my_fancy_network"/utf8>>).
|
||||
|
||||
encode_correct_test_() ->
|
||||
[{"Encode preclaim sig",
|
||||
fun() ->
|
||||
gmser_delegation:aens_preclaim_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
||||
end},
|
||||
{"Encode name sig",
|
||||
fun() ->
|
||||
gmser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, ?NAME, ?CONTRACT)
|
||||
end},
|
||||
{"Encode aens wildcard sig",
|
||||
fun() ->
|
||||
gmser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
||||
end}
|
||||
].
|
||||
|
||||
encode_fail_test_() ->
|
||||
[{"Bad encoding preclaim sig",
|
||||
fun() ->
|
||||
?assertError(_, gmser_delegation:aens_preclaim_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)),
|
||||
?assertError(_, gmser_delegation:aens_preclaim_sig(?NETWORK_ID, ?CONTRACT, ?ACCOUNT))
|
||||
end},
|
||||
{"Bad encoding name sig",
|
||||
fun() ->
|
||||
?assertError(_, gmser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>, ?CONTRACT)),
|
||||
?assertError(_, gmser_delegation:aens_name_sig(?NETWORK_ID, ?NAME, ?ACCOUNT, ?CONTRACT))
|
||||
end},
|
||||
{"Bad encoding aens wildcard sig",
|
||||
fun() ->
|
||||
?assertError(_, gmser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>)),
|
||||
?assertError(_, gmser_delegation:aens_sig(?NETWORK_ID, ?CONTRACT, ?CONTRACT))
|
||||
end}
|
||||
].
|
||||
@@ -1,10 +1,11 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2017, Aeternity Anstalt
|
||||
%%% @doc Tests for Recursive Length Prefix
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeser_rlp_tests).
|
||||
-module(gmser_rlp_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
@@ -13,7 +14,7 @@
|
||||
-define(BYTE_ARRAY_OFFSET , 128).
|
||||
-define(LIST_OFFSET , 192).
|
||||
|
||||
-define(TEST_MODULE, aeser_rlp).
|
||||
-define(TEST_MODULE, gmser_rlp).
|
||||
|
||||
rlp_one_byte_test() ->
|
||||
B = <<42>>,
|
||||
@@ -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","eblake2",{1,0,1}},{"otpr","base58",{0,1,1}}]}.
|
||||
{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