WIP: Adding contract_create_built/3

This commit is contained in:
Craig Everett 2024-12-09 15:00:21 +09:00
parent dbf4f6bdb2
commit 06fc0ac403
13 changed files with 49 additions and 14 deletions

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
.eunit
deps
cancer
*.o
*.beam
*.plt
*.swp
erl_crash.dump
ebin/*.beam
doc/*.html
doc/*.css
doc/edoc-info
doc/erlang.png
rel/example_project
.concrete/DEV_MODE
.rebar

View File

@ -3,6 +3,6 @@
{included_applications,[]},
{applications,[stdlib,kernel]},
{description,"Gajumaru interoperation library"},
{vsn,"0.1.0"},
{vsn,"0.2.0"},
{modules,[hakuzaru,hz,hz_fetcher,hz_man,hz_sup]},
{mod,{hakuzaru,[]}}]}.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,7 +6,7 @@
%%% @end
-module(hakuzaru).
-vsn("0.4.1").
-vsn("0.2.0").
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").
-license("GPL-3.0-or-later").

View File

@ -23,7 +23,7 @@
%%% @end
-module(hz).
-vsn("0.4.1").
-vsn("0.2.0").
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").
-license("GPL-3.0-or-later").
@ -61,6 +61,7 @@
min_gas/0,
min_gas_price/0,
contract_create/3,
contract_create_built/3,
contract_create/8,
prepare_contract/1,
aaci_lookup_spec/2,
@ -1012,36 +1013,54 @@ contract_create(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Path, InitArgs) ->
Error
end.
contract_create_built(CreatorID, Compiled, InitArgs) ->
case next_nonce(CreatorID) of
{ok, Nonce} ->
Amount = 0,
{ok, Height} = top_height(),
TTL = Height + 262980,
Gas = 500000,
GasPrice = min_gas_price(),
contract_create3(CreatorID, Nonce,
Amount, TTL, Gas, GasPrice,
Compiled, InitArgs);
Error ->
Error
end.
contract_create2(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Source, Options, InitArgs) ->
case aeso_compiler:from_string(Source, Options) of
{ok, Compiled} ->
contract_create3(CreatorID, Nonce, Amount, TTL, Gas, GasPrice,
Source, Compiled, InitArgs);
Compiled, InitArgs);
Error ->
Error
end.
contract_create3(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Source, Compiled, InitArgs) ->
contract_create3(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) ->
AACI = prepare_aaci(maps:get(aci, Compiled)),
case encode_call_data(AACI, "init", InitArgs) of
{ok, CallData} ->
contract_create4(CreatorID, Nonce, Amount, TTL, Gas, GasPrice,
Source, Compiled, CallData);
Compiled, CallData);
Error ->
Error
end.
contract_create4(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Source, Compiled, CallData) ->
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),
contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Source, Compiled, CallData)
contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData)
catch
Error:Reason -> {Error, Reason}
end.
contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Source, Compiled, CallData) ->
contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) ->
Code = aeser_contract_code:serialize(Compiled),
Source = maps:get(contract_source, Compiled, <<>>),
VM = 1,
ABI = 1,
<<CTVersion:32>> = <<VM:16, ABI:16>>,

View File

@ -1,5 +1,5 @@
-module(hz_fetcher).
-vsn("0.4.1").
-vsn("0.2.0").
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").
-license("MIT").

View File

@ -9,7 +9,7 @@
%%% @end
-module(hz_man).
-vsn("0.4.1").
-vsn("0.2.0").
-behavior(gen_server).
-author("Craig Everett <ceverett@tsuriai.jp>").
-copyright("Craig Everett <ceverett@tsuriai.jp>").

View File

@ -9,7 +9,7 @@
%%% @end
-module(hz_sup).
-vsn("0.4.1").
-vsn("0.2.0").
-behaviour(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -1,10 +1,10 @@
{name,"Hakuzaru"}.
{type,app}.
{modules,[]}.
{author,"Craig Everett"}.
{prefix,"hz"}.
{desc,"Gajumaru interoperation library"}.
{package_id,{"otpr","hakuzaru",{0,1,0}}}.
{author,"Craig Everett"}.
{package_id,{"otpr","hakuzaru",{0,2,0}}}.
{deps,[{"otpr","erl_base58",{0,1,0}},
{"otpr","ec_utils",{1,0,0}},
{"otpr","aebytecode",{3,2,1}},