Unify call arg order between call and create
This commit is contained in:
+40
-50
@@ -272,8 +272,7 @@ chain_nodes() ->
|
|||||||
%% transactions are submitted is called the "sticky node". This is the first node
|
%% transactions are submitted is called the "sticky node". This is the first node
|
||||||
%% (head position) in the list of nodes submitted to the chain when `chain_nodes/1'
|
%% (head position) in the list of nodes submitted to the chain when `chain_nodes/1'
|
||||||
%% is called. If using multiple nodes but the sticky node should also be used for
|
%% is called. If using multiple nodes but the sticky node should also be used for
|
||||||
%% read-only queries, submit the sticky node at the head of the list and again in
|
%% read-only queries, put the sticky node in the list twice.
|
||||||
%% the tail.
|
|
||||||
|
|
||||||
chain_nodes(List) when is_list(List) ->
|
chain_nodes(List) when is_list(List) ->
|
||||||
hz_man:chain_nodes(List).
|
hz_man:chain_nodes(List).
|
||||||
@@ -284,7 +283,7 @@ chain_nodes(List) when is_list(List) ->
|
|||||||
%% Check whether TLS is in use. The typical situation is to not use TLS as nodes that
|
%% Check whether TLS is in use. The typical situation is to not use TLS as nodes that
|
||||||
%% serve as part of the backend of an application are typically run in the same
|
%% serve as part of the backend of an application are typically run in the same
|
||||||
%% backend network as the application service. When accessing chain nodes over the WAN
|
%% backend network as the application service. When accessing chain nodes over the WAN
|
||||||
%% however, TLS is strongly recommended to avoid a MITM attack.
|
%% however, TLS is recommended to avoid a MitM attack.
|
||||||
%%
|
%%
|
||||||
%% In this version of Hakuzaru TLS is either on or off for all nodes, making a mixed
|
%% In this version of Hakuzaru TLS is either on or off for all nodes, making a mixed
|
||||||
%% infrastructure complicated to support without two Hakuzaru instances. This will
|
%% infrastructure complicated to support without two Hakuzaru instances. This will
|
||||||
@@ -299,7 +298,7 @@ tls() ->
|
|||||||
-spec tls(boolean()) -> ok.
|
-spec tls(boolean()) -> ok.
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Set TLS true or false. That's what a boolean is, by the way, `true' or `false'.
|
%% Set TLS true or false. That's what a boolean is, by the way, `true' or `false'.
|
||||||
%% This is a condescending comment. That means I am talking down to you.
|
%% This is a condescending comment. That means to talk down to someone.
|
||||||
%%
|
%%
|
||||||
%% TLS defaults to `false'.
|
%% TLS defaults to `false'.
|
||||||
|
|
||||||
@@ -343,7 +342,8 @@ timeout(MS) ->
|
|||||||
%% NOTE:
|
%% NOTE:
|
||||||
%% This will return the currently synced height, which may be different than the
|
%% This will return the currently synced height, which may be different than the
|
||||||
%% actual current top of the entire chain if the node being queried is still syncing
|
%% actual current top of the entire chain if the node being queried is still syncing
|
||||||
%% (has not yet caught up with the chain).
|
%% (has not yet caught up with the chain). More complete information, including
|
||||||
|
%% whether the node is currently syncing, can be gained from a `status()' query.
|
||||||
|
|
||||||
top_height() ->
|
top_height() ->
|
||||||
case top_block() of
|
case top_block() of
|
||||||
@@ -356,7 +356,7 @@ top_height() ->
|
|||||||
when TopBlock :: microblock_header(),
|
when TopBlock :: microblock_header(),
|
||||||
Reason :: chain_error().
|
Reason :: chain_error().
|
||||||
%% @doc
|
%% @doc
|
||||||
%% Returns the current block height as an integer.
|
%% Returns the current top block of the chain.
|
||||||
|
|
||||||
top_block() ->
|
top_block() ->
|
||||||
request("/v3/headers/top").
|
request("/v3/headers/top").
|
||||||
@@ -444,10 +444,6 @@ kb_by_height(Height) ->
|
|||||||
result(request(["/v3/key-blocks/height/", StringN])).
|
result(request(["/v3/key-blocks/height/", StringN])).
|
||||||
|
|
||||||
|
|
||||||
%kb_insert(KeyblockData) ->
|
|
||||||
% request("/v3/key-blocks", KeyblockData).
|
|
||||||
|
|
||||||
|
|
||||||
-spec mb_header(ID) -> {ok, MB_Header} | {error, Reason}
|
-spec mb_header(ID) -> {ok, MB_Header} | {error, Reason}
|
||||||
when ID :: microblock_hash(),
|
when ID :: microblock_hash(),
|
||||||
MB_Header :: microblock_header(),
|
MB_Header :: microblock_header(),
|
||||||
@@ -607,12 +603,6 @@ next_nonce(AccountID) ->
|
|||||||
{ok, #{"reason" := Reason}} -> {error, Reason};
|
{ok, #{"reason" := Reason}} -> {error, Reason};
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
% case request_sticky(["/v3/accounts/", AccountID]) of
|
|
||||||
% {ok, #{"nonce" := Nonce}} -> {ok, Nonce + 1};
|
|
||||||
% {ok, #{"reason" := "Account not found"}} -> {ok, 1};
|
|
||||||
% {ok, #{"reason" := Reason}} -> {error, Reason};
|
|
||||||
% Error -> Error
|
|
||||||
% end.
|
|
||||||
|
|
||||||
|
|
||||||
-spec dry_run(TX) -> {ok, Result} | {error, Reason}
|
-spec dry_run(TX) -> {ok, Result} | {error, Reason}
|
||||||
@@ -929,14 +919,14 @@ contract_create(CreatorID, Path, InitArgs) ->
|
|||||||
|
|
||||||
|
|
||||||
-spec contract_create(CreatorID, Nonce,
|
-spec contract_create(CreatorID, Nonce,
|
||||||
Amount, TTL, Gas, GasPrice,
|
Gas, GasPrice, Amount, TTL,
|
||||||
Path, InitArgs) -> Result
|
Path, InitArgs) -> Result
|
||||||
when CreatorID :: pubkey(),
|
when CreatorID :: pubkey(),
|
||||||
Nonce :: pos_integer(),
|
Nonce :: pos_integer(),
|
||||||
Amount :: non_neg_integer(),
|
|
||||||
TTL :: non_neg_integer(),
|
|
||||||
Gas :: pos_integer(),
|
Gas :: pos_integer(),
|
||||||
GasPrice :: pos_integer(),
|
GasPrice :: pos_integer(),
|
||||||
|
Amount :: non_neg_integer(),
|
||||||
|
TTL :: non_neg_integer(),
|
||||||
Path :: file:filename(),
|
Path :: file:filename(),
|
||||||
InitArgs :: [string()]
|
InitArgs :: [string()]
|
||||||
| {erlang, [term()]}
|
| {erlang, [term()]}
|
||||||
@@ -973,24 +963,6 @@ contract_create(CreatorID, Path, InitArgs) ->
|
|||||||
%% querying your Gajumaru node (via `hz:next_nonce(CallerID)', for example).
|
%% querying your Gajumaru node (via `hz:next_nonce(CallerID)', for example).
|
||||||
%% </li>
|
%% </li>
|
||||||
%% <li>
|
%% <li>
|
||||||
%% <b>Amount:</b>
|
|
||||||
%% All Gajumaru transactions can carry an "amount" spent from the origin account
|
|
||||||
%% (in this case the `CallerID') to the destination. In a "Spend" transaction this
|
|
||||||
%% is the only value that really matters, but in a contract call the utility is
|
|
||||||
%% quite different, as you can pay money <em>into</em> a contract and have that
|
|
||||||
%% contract hold it (for future payouts, to be held in escrow, as proof of intent
|
|
||||||
%% to purchase or engage in an auction, whatever). Typically this value is 0, but
|
|
||||||
%% of course there are very good reasons why it should be set to a non-zero value
|
|
||||||
%% in the case of calls related to contract-governed payment systems.
|
|
||||||
%% </li>
|
|
||||||
%% <li>
|
|
||||||
%% <b>TTL:</b>
|
|
||||||
%% This stands for "Time-To-Live", meaning the height beyond which this element is
|
|
||||||
%% considered to be eligible for garbage collection (and therefore inaccessible!).
|
|
||||||
%% The TTL can be extended by a "live extension" transaction (basically pay for the
|
|
||||||
%% data to remain alive longer).
|
|
||||||
%% </li>
|
|
||||||
%% <li>
|
|
||||||
%% <b>Gas:</b>
|
%% <b>Gas:</b>
|
||||||
%% This number sets a limit on the maximum amount of computation the caller is willing
|
%% This number sets a limit on the maximum amount of computation the caller is willing
|
||||||
%% to pay for on the chain.
|
%% to pay for on the chain.
|
||||||
@@ -1023,6 +995,24 @@ contract_create(CreatorID, Path, InitArgs) ->
|
|||||||
%% transaction, thus making miners more likely to prioritize the high value ones.
|
%% transaction, thus making miners more likely to prioritize the high value ones.
|
||||||
%% </li>
|
%% </li>
|
||||||
%% <li>
|
%% <li>
|
||||||
|
%% <b>Amount:</b>
|
||||||
|
%% All Gajumaru transactions can carry an "amount" spent from the origin account
|
||||||
|
%% (in this case the `CallerID') to the destination. In a "Spend" transaction this
|
||||||
|
%% is the only value that really matters, but in a contract call the utility is
|
||||||
|
%% quite different, as you can pay money <em>into</em> a contract and have that
|
||||||
|
%% contract hold it (for future payouts, to be held in escrow, as proof of intent
|
||||||
|
%% to purchase or engage in an auction, whatever). Typically this value is 0, but
|
||||||
|
%% of course there are very good reasons why it should be set to a non-zero value
|
||||||
|
%% in the case of calls related to contract-governed payment systems.
|
||||||
|
%% </li>
|
||||||
|
%% <li>
|
||||||
|
%% <b>TTL:</b>
|
||||||
|
%% This stands for "Time-To-Live", meaning the height beyond which this element is
|
||||||
|
%% considered to be eligible for garbage collection (and therefore inaccessible!).
|
||||||
|
%% The TTL can be extended by a "live extension" transaction (basically pay for the
|
||||||
|
%% data to remain alive longer).
|
||||||
|
%% </li>
|
||||||
|
%% <li>
|
||||||
%% <b>ACI:</b>
|
%% <b>ACI:</b>
|
||||||
%% This is the compiled contract's metadata. It provides the information necessary
|
%% This is the compiled contract's metadata. It provides the information necessary
|
||||||
%% for the contract call data to be formed in a way that the Gajumaru runtime will
|
%% for the contract call data to be formed in a way that the Gajumaru runtime will
|
||||||
@@ -1056,7 +1046,7 @@ contract_create(CreatorID, Path, InitArgs) ->
|
|||||||
%% if you do not already have a copy, and can check the spec of a function before
|
%% if you do not already have a copy, and can check the spec of a function before
|
||||||
%% trying to form a contract call.
|
%% trying to form a contract call.
|
||||||
|
|
||||||
contract_create(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Path, InitArgs) ->
|
contract_create(CreatorID, Nonce, Gas, GasPrice, Amount, TTL, Path, InitArgs) ->
|
||||||
case file:read_file(Path) of
|
case file:read_file(Path) of
|
||||||
{ok, Source} ->
|
{ok, Source} ->
|
||||||
Dir = filename:dirname(Path),
|
Dir = filename:dirname(Path),
|
||||||
@@ -1067,17 +1057,17 @@ contract_create(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Path, InitArgs) ->
|
|||||||
{src_file, Path},
|
{src_file, Path},
|
||||||
{src_dir, SrcDir},
|
{src_dir, SrcDir},
|
||||||
{include, {file_system, [CWD, so_utils:canonical_dir(Dir)]}}],
|
{include, {file_system, [CWD, so_utils:canonical_dir(Dir)]}}],
|
||||||
contract_create2(CreatorID, Nonce, Amount, TTL, Gas, GasPrice,
|
contract_create2(CreatorID, Nonce, Gas, GasPrice, Amount, TTL,
|
||||||
Source, Options, InitArgs);
|
Source, Options, InitArgs);
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
contract_create2(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Source, Options, InitArgs) ->
|
contract_create2(CreatorID, Nonce, Gas, GasPrice, Amount, TTL, Source, Options, InitArgs) ->
|
||||||
case so_compiler:from_string(Source, Options) of
|
case so_compiler:from_string(Source, Options) of
|
||||||
{ok, Compiled} ->
|
{ok, Compiled} ->
|
||||||
contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice,
|
contract_create_built(CreatorID, Nonce, Gas, GasPrice, Amount, TTL,
|
||||||
Compiled, InitArgs);
|
Compiled, InitArgs);
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
@@ -1108,20 +1098,20 @@ contract_create_built(CreatorID, Compiled, InitArgs) ->
|
|||||||
Gas = 500000,
|
Gas = 500000,
|
||||||
GasPrice = min_gas_price(),
|
GasPrice = min_gas_price(),
|
||||||
contract_create_built(CreatorID, Nonce,
|
contract_create_built(CreatorID, Nonce,
|
||||||
Amount, TTL, Gas, GasPrice,
|
Gas, GasPrice, Amount, TTL,
|
||||||
Compiled, InitArgs);
|
Compiled, InitArgs);
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
-spec contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) -> Result
|
-spec contract_create_built(CreatorID, Nonce, Gas, GasPrice, Amount, TTL, Compiled, InitArgs) -> Result
|
||||||
when CreatorID :: unicode:chardata(),
|
when CreatorID :: unicode:chardata(),
|
||||||
Nonce :: pos_integer(),
|
Nonce :: pos_integer(),
|
||||||
Amount :: non_neg_integer(),
|
|
||||||
TTL :: non_neg_integer(),
|
|
||||||
Gas :: pos_integer(),
|
Gas :: pos_integer(),
|
||||||
GasPrice :: pos_integer(),
|
GasPrice :: pos_integer(),
|
||||||
|
Amount :: non_neg_integer(),
|
||||||
|
TTL :: non_neg_integer(),
|
||||||
Compiled :: map(),
|
Compiled :: map(),
|
||||||
InitArgs :: [string()]
|
InitArgs :: [string()]
|
||||||
| {erlang, [term()]}
|
| {erlang, [term()]}
|
||||||
@@ -1135,26 +1125,26 @@ contract_create_built(CreatorID, Compiled, InitArgs) ->
|
|||||||
%% The `Compiled' argument is the output of contract compilation and replaces the `File'
|
%% The `Compiled' argument is the output of contract compilation and replaces the `File'
|
||||||
%% argument in `contract_create/8'.
|
%% argument in `contract_create/8'.
|
||||||
|
|
||||||
contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) ->
|
contract_create_built(CreatorID, Nonce, Gas, GasPrice, Amount, TTL, Compiled, InitArgs) ->
|
||||||
AACI = hz_aaci:prepare(maps:get(aci, Compiled)),
|
AACI = hz_aaci:prepare(maps:get(aci, Compiled)),
|
||||||
case encode_call_data(AACI, "init", InitArgs) of
|
case encode_call_data(AACI, "init", InitArgs) of
|
||||||
{ok, CallData} ->
|
{ok, CallData} ->
|
||||||
assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData);
|
assemble_calldata(CreatorID, Nonce, Gas, GasPrice, Amount, TTL, Compiled, CallData);
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) ->
|
assemble_calldata(CreatorID, Nonce, Gas, GasPrice, Amount, TTL, Compiled, CallData) ->
|
||||||
PK = unicode:characters_to_binary(CreatorID),
|
PK = unicode:characters_to_binary(CreatorID),
|
||||||
try
|
try
|
||||||
{account_pubkey, OwnerID} = gmser_api_encoder:decode(PK),
|
{account_pubkey, OwnerID} = gmser_api_encoder:decode(PK),
|
||||||
assemble_calldata2(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData)
|
assemble_calldata2(OwnerID, Nonce, Gas, GasPrice, Amount, TTL, Compiled, CallData)
|
||||||
catch
|
catch
|
||||||
Error:Reason -> {Error, Reason}
|
Error:Reason -> {Error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
assemble_calldata2(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) ->
|
assemble_calldata2(OwnerID, Nonce, Gas, GasPrice, Amount, TTL, Compiled, CallData) ->
|
||||||
Code = gmser_contract_code:serialize(Compiled),
|
Code = gmser_contract_code:serialize(Compiled),
|
||||||
Source = unicode:characters_to_binary(maps:get(contract_source, Compiled, <<>>)),
|
Source = unicode:characters_to_binary(maps:get(contract_source, Compiled, <<>>)),
|
||||||
VM = 1,
|
VM = 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user