WIP: Contract create is still broken (type problem)

This commit is contained in:
Craig Everett
2022-11-09 18:47:44 +09:00
parent 7b0e6a9988
commit 446cf1b58c
+31 -43
View File
@@ -65,6 +65,8 @@
min_gas/0, min_gas/0,
min_gas_price/0, min_gas_price/0,
min_fee/0, min_fee/0,
contract_create/3,
contract_create/8,
prepare_contract/1, prepare_contract/1,
contract_call/5, contract_call/5,
contract_call/10]). contract_call/10]).
@@ -745,7 +747,7 @@ result(Received) -> Received.
when CreatorID :: binary(), when CreatorID :: binary(),
Path :: file:filename(), Path :: file:filename(),
InitArgs :: [string()], InitArgs :: [string()],
Result :: {ok, CallTX} | {error, Reason}, Result :: {ok, CreateTX} | {error, Reason},
CreateTX :: binary(), CreateTX :: binary(),
Reason :: file:posix() | term(). Reason :: file:posix() | term().
%% @doc %% @doc
@@ -756,27 +758,23 @@ result(Received) -> Received.
contract_create(CreatorID, Path, InitArgs) -> contract_create(CreatorID, Path, InitArgs) ->
case next_nonce(CreatorID) of case next_nonce(CreatorID) of
{ok, Nonce} -> {ok, Nonce} ->
Deposit = 0,
Amount = 0, Amount = 0,
Gas = 100000, Gas = 100000,
GasPrice = min_gas_price(), GasPrice = min_gas_price(),
Fee = fee(), Fee = min_fee(),
contract_create(CreatorID, Nonce, contract_create(CreatorID, Nonce,
Deposit, Amount, Amount, Gas, GasPrice, Fee,
Gas, GasPrice, Fee,
Path, InitArgs); Path, InitArgs);
Error -> Error ->
Error Error
end. end.
-spec create_contract(CreatorID, Nonce, -spec contract_create(CreatorID, Nonce,
Deposit, Amount, Amount, Gas, GasPrice, Fee,
Gas, GasPrice, Fee,
Path, InitArgs) -> Result Path, InitArgs) -> Result
when CreatorID :: binary(), when CreatorID :: binary(),
Nonce :: pos_integer(), Nonce :: pos_integer(),
Deposit :: non_neg_integer(),
Amount :: non_neg_integer(), Amount :: non_neg_integer(),
Gas :: pos_integer(), Gas :: pos_integer(),
GasPrice :: pos_integer(), GasPrice :: pos_integer(),
@@ -813,11 +811,6 @@ contract_create(CreatorID, Path, InitArgs) ->
%% querying your Aeternity node (via `vanillae:next_nonce(CallerID)', for example). %% querying your Aeternity node (via `vanillae:next_nonce(CallerID)', for example).
%% </li> %% </li>
%% <li> %% <li>
%% <b>Deposit:</b>
%% I'm still not sure how to define this, so leave it at 0 for now.
%% Note to self: FIXME
%% </li>
%% <li>
%% <b>Amount:</b> %% <b>Amount:</b>
%% All Aeternity transactions can carry an "amount" spent from the origin account %% All Aeternity transactions can carry an "amount" spent from the origin account
%% (in this case the `CallerID') to the destination. In a "Spend" transaction this %% (in this case the `CallerID') to the destination. In a "Spend" transaction this
@@ -900,69 +893,64 @@ 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.
create_contract(CreatorID, Nonce, contract_create(CreatorID, Nonce,
Deposit, Amount, Amount, Gas, GasPrice, Fee,
Gas, GasPrice, Fee,
Path, InitArgs) -> Path, InitArgs) ->
case aeso_compiler:file(Path, [{aci, json}]) of case aeso_compiler:file(Path, [{aci, json}]) of
{ok, Compiled} -> {ok, Compiled} ->
contract_create2(CreatorID, Nonce, contract_create2(CreatorID, Nonce,
Deposit, Amount, Amount, Gas, GasPrice, Fee,
Gas, GasPrice, Fee,
Compiled, InitArgs); Compiled, InitArgs);
Error -> Error ->
Error Error
end. end.
contract_create2(CratorID, Nonce, contract_create2(CreatorID, Nonce,
Deposit, Amount, Amount, Gas, GasPrice, Fee,
Gas, GasPrice, Fee,
Compiled, InitArgs) -> Compiled, InitArgs) ->
AACI = prepare_aaci(maps:get(aci, Compiled)), AACI = prepare_aaci(maps:get(aci, Compiled)),
case encode_call_data(AACI, "init", InitArgs) of case encode_call_data(AACI, "init", InitArgs) of
{ok, CallData} -> {ok, CallData} ->
contract_create3(CreatorID, Nonce, contract_create3(CreatorID, Nonce,
Deposit, Amount, Amount, Gas, GasPrice, Fee,
Gas, GasPrice, Fee, Compiled, CallData);
Compiled, CallData, InitArgs);
Error -> Error ->
Error Error
end. end.
contract_create3(CreatorID, Nonce, contract_create3(CreatorID, Nonce,
Deposit, Amount, Amount, Gas, GasPrice, Fee,
Gas, GasPrice, Fee, Compiled, CallData) ->
Compiled, CallData, InitArgs) -> Code = aeser_contract_code:serialize(Compiled),
SophiaContractVersion = 3,
Code = aeser_contract_code:serialize(Compiled, SophiaContractVersion),
CTVersion = 2, CTVersion = 2,
ContractCreateVersion = 1,
TTL = 0, TTL = 0,
Type = contract_create_tx, Type = contract_create_tx,
Fields = Fields =
[{owner_id, aeser_id:create(account, Owner)}, [{owner_id, aeser_id:create(account, CreatorID)},
{nonce, Nonce}, {nonce, Nonce},
{code, Code}, {code, Code},
{ct_version, CTVersion}, {ct_version, CTVersion},
{fee, Fee}, {fee, Fee},
{ttl, TTL}, {ttl, TTL},
{deposit, Deposit}, {deposit, 0},
{amount, Amount}, {amount, Amount},
{gas, Gas}, {gas, Gas},
{gas_price, GasPrice}, {gas_price, GasPrice},
{call_data, CallData}], {call_data, CallData}],
Template = Template =
[{owner_id, id} [{owner_id, id},
{nonce, int} {nonce, int},
{code, binary} {code, binary},
{ct_version, int} {ct_version, int},
{fee, int} {fee, int},
{ttl, int} {ttl, int},
{deposit, int} {deposit, int},
{amount, int} {amount, int},
{gas, int} {gas, int},
{gas_price, int} {gas_price, int},
{call_data, binary}], {call_data, binary}],
TXB = aeser_chain_objects:serialize(Type, CallVersion, Template, Fields), TXB = aeser_chain_objects:serialize(Type, ContractCreateVersion, Template, Fields),
try try
{ok, aeser_api_encoder:encode(transaction, TXB)} {ok, aeser_api_encoder:encode(transaction, TXB)}
catch catch