Unify call arg order between call and create
This commit is contained in:
+41
-51
@@ -272,8 +272,7 @@ chain_nodes() ->
|
||||
%% 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'
|
||||
%% 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
|
||||
%% the tail.
|
||||
%% read-only queries, put the sticky node in the list twice.
|
||||
|
||||
chain_nodes(List) when is_list(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
|
||||
%% 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
|
||||
%% 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
|
||||
%% infrastructure complicated to support without two Hakuzaru instances. This will
|
||||
@@ -299,7 +298,7 @@ tls() ->
|
||||
-spec tls(boolean()) -> ok.
|
||||
%% @doc
|
||||
%% 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'.
|
||||
|
||||
@@ -343,7 +342,8 @@ timeout(MS) ->
|
||||
%% NOTE:
|
||||
%% 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
|
||||
%% (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() ->
|
||||
case top_block() of
|
||||
@@ -356,7 +356,7 @@ top_height() ->
|
||||
when TopBlock :: microblock_header(),
|
||||
Reason :: chain_error().
|
||||
%% @doc
|
||||
%% Returns the current block height as an integer.
|
||||
%% Returns the current top block of the chain.
|
||||
|
||||
top_block() ->
|
||||
request("/v3/headers/top").
|
||||
@@ -386,7 +386,7 @@ kb_current() ->
|
||||
kb_current_hash() ->
|
||||
case request("/v3/key-blocks/current/hash") of
|
||||
{ok, #{"reason" := Reason}} -> {error, Reason};
|
||||
{ok, #{"hash" := Hash}} -> {ok, Hash};
|
||||
{ok, #{"hash" := Hash}} -> {ok, Hash};
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
@@ -444,10 +444,6 @@ kb_by_height(Height) ->
|
||||
result(request(["/v3/key-blocks/height/", StringN])).
|
||||
|
||||
|
||||
%kb_insert(KeyblockData) ->
|
||||
% request("/v3/key-blocks", KeyblockData).
|
||||
|
||||
|
||||
-spec mb_header(ID) -> {ok, MB_Header} | {error, Reason}
|
||||
when ID :: microblock_hash(),
|
||||
MB_Header :: microblock_header(),
|
||||
@@ -607,12 +603,6 @@ next_nonce(AccountID) ->
|
||||
{ok, #{"reason" := Reason}} -> {error, Reason};
|
||||
Error -> Error
|
||||
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}
|
||||
@@ -929,14 +919,14 @@ contract_create(CreatorID, Path, InitArgs) ->
|
||||
|
||||
|
||||
-spec contract_create(CreatorID, Nonce,
|
||||
Amount, TTL, Gas, GasPrice,
|
||||
Gas, GasPrice, Amount, TTL,
|
||||
Path, InitArgs) -> Result
|
||||
when CreatorID :: pubkey(),
|
||||
Nonce :: pos_integer(),
|
||||
Amount :: non_neg_integer(),
|
||||
TTL :: non_neg_integer(),
|
||||
Gas :: pos_integer(),
|
||||
GasPrice :: pos_integer(),
|
||||
Amount :: non_neg_integer(),
|
||||
TTL :: non_neg_integer(),
|
||||
Path :: file:filename(),
|
||||
InitArgs :: [string()]
|
||||
| {erlang, [term()]}
|
||||
@@ -973,24 +963,6 @@ contract_create(CreatorID, Path, InitArgs) ->
|
||||
%% querying your Gajumaru node (via `hz:next_nonce(CallerID)', for example).
|
||||
%% </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>
|
||||
%% This number sets a limit on the maximum amount of computation the caller is willing
|
||||
%% 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.
|
||||
%% </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>
|
||||
%% 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
|
||||
@@ -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
|
||||
%% 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
|
||||
{ok, Source} ->
|
||||
Dir = filename:dirname(Path),
|
||||
@@ -1067,17 +1057,17 @@ contract_create(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Path, InitArgs) ->
|
||||
{src_file, Path},
|
||||
{src_dir, SrcDir},
|
||||
{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);
|
||||
Error ->
|
||||
Error
|
||||
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
|
||||
{ok, Compiled} ->
|
||||
contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice,
|
||||
contract_create_built(CreatorID, Nonce, Gas, GasPrice, Amount, TTL,
|
||||
Compiled, InitArgs);
|
||||
Error ->
|
||||
Error
|
||||
@@ -1108,20 +1098,20 @@ contract_create_built(CreatorID, Compiled, InitArgs) ->
|
||||
Gas = 500000,
|
||||
GasPrice = min_gas_price(),
|
||||
contract_create_built(CreatorID, Nonce,
|
||||
Amount, TTL, Gas, GasPrice,
|
||||
Gas, GasPrice, Amount, TTL,
|
||||
Compiled, InitArgs);
|
||||
Error ->
|
||||
Error
|
||||
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(),
|
||||
Nonce :: pos_integer(),
|
||||
Amount :: non_neg_integer(),
|
||||
TTL :: non_neg_integer(),
|
||||
Gas :: pos_integer(),
|
||||
GasPrice :: pos_integer(),
|
||||
Amount :: non_neg_integer(),
|
||||
TTL :: non_neg_integer(),
|
||||
Compiled :: map(),
|
||||
InitArgs :: [string()]
|
||||
| {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'
|
||||
%% 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)),
|
||||
case encode_call_data(AACI, "init", InitArgs) of
|
||||
{ok, CallData} ->
|
||||
assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData);
|
||||
assemble_calldata(CreatorID, Nonce, Gas, GasPrice, Amount, TTL, Compiled, CallData);
|
||||
Error ->
|
||||
Error
|
||||
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),
|
||||
try
|
||||
{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
|
||||
Error:Reason -> {Error, Reason}
|
||||
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),
|
||||
Source = unicode:characters_to_binary(maps:get(contract_source, Compiled, <<>>)),
|
||||
VM = 1,
|
||||
|
||||
Reference in New Issue
Block a user