Compare commits
3 Commits
b69ababf0f
...
e0860f72ca
Author | SHA1 | Date | |
---|---|---|---|
e0860f72ca | |||
f5ece9946d | |||
ab6442daa4 |
60
src/hz.erl
60
src/hz.erl
@ -656,13 +656,13 @@ dry_run_map(Map) ->
|
||||
|
||||
%% @doc
|
||||
%% Decode the "cb_XXXX" string that came out of a tx_info or dry_run, to
|
||||
%% the Erlang representation of FATE objects used by aeb_fate_encoding. See
|
||||
%% the Erlang representation of FATE objects used by gmb_fate_encoding. See
|
||||
%% decode_bytearray/2 for an alternative that provides simpler outputs based on
|
||||
%% information provided by an AACI.
|
||||
|
||||
decode_bytearray_fate(EncodedStr) ->
|
||||
Encoded = unicode:characters_to_binary(EncodedStr),
|
||||
{contract_bytearray, Binary} = aeser_api_encoder:decode(Encoded),
|
||||
{contract_bytearray, Binary} = gmser_api_encoder:decode(Encoded),
|
||||
case Binary of
|
||||
<<>> -> {ok, none};
|
||||
<<"Out of gas">> -> {error, out_of_gas};
|
||||
@ -670,7 +670,7 @@ decode_bytearray_fate(EncodedStr) ->
|
||||
% FIXME there may be other errors that are encoded directly into
|
||||
% the byte array. We could try and catch to at least return
|
||||
% *something* for cases that we don't already detect.
|
||||
Object = aeb_fate_encoding:deserialize(Binary),
|
||||
Object = gmb_fate_encoding:deserialize(Binary),
|
||||
{ok, Object}
|
||||
end.
|
||||
|
||||
@ -952,7 +952,7 @@ contract_create(CreatorID, Path, InitArgs) ->
|
||||
%% </li>
|
||||
%% <li>
|
||||
%% <b>GasPrice:</b>
|
||||
%% This is a factor that is used calculate a value in aettos (the smallest unit of
|
||||
%% This is a factor that is used calculate a value in pucks (the smallest unit of
|
||||
%% Gajumaru's currency value) for the gas consumed. In times of high contention
|
||||
%% in the mempool increasing the gas price increases the value of mining a given
|
||||
%% transaction, thus making miners more likely to prioritize the high value ones.
|
||||
@ -1058,14 +1058,14 @@ contract_create3(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArg
|
||||
contract_create4(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) ->
|
||||
PK = unicode:characters_to_binary(CreatorID),
|
||||
try
|
||||
{account_pubkey, OwnerID} = aeser_api_encoder:decode(PK),
|
||||
{account_pubkey, OwnerID} = gmser_api_encoder:decode(PK),
|
||||
contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData)
|
||||
catch
|
||||
Error:Reason -> {Error, Reason}
|
||||
end.
|
||||
|
||||
contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) ->
|
||||
Code = aeser_contract_code:serialize(Compiled),
|
||||
Code = gmser_contract_code:serialize(Compiled),
|
||||
Source = maps:get(contract_source, Compiled, <<>>),
|
||||
VM = 1,
|
||||
ABI = 1,
|
||||
@ -1073,7 +1073,7 @@ contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData)
|
||||
ContractCreateVersion = 1,
|
||||
Type = contract_create_tx,
|
||||
Fields =
|
||||
[{owner_id, aeser_id:create(account, OwnerID)},
|
||||
[{owner_id, gmser_id:create(account, OwnerID)},
|
||||
{nonce, Nonce},
|
||||
{code, Code},
|
||||
{source, Source},
|
||||
@ -1096,9 +1096,9 @@ contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData)
|
||||
{gas_price, int},
|
||||
{gas, int},
|
||||
{call_data, binary}],
|
||||
TXB = aeser_chain_objects:serialize(Type, ContractCreateVersion, Template, Fields),
|
||||
TXB = gmser_chain_objects:serialize(Type, ContractCreateVersion, Template, Fields),
|
||||
try
|
||||
{ok, aeser_api_encoder:encode(transaction, TXB)}
|
||||
{ok, gmser_api_encoder:encode(transaction, TXB)}
|
||||
catch
|
||||
error:Reason -> {error, Reason}
|
||||
end.
|
||||
@ -1271,7 +1271,7 @@ contract_call(CallerID, Gas, AACI, ConID, Fun, Args) ->
|
||||
%% </li>
|
||||
%% <li>
|
||||
%% <b>GasPrice:</b>
|
||||
%% This is a factor that is used calculate a value in aettos (the smallest unit of
|
||||
%% This is a factor that is used calculate a value in pucks (the smallest unit of
|
||||
%% Gajumaru's currency value) for the gas consumed. In times of high contention
|
||||
%% in the mempool increasing the gas price increases the value of mining a given
|
||||
%% transaction, thus making miners more likely to prioritize the high value ones.
|
||||
@ -1329,7 +1329,7 @@ contract_call(CallerID, Nonce, Gas, GP, Amount, TTL, AACI, ConID, Fun, Args) ->
|
||||
contract_call2(CallerID, Nonce, Gas, GasPrice, Amount, TTL, ConID, CallData) ->
|
||||
CallerBin = unicode:characters_to_binary(CallerID),
|
||||
try
|
||||
{account_pubkey, PK} = aeser_api_encoder:decode(CallerBin),
|
||||
{account_pubkey, PK} = gmser_api_encoder:decode(CallerBin),
|
||||
contract_call3(PK, Nonce, Gas, GasPrice, Amount, TTL, ConID, CallData)
|
||||
catch
|
||||
Error:Reason -> {Error, Reason}
|
||||
@ -1338,7 +1338,7 @@ contract_call2(CallerID, Nonce, Gas, GasPrice, Amount, TTL, ConID, CallData) ->
|
||||
contract_call3(PK, Nonce, Gas, GasPrice, Amount, TTL, ConID, CallData) ->
|
||||
ConBin = unicode:characters_to_binary(ConID),
|
||||
try
|
||||
{contract_pubkey, CK} = aeser_api_encoder:decode(ConBin),
|
||||
{contract_pubkey, CK} = gmser_api_encoder:decode(ConBin),
|
||||
contract_call4(PK, Nonce, Gas, GasPrice, Amount, TTL, CK, CallData)
|
||||
catch
|
||||
Error:Reason -> {Error, Reason}
|
||||
@ -1349,9 +1349,9 @@ contract_call4(PK, Nonce, Gas, GasPrice, Amount, TTL, CK, CallData) ->
|
||||
CallVersion = 1,
|
||||
Type = contract_call_tx,
|
||||
Fields =
|
||||
[{caller_id, aeser_id:create(account, PK)},
|
||||
[{caller_id, gmser_id:create(account, PK)},
|
||||
{nonce, Nonce},
|
||||
{contract_id, aeser_id:create(contract, CK)},
|
||||
{contract_id, gmser_id:create(contract, CK)},
|
||||
{abi_version, ABI},
|
||||
{ttl, TTL},
|
||||
{amount, Amount},
|
||||
@ -1368,9 +1368,9 @@ contract_call4(PK, Nonce, Gas, GasPrice, Amount, TTL, CK, CallData) ->
|
||||
{gas_price, int},
|
||||
{gas, int},
|
||||
{call_data, binary}],
|
||||
TXB = aeser_chain_objects:serialize(Type, CallVersion, Template, Fields),
|
||||
TXB = gmser_chain_objects:serialize(Type, CallVersion, Template, Fields),
|
||||
try
|
||||
{ok, aeser_api_encoder:encode(transaction, TXB)}
|
||||
{ok, gmser_api_encoder:encode(transaction, TXB)}
|
||||
catch
|
||||
error:Reason -> {error, Reason}
|
||||
end.
|
||||
@ -1385,7 +1385,7 @@ contract_call4(PK, Nonce, Gas, GasPrice, Amount, TTL, CK, CallData) ->
|
||||
%% of calldata
|
||||
|
||||
prepare_contract(File) ->
|
||||
case aeso_compiler:file(File, [{aci, json}]) of
|
||||
case gmso_compiler:file(File, [{aci, json}]) of
|
||||
{ok, #{aci := ACI}} -> {ok, prepare_aaci(ACI)};
|
||||
Error -> Error
|
||||
end.
|
||||
@ -1453,7 +1453,7 @@ simplify_args(#{name := NameBin, type := TypeDef}, Types) ->
|
||||
|
||||
% Type preparation has two goals. First, we need a data structure that can be
|
||||
% traversed quickly, to take sophia-esque erlang expressions and turn them into
|
||||
% fate-esque erlang expressions that aebytecode can serialize. Second, we need
|
||||
% fate-esque erlang expressions that gmbytecode can serialize. Second, we need
|
||||
% partially substituted names, so that error messages can be generated for why
|
||||
% "foobar" is not valid as the third field of a `bazquux`, because the third
|
||||
% field is supposed to be `option(integer)`, not `string`.
|
||||
@ -1708,7 +1708,7 @@ coerce({O, N, integer}, S, to_fate) when is_list(S) ->
|
||||
end;
|
||||
coerce({O, N, address}, S, to_fate) ->
|
||||
try
|
||||
case aeser_api_encoder:decode(unicode:characters_to_binary(S)) of
|
||||
case gmser_api_encoder:decode(unicode:characters_to_binary(S)) of
|
||||
{account_pubkey, Key} -> {ok, {address, Key}};
|
||||
_ -> single_error({invalid, O, N, S})
|
||||
end
|
||||
@ -1716,11 +1716,11 @@ coerce({O, N, address}, S, to_fate) ->
|
||||
error:_ -> single_error({invalid, O, N, S})
|
||||
end;
|
||||
coerce({_, _, address}, {address, Bin}, from_fate) ->
|
||||
Address = aeser_api_encoder:encode(account_pubkey, Bin),
|
||||
Address = gmser_api_encoder:encode(account_pubkey, Bin),
|
||||
{ok, unicode:characters_to_list(Address)};
|
||||
coerce({O, N, contract}, S, to_fate) ->
|
||||
try
|
||||
case aeser_api_encoder:decode(unicode:characters_to_binary(S)) of
|
||||
case gmser_api_encoder:decode(unicode:characters_to_binary(S)) of
|
||||
{contract_pubkey, Key} -> {ok, {contract, Key}};
|
||||
_ -> single_error({invalid, O, N, S})
|
||||
end
|
||||
@ -1728,7 +1728,7 @@ coerce({O, N, contract}, S, to_fate) ->
|
||||
error:_ -> single_error({invalid, O, N, S})
|
||||
end;
|
||||
coerce({_, _, contract}, {contract, Bin}, from_fate) ->
|
||||
Address = aeser_api_encoder:encode(contract_pubkey, Bin),
|
||||
Address = gmser_api_encoder:encode(contract_pubkey, Bin),
|
||||
{ok, unicode:characters_to_list(Address)};
|
||||
coerce({_, _, boolean}, true, _) ->
|
||||
{ok, true};
|
||||
@ -1995,8 +1995,7 @@ aaci_lookup_spec({aaci, _, FunDefs, _}, Fun) ->
|
||||
%% @doc
|
||||
%% This function always returns 1,000,000,000 in the current version.
|
||||
%%
|
||||
%% This is the minimum gas price returned by aec_tx_pool:minimum_miner_gas_price(),
|
||||
%% (the default set in aeternity_config_schema.json).
|
||||
%% This is the minimum gas price returned by aec_tx_pool:minimum_miner_gas_price()
|
||||
%%
|
||||
%% Surely there can be some more nuance to this, but until a "gas station" type
|
||||
%% market/chain survey service exists we will use this naive value as a default
|
||||
@ -2030,7 +2029,7 @@ encode_call_data({aaci, _ContractName, FunDefs, _TypeDefs}, Fun, Args) ->
|
||||
|
||||
encode_call_data2(ArgDef, Fun, Args) ->
|
||||
case coerce_bindings(ArgDef, Args, to_fate) of
|
||||
{ok, Coerced} -> aeb_fate_abi:create_calldata(Fun, Coerced);
|
||||
{ok, Coerced} -> gmb_fate_abi:create_calldata(Fun, Coerced);
|
||||
Errors -> Errors
|
||||
end.
|
||||
|
||||
@ -2050,7 +2049,7 @@ encode_call_data2(ArgDef, Fun, Args) ->
|
||||
%% check failed before verification was able to pass or fail (bad key encoding or similar).
|
||||
|
||||
verify_signature(Sig, Message, PubKey) ->
|
||||
case aeser_api_encoder:decode(PubKey) of
|
||||
case gmser_api_encoder:decode(PubKey) of
|
||||
{account_pubkey, PK} -> verify_signature2(Sig, Message, PK);
|
||||
Other -> {error, {bad_key, Other}}
|
||||
end.
|
||||
@ -2059,20 +2058,11 @@ verify_signature2(Sig, Message, PK) ->
|
||||
% Gajumaru signatures require messages to be salted and hashed, then
|
||||
% the hash is what gets signed in order to protect
|
||||
% the user from accidentally signing a transaction disguised as a message.
|
||||
%
|
||||
% Salt the message then hash with blake2b. See:
|
||||
% 1. Erlang Blake2 blake2b/2 function:
|
||||
% https://gitlab.com/ioecs/eblake2/blob/60a079f00d72d1bfcc25de8e6996d28f912db3fd/src/eblake2.erl#L23-L25
|
||||
% 2. SDK salting step:
|
||||
% https://gitlab.com/ioecs/aepp-sdk-js/blob/370f1e30064ad0239ba59931908d9aba0a2e86b6/src/utils/crypto.ts#L171-L175
|
||||
% 3. SDK hashing:
|
||||
% https://gitlab.com/ioecs/aepp-sdk-js/blob/370f1e30064ad0239ba59931908d9aba0a2e86b6/src/utils/crypto.ts#L83-L85
|
||||
Prefix = <<"Gajumaru Signed Message:\n">>,
|
||||
{ok, PSize} = vencode(byte_size(Prefix)),
|
||||
{ok, MSize} = vencode(byte_size(Message)),
|
||||
Smashed = iolist_to_binary([PSize, Prefix, MSize, Message]),
|
||||
{ok, Hashed} = eblake2:blake2b(32, Smashed),
|
||||
% Signature = <<(binary_to_integer(Sig, 16)):(64 * 8)>>,
|
||||
Signature = base64:decode(Sig),
|
||||
Result = ecu_eddsa:sign_verify_detached(Signature, Hashed, PK),
|
||||
{ok, Result}.
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
-export([connect/4, slowly_connect/4]).
|
||||
|
||||
-include("$zx_include/zx_logger.hrl").
|
||||
|
||||
|
||||
connect(Node = {Host, Port}, Request, From, Timeout) ->
|
||||
Timer = erlang:send_after(Timeout, self(), timeout),
|
||||
@ -236,3 +234,10 @@ url({Node, Port}, Path) when is_list(Node) ->
|
||||
["https://", Node, ":", integer_to_list(Port), Path];
|
||||
url({Node, Port}, Path) when is_tuple(Node) ->
|
||||
["https://", inet:ntoa(Node), ":", integer_to_list(Port), Path].
|
||||
|
||||
|
||||
|
||||
log(Level, Format, Args) ->
|
||||
Raw = io_lib:format("~w ~w: " ++ Format, [?MODULE, self() | Args]),
|
||||
Entry = unicode:characters_to_list(Raw),
|
||||
logger:log(Level, Entry).
|
||||
|
@ -29,8 +29,6 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
code_change/3, terminate/2]).
|
||||
|
||||
%% TODO: Make logging more flexible
|
||||
-include("$zx_include/zx_logger.hrl").
|
||||
|
||||
|
||||
%%% Type and Record Definitions
|
||||
@ -197,7 +195,7 @@ handle_info({'DOWN', Mon, process, PID, Info}, State) ->
|
||||
NewState = handle_down(PID, Mon, Info, State),
|
||||
{noreply, NewState};
|
||||
handle_info(Unexpected, State) ->
|
||||
ok = log("Unexpected info: ~tp~n", [Unexpected]),
|
||||
ok = log(warning, "Unexpected info: ~tp~n", [Unexpected]),
|
||||
{noreply, State}.
|
||||
|
||||
|
||||
@ -287,3 +285,11 @@ do_request(Request,
|
||||
do_request(Request, From, State = #s{chain_nodes = {[], Used}}) ->
|
||||
Fresh = lists:reverse(Used),
|
||||
do_request(Request, From, State#s{chain_nodes = {Fresh, []}}).
|
||||
|
||||
|
||||
|
||||
|
||||
log(Level, Format, Args) ->
|
||||
Raw = io_lib:format("~w ~w: " ++ Format, [?MODULE, self() | Args]),
|
||||
Entry = unicode:characters_to_list(Raw),
|
||||
logger:log(Level, Entry).
|
||||
|
Loading…
x
Reference in New Issue
Block a user