From 89037a0b71df7a7f04a4b199093594d89ee05fac Mon Sep 17 00:00:00 2001 From: Alexander Jung <104335080+AlexRamRam@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:58:11 -0400 Subject: [PATCH] In http_server::exec_tx() fix error propagation via json value object Signed-off-by: Alexander Jung <104335080+AlexRamRam@users.noreply.github.com> --- src/3pc/agent/runners/evm/http_server.cpp | 56 +++++++++++------------ src/3pc/agent/runners/evm/http_server.hpp | 13 +++--- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/3pc/agent/runners/evm/http_server.cpp b/src/3pc/agent/runners/evm/http_server.cpp index 05296e8f9..4b5636c67 100644 --- a/src/3pc/agent/runners/evm/http_server.cpp +++ b/src/3pc/agent/runners/evm/http_server.cpp @@ -1307,29 +1307,40 @@ namespace cbdc::threepc::agent::rpc { } auto http_server::exec_tx( - const server_type::result_callback_type& callback, + const server_type::result_callback_type& json_ret_callback, runner::evm_runner_function f_type, cbdc::buffer& runner_params, bool is_readonly_run, - std::function res_cb) -> bool { + const std::function& res_success_cb) + -> bool { auto function = cbdc::buffer(); function.append(&f_type, sizeof(f_type)); - auto cb = [res_cb, callback](interface::exec_return_type res) { - if(!std::holds_alternative(res)) { - auto ec = std::get(res); - auto ret = Json::Value(); - ret["error"] = Json::Value(); - ret["error"]["code"] - = error_code::execution_error - static_cast(ec); - ret["error"]["message"] = "Execution error"; - callback(ret); - return; - } + auto id = m_next_id++; - res_cb(res); - }; + const auto res_cb_for_agent = + [this, id, res_success_cb, json_ret_callback]( + interface::exec_return_type res) { + const auto success = std::holds_alternative(res); + if(success) { + res_success_cb(res); + m_cleanup_queue.push(id); + } else { + // Handle error: + const auto ec = std::get(res); + + if(ec == interface::error_code::retry) { + m_retry_queue.push(id); + } else { + auto ret = Json::Value(); + ret["error"] = Json::Value(); + ret["error"]["code"] = error_code::execution_error + - static_cast(ec); + ret["error"]["message"] = "Execution error"; + json_ret_callback(ret); + } + } + }; - auto id = m_next_id++; auto a = [&]() { auto agent = std::make_shared( m_log, @@ -1338,18 +1349,7 @@ namespace cbdc::threepc::agent::rpc { m_broker, function, runner_params, - [this, id, res_cb](interface::exec_return_type res) { - auto success = std::holds_alternative(res); - if(!success) { - auto ec = std::get(res); - if(ec == interface::error_code::retry) { - m_retry_queue.push(id); - return; - } - } - res_cb(res); - m_cleanup_queue.push(id); - }, + res_cb_for_agent, runner::evm_runner::initial_lock_type, is_readonly_run, m_secp, diff --git a/src/3pc/agent/runners/evm/http_server.hpp b/src/3pc/agent/runners/evm/http_server.hpp index 3313929df..2cd63261e 100644 --- a/src/3pc/agent/runners/evm/http_server.hpp +++ b/src/3pc/agent/runners/evm/http_server.hpp @@ -200,12 +200,13 @@ namespace cbdc::threepc::agent::rpc { cbdc::buffer)>& res_cb) -> bool; - auto exec_tx(const server_type::result_callback_type& callback, - runner::evm_runner_function f_type, - cbdc::buffer& runner_params, - bool is_readonly_run, - std::function res_cb) - -> bool; + auto + exec_tx(const server_type::result_callback_type& json_ret_callback, + runner::evm_runner_function f_type, + cbdc::buffer& runner_params, + bool is_readonly_run, + const std::function& + res_success_cb) -> bool; auto handle_unsupported(const std::string& method,