Skip to content

Commit 8088be5

Browse files
committed
Squashed commit of the following:
Ability to make execute/call with preencoded data Run evm code on chain without deploying Improve ABI codec Add internal EVM runner watchdog upgrade eevm
1 parent a186da4 commit 8088be5

24 files changed

Lines changed: 1438 additions & 258 deletions

apps/tpnode/src/contract_evm.erl

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ deploy(#{from:=From,txext:=#{"code":=Code}=_TE}=Tx, Ledger, GasLimit, GetFun, Op
8282
balance => GetBalFun
8383
},
8484
data=>#{
85-
address=>binary:decode_unsigned(From),
85+
address=>binary:decode_unsigned(maps:get(address,Tx,From)),
8686
callvalue=>Value,
8787
caller=>binary:decode_unsigned(From),
8888
gasprice=>1,
@@ -160,9 +160,15 @@ encode_str(Bin) ->
160160
end*8,
161161
<<(size(Bin)):256/big,Bin/binary,0:Pad/big>>.
162162

163+
handle_tx(#{to:=To,from:=From,txext:=#{"code":=Code,"vm":= "evm"}}=Tx,
164+
Ledger, GasLimit, GetFun, Opaque) when To==From ->
165+
handle_tx_int(Tx, Ledger#{code=>Code}, GasLimit, GetFun, Opaque);
163166

164-
handle_tx(#{to:=To,from:=From}=Tx, #{code:=Code}=Ledger,
165-
GasLimit, GetFun, #{log:=PreLog}=Opaque) ->
167+
handle_tx(Tx, Ledger, GasLimit, GetFun, Opaque) ->
168+
handle_tx_int(Tx, Ledger, GasLimit, GetFun, Opaque).
169+
170+
handle_tx_int(#{to:=To,from:=From}=Tx, #{code:=Code}=Ledger,
171+
GasLimit, GetFun, #{log:=PreLog}=Opaque) ->
166172
State=case maps:get(state,Ledger,#{}) of
167173
BinState when is_binary(BinState) ->
168174
{ok,MapState}=msgpack:unpack(BinState),
@@ -538,16 +544,16 @@ tx_abi() ->
538544
{<<"t">>,uint256},
539545
{<<"seq">>,uint256},
540546
{<<"call">>,
541-
{array,{tuple,[{<<"func">>,string},
542-
{<<"args">>,{array,uint256}}]}}},
547+
{darray,{tuple,[{<<"func">>,string},
548+
{<<"args">>,{darray,uint256}}]}}},
543549
{<<"payload">>,
544-
{array,{tuple, [
550+
{darray,{tuple, [
545551
{<<"purpose">>,uint256},
546552
{<<"cur">>,string},
547553
{<<"amount">>,uint256}
548554
]}}},
549555
{<<"signatures">>,
550-
{array,{tuple,[{<<"raw">>,bytes},
556+
{darray,{tuple,[{<<"raw">>,bytes},
551557
{<<"timestamp">>,uint256},
552558
{<<"pubkey">>,bytes},
553559
{<<"rawkey">>,bytes},
@@ -690,7 +696,7 @@ embedded_blocks(<<1489993744:32/big,Bin/binary>>,#{getfun:=GetFun}=XAcc) -> %get
690696
Data=lists:sort([ PubKey || #{beneficiary := PubKey } <- Signatures]),
691697

692698
logger:notice("=== get_block: ~p",[Data]),
693-
RBin=contract_evm_abi:encode_abi([Data], [{<<>>, {array,bytes}}]),
699+
RBin=contract_evm_abi:encode_abi([Data], [{<<>>, {darray,bytes}}]),
694700
{1,RBin,XAcc}
695701
catch Ec:Ee ->
696702
logger:info("decode_abi error: ~p:~p~n",[Ec,Ee]),
@@ -703,7 +709,7 @@ embedded_blocks(<<Sig:32/big,_/binary>>,XAcc) ->
703709

704710
embedded_settings(<<3410561484:32/big,Bin/binary>>,#{getfun:=GetFun}=XAcc) -> %byPath(string[])
705711
try
706-
[{<<"key">>,Path}]=contract_evm_abi:decode_abi(Bin,[{<<"key">>,{array,string}}]),
712+
[{<<"key">>,Path}]=contract_evm_abi:decode_abi(Bin,[{<<"key">>,{darray,string}}]),
707713
SRes=GetFun({settings,Path}),
708714
RBin=enc_settings1(SRes),
709715
{1,RBin,XAcc}
@@ -740,7 +746,7 @@ embedded_settings(<<Sig:32/big,_/binary>>,XAcc) ->
740746
embedded_lstore(<<16#8D0FE062:32/big,Bin/binary>>,
741747
#{data:=#{address:=A}},
742748
#{getfun:=GetFun}=XAcc) ->% getByPath(bytes[])
743-
InABI=[{<<"key">>,{array,bytes}}],
749+
InABI=[{<<"key">>,{darray,bytes}}],
744750
try
745751
[{<<"key">>,Path}]=contract_evm_abi:decode_abi(Bin,InABI),
746752

@@ -761,7 +767,7 @@ embedded_lstore(<<16#8D0FE062:32/big,Bin/binary>>,
761767
embedded_lstore(<<2693574879:32/big,Bin/binary>>,
762768
#{data:=#{address:=_A}},
763769
#{getfun:=GetFun}=XAcc) ->% getByPath(address,bytes[])
764-
InABI=[{<<"address">>,address},{<<"key">>,{array,bytes}}],
770+
InABI=[{<<"address">>,address},{<<"key">>,{darray,bytes}}],
765771
try
766772
[{<<"address">>,Addr},{<<"key">>,Path}]=contract_evm_abi:decode_abi(Bin,InABI),
767773

@@ -783,7 +789,7 @@ embedded_lstore(<<2956342894:32/big,Bin/binary>>,
783789
#{data:=#{address:=OwnerI}},
784790
#{global_acc:=GA=#{table:=Addresses}}=XAcc) ->% setByPath(bytes[],uint256,bytes)
785791
Owner=binary:encode_unsigned(OwnerI),
786-
InABI=[{<<"p">>,{array,bytes}}, {<<"t">>,uint256}, {<<"v">>,bytes}],
792+
InABI=[{<<"p">>,{darray,bytes}}, {<<"t">>,uint256}, {<<"v">>,bytes}],
787793
try
788794
hex:hexdump(Bin),
789795
io:format("Bin ~4000p~n",[Bin]),
@@ -815,7 +821,7 @@ enc_settings1(SRes) ->
815821
OutABI=[{<<"datatype">>,uint256},
816822
{<<"res_bin">>,bytes},
817823
{<<"res_int">>,uint256},
818-
{<<"keys">>,{array,{tuple,[{<<"datatype">>,uint256},
824+
{<<"keys">>,{darray,{tuple,[{<<"datatype">>,uint256},
819825
{<<"res_bin">>,bytes}]}}}],
820826
EncSub=fun(Sub) ->
821827
[ if is_atom(A) -> [5, atom_to_binary(A)];
@@ -848,8 +854,21 @@ ask_if_wants_to_pay(Code, Tx, Gas) ->
848854
%{ok,{_,OutABI,_}}=contract_evm_abi:parse_signature(
849855
% "(string iWillPay,(uint256 purpose,string cur,uint256 amount)[] pay)"
850856
% ),
851-
InABI=[{<<>>,{tuple,[{<<>>,uint256},{<<>>,address},{<<>>,address},{<<>>,uint256},{<<>>,uint256},{<<>>,{array,{tuple,[{<<>>,string},{<<>>,{array,uint256}}]}}},{<<>>,{array,{tuple,[{<<>>,uint256},{<<>>,string},{<<>>,uint256}]}}},{<<>>,{array,{tuple,[{<<>>,bytes},{<<>>,uint256},{<<>>,bytes},{<<>>,bytes},{<<>>,bytes}]}}}]}}],
852-
OutABI=[{<<"iWillPay">>,string},{<<"pay">>,{array,{tuple,[{<<"purpose">>,uint256},{<<"cur">>,string},{<<"amount">>,uint256}]}}}],
857+
InABI=[{<<>>,{tuple,[{<<>>,uint256},
858+
{<<>>,address},
859+
{<<>>,address},
860+
{<<>>,uint256},
861+
{<<>>,uint256},
862+
{<<>>,{darray,{tuple,[{<<>>,string},{<<>>,{darray,uint256}}]}}},
863+
{<<>>,{darray,{tuple,[{<<>>,uint256},{<<>>,string},{<<>>,uint256}]}}},
864+
{<<>>,{darray,{tuple,[
865+
{<<>>,bytes},
866+
{<<>>,uint256},
867+
{<<>>,bytes},
868+
{<<>>,bytes},
869+
{<<>>,bytes}]}}}
870+
]}}],
871+
OutABI=[{<<"iWillPay">>,string},{<<"pay">>,{darray,{tuple,[{<<"purpose">>,uint256},{<<"cur">>,string},{<<"amount">>,uint256}]}}}],
853872
{ok,PTx}=preencode_tx(Tx,[]),
854873

855874
CD=callcd(Function, [PTx], InABI),

0 commit comments

Comments
 (0)