eos智能合約執行web
1. 執行流程api
controller::push_transaction() // 事務app
-> transaction_context::exec() // 事務函數
-> transaction_context::dispatch_action() // 經過便利transaction中的各個action來分發執行this
-> apply_context::exec() // actionspa
-> apply_context::exec_one() // action 執行具體的智能合約code
-> controller::get_wasm_interface()->apply() // 進入虛擬機開始執行對應智能合約事務
-> wasm_interface_impl::get_instantiated_module()->apply() // 加載智能合約並執行get
-> wavm_instantiated_module::apply() // 具體模塊開始接收調用虛擬機
-> wavm_instantiated_module::call() // 開始執行具體函數
-> Runtime::invokeFunction() // 進入到wasm運行時庫開始執行具體函數
2. 分析exec_one
/**
* IMPORTENT:執行具體action
*/
void apply_context::exec_one(action_trace &trace)
{
auto start = fc::time_point::now();
...略
const auto &cfg = control.get_global_properties().configuration;
try
{
try
{
/**
* 接收者信息,智能合約帳號?應該是對應爲eosio
*/
const auto &a = control.get_account(receiver);
privileged = a.privileged;
/**
* IMPORTENT:智能合約查找apply_handler,Native是原生api
*/
auto native = control.find_apply_handler(receiver, act.account, act.name);
if (native)
{
...略...
...內置API調用
(*native)(*this);
}
/**
* IMPORTENT:智能合約,a.code?這部分是代碼?智能合約帳號對應code就是合約代碼
*/
if (a.code.size() > 0 && !(act.account == config::system_account_name && act.name == N(setcode) &&
receiver == config::system_account_name))
{
...略...
try
{
/**
* IMPORTENT:執行智能合約
*/
control.get_wasm_interface().apply(a.code_version, a.code, *this);
}
catch (const wasm_exit &)
{
}
}
}
FC_RETHROW_EXCEPTIONS(warn, "pending console output: ${console}", ("console", _pending_console_output.str()))
}
catch (fc::exception &e)
{
...
throw;
}
...
}