提交 5e61e56d 编写于 作者: N Nathan Hourt

Progress #14: Add get_block call

Add get_block call to chain read_only api
上级 ead686b6
......@@ -29,6 +29,9 @@ void chain_api_plugin::plugin_initialize(const variables_map&) {}
if (body.empty()) body = "{}"; \
auto result = api_handle.call_name(fc::json::from_string(body).as<api_namespace::call_name ## _params>()); \
cb(200, fc::json::to_string(result)); \
} catch (fc::eof_exception) { \
cb(400, "Invalid arguments"); \
elog("Unable to parse arguments: ${args}", ("args", body)); \
} catch (fc::exception& e) { \
cb(500, e.what()); \
elog("Exception encountered while processing ${call}: ${e}", ("call", #api_name "." #call_name)("e", e)); \
......@@ -39,7 +42,8 @@ void chain_api_plugin::plugin_startup() {
auto ro_api = app().get_plugin<chain_plugin>().get_read_only_api();
app().get_plugin<http_plugin>().add_api({
CALL(chain, ro_api, chain_apis::read_only, get_info)
CALL(chain, ro_api, chain_apis::read_only, get_info),
CALL(chain, ro_api, chain_apis::read_only, get_block)
});
}
......
......@@ -159,5 +159,19 @@ read_only::get_info_results read_only::get_info(const read_only::get_info_params
};
}
read_only::get_block_results read_only::get_block(const read_only::get_block_params& params) const {
try {
if (auto block = db.fetch_block_by_id(fc::json::from_string(params.block_num_or_id).as<chain::block_id_type>()))
return *block;
} catch (fc::bad_cast_exception) {/* do nothing */}
try {
if (auto block = db.fetch_block_by_number(fc::to_uint64(params.block_num_or_id)))
return *block;
} catch (fc::bad_cast_exception) {/* do nothing */}
FC_THROW_EXCEPTION(chain::unknown_block_exception,
"Could not find block: ${block}", ("block", params.block_num_or_id));
}
} // namespace chain_apis
} // namespace eos
......@@ -27,6 +27,12 @@ public:
double participation_rate;
};
get_info_results get_info(const get_info_params&) const;
struct get_block_params {
string block_num_or_id;
};
using get_block_results = chain::signed_block;
get_block_results get_block(const get_block_params& params) const;
};
} // namespace chain_apis
......@@ -65,3 +71,4 @@ FC_REFLECT(eos::chain_apis::empty, )
FC_REFLECT(eos::chain_apis::read_only::get_info_results,
(head_block_num)(head_block_id)(head_block_time)(head_block_producer)
(recent_slots)(participation_rate))
FC_REFLECT(eos::chain_apis::read_only::get_block_params, (block_num_or_id))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册