Implement caching for compiled child contracts (#363)
This commit is contained in:
parent
c04f66a00a
commit
b474bb22cd
@ -176,17 +176,13 @@ lookup_var(#env{vars = Vars}, X) ->
|
|||||||
|
|
||||||
%% -- The compiler --
|
%% -- The compiler --
|
||||||
|
|
||||||
lit_to_fate(Env, L) ->
|
serialize_contract_code(Env, C) ->
|
||||||
case L of
|
Cache = case get(contract_code_cache) of
|
||||||
{int, N} -> aeb_fate_data:make_integer(N);
|
undefined -> put(contract_code_cache, #{}), #{};
|
||||||
{string, S} -> aeb_fate_data:make_string(S);
|
Res -> Res
|
||||||
{bytes, B} -> aeb_fate_data:make_bytes(B);
|
end,
|
||||||
{bool, B} -> aeb_fate_data:make_boolean(B);
|
case maps:get(C, Cache, none) of
|
||||||
{account_pubkey, K} -> aeb_fate_data:make_address(K);
|
none ->
|
||||||
{contract_pubkey, K} -> aeb_fate_data:make_contract(K);
|
|
||||||
{oracle_pubkey, K} -> aeb_fate_data:make_oracle(K);
|
|
||||||
{oracle_query_id, H} -> aeb_fate_data:make_oracle_query(H);
|
|
||||||
{contract_code, C} ->
|
|
||||||
Options = Env#env.options,
|
Options = Env#env.options,
|
||||||
FCode = maps:get(C, Env#env.child_contracts),
|
FCode = maps:get(C, Env#env.child_contracts),
|
||||||
FateCode = compile(Env#env.child_contracts, FCode, Options),
|
FateCode = compile(Env#env.child_contracts, FCode, Options),
|
||||||
@ -201,7 +197,22 @@ lit_to_fate(Env, L) ->
|
|||||||
payable => maps:get(payable, FCode)
|
payable => maps:get(payable, FCode)
|
||||||
},
|
},
|
||||||
Serialized = aeser_contract_code:serialize(Code),
|
Serialized = aeser_contract_code:serialize(Code),
|
||||||
aeb_fate_data:make_contract_bytearray(Serialized);
|
put(contract_code_cache, maps:put(C, Serialized, Cache)),
|
||||||
|
Serialized;
|
||||||
|
Serialized -> Serialized
|
||||||
|
end.
|
||||||
|
|
||||||
|
lit_to_fate(Env, L) ->
|
||||||
|
case L of
|
||||||
|
{int, N} -> aeb_fate_data:make_integer(N);
|
||||||
|
{string, S} -> aeb_fate_data:make_string(S);
|
||||||
|
{bytes, B} -> aeb_fate_data:make_bytes(B);
|
||||||
|
{bool, B} -> aeb_fate_data:make_boolean(B);
|
||||||
|
{account_pubkey, K} -> aeb_fate_data:make_address(K);
|
||||||
|
{contract_pubkey, K} -> aeb_fate_data:make_contract(K);
|
||||||
|
{oracle_pubkey, K} -> aeb_fate_data:make_oracle(K);
|
||||||
|
{oracle_query_id, H} -> aeb_fate_data:make_oracle_query(H);
|
||||||
|
{contract_code, C} -> aeb_fate_data:make_contract_bytearray(serialize_contract_code(Env, C));
|
||||||
{typerep, T} -> aeb_fate_data:make_typerep(type_to_scode(T))
|
{typerep, T} -> aeb_fate_data:make_typerep(type_to_scode(T))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user