Merge branch 'master' into zomp
All checks were successful
Gajumaru Serialization Tests / tests (push) Successful in -4m22s
All checks were successful
Gajumaru Serialization Tests / tests (push) Successful in -4m22s
This commit is contained in:
commit
6fae7b4119
@ -1,37 +0,0 @@
|
||||
version: 2.1
|
||||
|
||||
executors:
|
||||
aebuilder:
|
||||
docker:
|
||||
- image: aeternity/builder:bionic-otp23
|
||||
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
|
14
.gitea/workflows/test.yaml
Normal file
14
.gitea/workflows/test.yaml
Normal file
@ -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@v3
|
||||
- name: eunit
|
||||
run: |
|
||||
. /opt/act_runner/erts/27.2/activate
|
||||
./rebar3 eunit
|
1
LICENSE
1
LICENSE
@ -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
|
||||
|
10
README.md
10
README.md
@ -1,9 +1,15 @@
|
||||
aeserialization
|
||||
GM Serialization
|
||||
=====
|
||||
|
||||
Serialization helpers for Aeternity node.
|
||||
Serialization helpers for the Gajumaru.
|
||||
|
||||
Build
|
||||
-----
|
||||
|
||||
$ rebar3 compile
|
||||
|
||||
|
||||
Test
|
||||
----
|
||||
|
||||
$ rebar3 eunit
|
||||
|
@ -1,4 +1,4 @@
|
||||
{erl_opts, [debug_info]}.
|
||||
{deps, [ {base58, {git, "https://github.com/aeternity/erl-base58.git", {ref, "60a3356"}}}
|
||||
, {enacl, {git, "https://gitlab.com/ioecs/enacl.git", {ref, "4eb7ec70"}}}
|
||||
{deps, [ {base58, {git, "https://git.qpq.swiss/QPQ-AG/erl-base58.git", {ref, "b6c41ff2f86f679675b95a780bfc6475e973d796"}}}
|
||||
, {enacl, {git, "https://git.qpq.swiss/QPQ-AG/enacl.git", {ref, "4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}}}
|
||||
]}.
|
||||
|
@ -1,8 +1,8 @@
|
||||
[{<<"base58">>,
|
||||
{git,"https://github.com/aeternity/erl-base58.git",
|
||||
{ref,"60a335668a60328a29f9731b67c4a0e9e3d50ab6"}},
|
||||
{git,"https://git.qpq.swiss/QPQ-AG/erl-base58.git",
|
||||
{ref,"b6c41ff2f86f679675b95a780bfc6475e973d796"}},
|
||||
0},
|
||||
{<<"enacl">>,
|
||||
{git,"https://gitlab.com/ioecs/enacl.git",
|
||||
{git,"https://git.qpq.swiss/QPQ-AG/enacl.git",
|
||||
{ref,"4eb7ec70084ba7c87b1af8797c4c4e90c84f95a2"}},
|
||||
0}].
|
||||
|
@ -1,10 +1,11 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @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,
|
||||
@ -28,10 +29,6 @@
|
||||
| contract_source
|
||||
| transaction
|
||||
| tx_hash
|
||||
| oracle_pubkey
|
||||
| oracle_query
|
||||
| oracle_query_id
|
||||
| oracle_response
|
||||
| account_pubkey
|
||||
| account_seckey
|
||||
| associate_chain
|
||||
@ -57,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),
|
||||
@ -95,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 ->
|
||||
@ -176,8 +173,7 @@ id2type(contract) -> contract_pubkey;
|
||||
id2type(contract_source) -> contract_source;
|
||||
id2type(name) -> name;
|
||||
id2type(native_token) -> native_token;
|
||||
id2type(entry) -> entry;
|
||||
id2type(oracle) -> oracle_pubkey.
|
||||
id2type(entry) -> entry.
|
||||
|
||||
type2id(account_pubkey) -> account;
|
||||
type2id(associate_chain) -> associate_chain;
|
||||
@ -187,8 +183,7 @@ type2id(contract_pubkey) -> contract;
|
||||
type2id(contract_source) -> contract_source;
|
||||
type2id(name) -> name;
|
||||
type2id(native_token) -> native_token;
|
||||
type2id(entry) -> entry;
|
||||
type2id(oracle_pubkey) -> oracle.
|
||||
type2id(entry) -> entry.
|
||||
|
||||
type2enc(key_block_hash) -> ?BASE58;
|
||||
type2enc(micro_block_hash) -> ?BASE58;
|
||||
@ -204,10 +199,6 @@ 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;
|
||||
@ -240,10 +231,6 @@ 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">>;
|
||||
@ -275,10 +262,6 @@ 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;
|
||||
@ -312,10 +295,6 @@ 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;
|
@ -1,12 +1,13 @@
|
||||
%%% -*- 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
|
||||
@ -14,8 +15,8 @@
|
||||
, deserialize_type_and_vsn/1
|
||||
]).
|
||||
|
||||
-type template() :: aeserialization:template().
|
||||
-type fields() :: aeserialization:fields().
|
||||
-type template() :: gmserialization:template().
|
||||
-type fields() :: gmserialization:fields().
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
@ -23,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
|
||||
@ -41,12 +42,6 @@ tag(account) -> 10;
|
||||
tag(signed_tx) -> 11;
|
||||
tag(spend_tx) -> 12;
|
||||
tag(data_extend_tx) -> 13;
|
||||
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(name) -> 30;
|
||||
tag(name_commitment) -> 31;
|
||||
tag(name_claim_tx) -> 32;
|
||||
@ -89,7 +84,6 @@ 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;
|
||||
@ -105,6 +99,7 @@ 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;
|
||||
@ -126,12 +121,6 @@ rev_tag(10) -> account;
|
||||
rev_tag(11) -> signed_tx;
|
||||
rev_tag(12) -> spend_tx;
|
||||
rev_tag(13) -> data_extend_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(30) -> name;
|
||||
rev_tag(31) -> name_commitment;
|
||||
rev_tag(32) -> name_claim_tx;
|
||||
@ -174,7 +163,6 @@ 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;
|
||||
@ -190,6 +178,7 @@ 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;
|
@ -1,13 +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
|
||||
@ -44,7 +45,7 @@ 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).
|
||||
@ -66,13 +67,13 @@ blake2(Size, Bin) ->
|
||||
|
||||
-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
|
||||
@ -85,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
|
||||
@ -100,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
|
@ -1,18 +1,16 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2025, QPQ AG
|
||||
%%% @copyright (C) 2023, Aeternity Anstalt
|
||||
%%% @doc
|
||||
%%% Serialization of delegation signatures
|
||||
%%% @end
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(aeser_delegation).
|
||||
-module(gmser_delegation).
|
||||
-vsn("0.1.2").
|
||||
|
||||
-export([ aens_preclaim_sig/3
|
||||
, aens_name_sig/4
|
||||
, aens_sig/3
|
||||
|
||||
, oracle_sig/3
|
||||
, oracle_response_sig/3
|
||||
]).
|
||||
|
||||
%% Delegation signatures are prefixed with a unique tag, ensuring not to
|
||||
@ -29,7 +27,7 @@
|
||||
|
||||
-type sig_data() :: binary().
|
||||
|
||||
-spec aens_preclaim_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
||||
-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),
|
||||
@ -37,7 +35,7 @@ aens_preclaim_sig(NetworkId, Account, Contract) ->
|
||||
Fields = [{account, Account}, {contract, Contract}],
|
||||
serialize(?TYPE_AENS_PRECLAIM, NetworkId, Template, Fields).
|
||||
|
||||
-spec aens_name_sig(binary(), aeser_id:id(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
||||
-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),
|
||||
@ -46,7 +44,7 @@ aens_name_sig(NetworkId, Account, Name, Contract) ->
|
||||
Fields = [{account, Account}, {name, Name}, {contract, Contract}],
|
||||
serialize(?TYPE_AENS_NAME, NetworkId, Template, Fields).
|
||||
|
||||
-spec aens_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
||||
-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),
|
||||
@ -54,29 +52,14 @@ aens_sig(NetworkId, Account, Contract) ->
|
||||
Fields = [{account, Account}, {contract, Contract}],
|
||||
serialize(?TYPE_AENS, NetworkId, Template, Fields).
|
||||
|
||||
-spec oracle_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
||||
oracle_sig(NetworkId, Account, Contract) ->
|
||||
assert_id(account, Account),
|
||||
assert_id(contract, Contract),
|
||||
Template = [{account, id}, {contract, id}],
|
||||
Fields = [{account, Account}, {contract, Contract}],
|
||||
serialize(?TYPE_ORACLE, NetworkId, Template, Fields).
|
||||
|
||||
-spec oracle_response_sig(binary(), aeser_id:id(), aeser_id:id()) -> sig_data().
|
||||
oracle_response_sig(NetworkId, QueryId, Contract) ->
|
||||
assert_id(oracle, QueryId),
|
||||
assert_id(contract, Contract),
|
||||
Template = [{query, id}, {contract, id}],
|
||||
Fields = [{query, QueryId}, {contract, Contract}],
|
||||
serialize(?TYPE_ORACLE_RESPONSE, NetworkId, Template, Fields).
|
||||
|
||||
%% ------------------------------------------------------------------------
|
||||
%% -- Internal functions
|
||||
%% ------------------------------------------------------------------------
|
||||
|
||||
serialize(Type, NetworkId, Template, Fields) ->
|
||||
Data = aeserialization:serialize(Type, ?VSN, Template, Fields),
|
||||
Data = gmserialization:serialize(Type, ?VSN, Template, Fields),
|
||||
<<?DELEGATION_TAG:16, NetworkId/binary, Data/binary>>.
|
||||
|
||||
assert_id(Type, AeserId) ->
|
||||
Type = aeser_id:specialize_type(AeserId).
|
||||
Type = gmser_id:specialize_type(AeserId).
|
@ -1,12 +1,13 @@
|
||||
%%% -*- 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
|
||||
@ -25,7 +26,7 @@
|
||||
, val
|
||||
}).
|
||||
|
||||
-type tag() :: 'account' | 'oracle' | 'name'
|
||||
-type tag() :: 'account' | 'name'
|
||||
| 'commitment' | 'contract' | 'channel'
|
||||
| 'associate_chain' | 'entry' .
|
||||
-type val() :: <<_:256>>.
|
||||
@ -41,7 +42,6 @@
|
||||
-define(SERIALIZED_SIZE, 33). %% ?TAG_SIZE + ?PUB_SIZE
|
||||
|
||||
-define(IS_TAG(___TAG___), ___TAG___ =:= account;
|
||||
___TAG___ =:= oracle;
|
||||
___TAG___ =:= name;
|
||||
___TAG___ =:= commitment;
|
||||
___TAG___ =:= contract;
|
||||
@ -101,7 +101,6 @@ decode(<<Tag:?TAG_SIZE/unit:8, Val:?PUB_SIZE/binary>>) ->
|
||||
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(associate_chain) -> 7;
|
||||
@ -112,7 +111,6 @@ 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;
|
@ -1,15 +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,12 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @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
|
||||
@ -36,9 +37,9 @@
|
||||
| binary()
|
||||
| boolean()
|
||||
| [encodable_term()] %% Of any length
|
||||
| #{atom() => encodable_term()}
|
||||
| #{atom() => encodable_term()}
|
||||
| tuple() %% Any arity, containing encodable_term().
|
||||
| aeser_id:id().
|
||||
| gmser_id:id().
|
||||
|
||||
-type fields() :: [{field_name(), encodable_term()}].
|
||||
|
||||
@ -50,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] ->
|
||||
@ -69,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}.
|
||||
@ -119,7 +120,7 @@ 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}).
|
||||
@ -143,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,67 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @copyright (C) 2023, Aeternity Anstalt
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
-module(aeser_delegation_tests).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
-define(TEST_MODULE, aeser_delegation).
|
||||
|
||||
-define(ACCOUNT, aeser_id:create(account, <<1:256>>)).
|
||||
-define(CONTRACT, aeser_id:create(contract, <<2:256>>)).
|
||||
-define(NAME, aeser_id:create(name, <<3:256>>)).
|
||||
-define(ORACLE, aeser_id:create(oracle, <<3:256>>)).
|
||||
|
||||
-define(NETWORK_ID, <<"my_fancy_network"/utf8>>).
|
||||
|
||||
encode_correct_test_() ->
|
||||
[{"Encode preclaim sig",
|
||||
fun() ->
|
||||
aeser_delegation:aens_preclaim_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
||||
end},
|
||||
{"Encode name sig",
|
||||
fun() ->
|
||||
aeser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, ?NAME, ?CONTRACT)
|
||||
end},
|
||||
{"Encode aens wildcard sig",
|
||||
fun() ->
|
||||
aeser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
||||
end},
|
||||
{"Encode oracle sig",
|
||||
fun() ->
|
||||
aeser_delegation:oracle_sig(?NETWORK_ID, ?ACCOUNT, ?CONTRACT)
|
||||
end},
|
||||
{"Encode oracle response sig",
|
||||
fun() ->
|
||||
aeser_delegation:oracle_response_sig(?NETWORK_ID, ?ORACLE, ?CONTRACT)
|
||||
end}
|
||||
].
|
||||
|
||||
encode_fail_test_() ->
|
||||
[{"Bad encoding preclaim sig",
|
||||
fun() ->
|
||||
?assertError(_, aeser_delegation:aens_preclaim_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)),
|
||||
?assertError(_, aeser_delegation:aens_preclaim_sig(?NETWORK_ID, ?CONTRACT, ?ACCOUNT))
|
||||
end},
|
||||
{"Bad encoding name sig",
|
||||
fun() ->
|
||||
?assertError(_, aeser_delegation:aens_name_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>, ?CONTRACT)),
|
||||
?assertError(_, aeser_delegation:aens_name_sig(?NETWORK_ID, ?NAME, ?ACCOUNT, ?CONTRACT))
|
||||
end},
|
||||
{"Bad encoding aens wildcard sig",
|
||||
fun() ->
|
||||
?assertError(_, aeser_delegation:aens_sig(?NETWORK_ID, ?ACCOUNT, <<42:256>>)),
|
||||
?assertError(_, aeser_delegation:aens_sig(?NETWORK_ID, ?CONTRACT, ?CONTRACT))
|
||||
end},
|
||||
{"Bad encoding oracle sig",
|
||||
fun() ->
|
||||
?assertError(_, aeser_delegation:oracle_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)),
|
||||
?assertError(_, aeser_delegation:oracle_sig(?NETWORK_ID, ?ACCOUNT, ?ACCOUNT))
|
||||
end},
|
||||
{"Bad encoding oracle response sig",
|
||||
fun() ->
|
||||
?assertError(_, aeser_delegation:oracle_response_sig(?NETWORK_ID, <<42:256>>, ?CONTRACT)),
|
||||
?assertError(_, aeser_delegation:oracle_response_sig(?NETWORK_ID, ?ORACLE, ?ORACLE))
|
||||
end}
|
||||
].
|
@ -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,8 +16,6 @@
|
||||
, {contract_pubkey , 32}
|
||||
, {transaction , not_applicable}
|
||||
, {tx_hash , 32}
|
||||
, {oracle_pubkey , 32}
|
||||
, {oracle_query_id , 32}
|
||||
, {account_pubkey , 32}
|
||||
, {signature , 64}
|
||||
, {name , not_applicable}
|
@ -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)).
|
||||
|
49
test/gmser_delegation_tests.erl
Normal file
49
test/gmser_delegation_tests.erl
Normal file
@ -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>>,
|
Loading…
x
Reference in New Issue
Block a user