diff --git a/src/hera.cpp b/src/hera.cpp index ab3f84a01..2de151753 100644 --- a/src/hera.cpp +++ b/src/hera.cpp @@ -74,6 +74,40 @@ bool hasWasmPreamble(vector const& _input) { _input[7] == 0; } +bool deploySystemContract(string & code, evmc_address addr) { + evmc_message create_message; + create_message.input_data = reinterpret_cast(code.c_str()); + create_message.destination = addr; + + //Prepare message call to deploy system contract + + return true; +} + +void preloadSystemContracts(hera_instance *hera) { + auto const& list = hera->contract_preload_list; + + //Iterate through every entry on the contract preload list and deploy the code at the address from the filepath + for (size_t i = 0; i < list.size(); ++i) { + ifstream path; + path.open(list[i].second, ios::in | ios::binary); + + if (path.is_open()) { +#if HERA_DEBUGGING + cerr << "Loading code at " << list[i].second << " into address " << hex << list[i].first.bytes << dec << endl; +#endif + string bytecode((istreambuf_iterator(path)), + istreambuf_iterator()); + deploySystemContract(bytecode, list[i].first); + } else { +#if HERA_DEBUGGING + cerr << "Could not open filepath " << list[i].second << endl; +#endif + continue; + } + } +} + vector callSystemContract( evmc_context* context, evmc_address const& address, @@ -332,6 +366,8 @@ evmc_result hera_execute( ) noexcept { hera_instance* hera = static_cast(instance); + preloadSystemContracts(hera); + evmc_result ret; memset(&ret, 0, sizeof(evmc_result));