Skip to content

Commit 89037a0

Browse files
committed
In http_server::exec_tx() fix error propagation via json value object
Signed-off-by: Alexander Jung <[email protected]>
1 parent 75fcb76 commit 89037a0

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/3pc/agent/runners/evm/http_server.cpp

+28-28
Original file line numberDiff line numberDiff line change
@@ -1307,29 +1307,40 @@ namespace cbdc::threepc::agent::rpc {
13071307
}
13081308

13091309
auto http_server::exec_tx(
1310-
const server_type::result_callback_type& callback,
1310+
const server_type::result_callback_type& json_ret_callback,
13111311
runner::evm_runner_function f_type,
13121312
cbdc::buffer& runner_params,
13131313
bool is_readonly_run,
1314-
std::function<void(interface::exec_return_type)> res_cb) -> bool {
1314+
const std::function<void(interface::exec_return_type)>& res_success_cb)
1315+
-> bool {
13151316
auto function = cbdc::buffer();
13161317
function.append(&f_type, sizeof(f_type));
1317-
auto cb = [res_cb, callback](interface::exec_return_type res) {
1318-
if(!std::holds_alternative<return_type>(res)) {
1319-
auto ec = std::get<interface::error_code>(res);
1320-
auto ret = Json::Value();
1321-
ret["error"] = Json::Value();
1322-
ret["error"]["code"]
1323-
= error_code::execution_error - static_cast<int>(ec);
1324-
ret["error"]["message"] = "Execution error";
1325-
callback(ret);
1326-
return;
1327-
}
1318+
auto id = m_next_id++;
13281319

1329-
res_cb(res);
1330-
};
1320+
const auto res_cb_for_agent =
1321+
[this, id, res_success_cb, json_ret_callback](
1322+
interface::exec_return_type res) {
1323+
const auto success = std::holds_alternative<return_type>(res);
1324+
if(success) {
1325+
res_success_cb(res);
1326+
m_cleanup_queue.push(id);
1327+
} else {
1328+
// Handle error:
1329+
const auto ec = std::get<interface::error_code>(res);
1330+
1331+
if(ec == interface::error_code::retry) {
1332+
m_retry_queue.push(id);
1333+
} else {
1334+
auto ret = Json::Value();
1335+
ret["error"] = Json::Value();
1336+
ret["error"]["code"] = error_code::execution_error
1337+
- static_cast<int>(ec);
1338+
ret["error"]["message"] = "Execution error";
1339+
json_ret_callback(ret);
1340+
}
1341+
}
1342+
};
13311343

1332-
auto id = m_next_id++;
13331344
auto a = [&]() {
13341345
auto agent = std::make_shared<impl>(
13351346
m_log,
@@ -1338,18 +1349,7 @@ namespace cbdc::threepc::agent::rpc {
13381349
m_broker,
13391350
function,
13401351
runner_params,
1341-
[this, id, res_cb](interface::exec_return_type res) {
1342-
auto success = std::holds_alternative<return_type>(res);
1343-
if(!success) {
1344-
auto ec = std::get<interface::error_code>(res);
1345-
if(ec == interface::error_code::retry) {
1346-
m_retry_queue.push(id);
1347-
return;
1348-
}
1349-
}
1350-
res_cb(res);
1351-
m_cleanup_queue.push(id);
1352-
},
1352+
res_cb_for_agent,
13531353
runner::evm_runner::initial_lock_type,
13541354
is_readonly_run,
13551355
m_secp,

src/3pc/agent/runners/evm/http_server.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,13 @@ namespace cbdc::threepc::agent::rpc {
200200
cbdc::buffer)>& res_cb)
201201
-> bool;
202202

203-
auto exec_tx(const server_type::result_callback_type& callback,
204-
runner::evm_runner_function f_type,
205-
cbdc::buffer& runner_params,
206-
bool is_readonly_run,
207-
std::function<void(interface::exec_return_type)> res_cb)
208-
-> bool;
203+
auto
204+
exec_tx(const server_type::result_callback_type& json_ret_callback,
205+
runner::evm_runner_function f_type,
206+
cbdc::buffer& runner_params,
207+
bool is_readonly_run,
208+
const std::function<void(interface::exec_return_type)>&
209+
res_success_cb) -> bool;
209210

210211
auto
211212
handle_unsupported(const std::string& method,

0 commit comments

Comments
 (0)