From b37f1e1efe181da29bea4a73c3a58335a3dda50a Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Sat, 1 Mar 2025 14:00:44 +0900 Subject: [PATCH] Expose complete deployment parameters --- src/hz.erl | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/hz.erl b/src/hz.erl index 948f1ef..2335cbd 100644 --- a/src/hz.erl +++ b/src/hz.erl @@ -62,6 +62,7 @@ min_gas_price/0, contract_create/3, contract_create_built/3, + contract_create_built/8, contract_create/8, prepare_contract/1, prepare_aaci/1, @@ -1025,6 +1026,16 @@ contract_create(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Path, InitArgs) -> end. +contract_create2(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Source, Options, InitArgs) -> + case so_compiler:from_string(Source, Options) of + {ok, Compiled} -> + contract_create_built(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, + Compiled, InitArgs); + Error -> + Error + end. + + -spec contract_create_built(CreatorID, Compiled, InitArgs) -> Result when CreatorID :: unicode:chardata(), Compiled :: map(), @@ -1045,43 +1056,35 @@ contract_create_built(CreatorID, Compiled, InitArgs) -> TTL = Height + 262980, Gas = 500000, GasPrice = min_gas_price(), - contract_create3(CreatorID, Nonce, - Amount, TTL, Gas, GasPrice, - Compiled, InitArgs); + contract_create_built(CreatorID, Nonce, + Amount, TTL, Gas, GasPrice, + Compiled, InitArgs); Error -> Error end. -contract_create2(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Source, Options, InitArgs) -> - case so_compiler:from_string(Source, Options) of - {ok, Compiled} -> - contract_create3(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, - Compiled, InitArgs); - Error -> - Error - end. - -contract_create3(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, InitArgs) -> +contract_create_built(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, - Compiled, CallData); + assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, + Compiled, CallData); Error -> Error end. -contract_create4(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) -> + +assemble_calldata(CreatorID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) -> PK = unicode:characters_to_binary(CreatorID), try {account_pubkey, OwnerID} = gmser_api_encoder:decode(PK), - contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) + assemble_calldata2(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) catch Error:Reason -> {Error, Reason} end. -contract_create5(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) -> +assemble_calldata2(OwnerID, Nonce, Amount, TTL, Gas, GasPrice, Compiled, CallData) -> Code = gmser_contract_code:serialize(Compiled), Source = unicode:characters_to_binary(maps:get(contract_source, Compiled, <<>>)), VM = 1, -- 2.30.2