提交 c3c5f413 编写于 作者: M Matias Romeo

Add API function to return account registered types

上级 f84c0287
...@@ -180,8 +180,8 @@ namespace eos { namespace chain { ...@@ -180,8 +180,8 @@ namespace eos { namespace chain {
} } // eos::chain } } // eos::chain
namespace fc { namespace fc {
void to_variant(const shared_vector<eos::types::Field>& c, fc::variant& v); void to_variant(const eos::chain::shared_vector<eos::types::Field>& c, fc::variant& v);
void from_variant(const fc::variant& v, shared_vector<eos::types::Field>& fields); void from_variant(const fc::variant& v, eos::chain::shared_vector<eos::types::Field>& fields);
} }
FC_REFLECT_ENUM(eos::chain::object_type, FC_REFLECT_ENUM(eos::chain::object_type,
......
...@@ -49,6 +49,7 @@ void chain_api_plugin::plugin_startup() { ...@@ -49,6 +49,7 @@ void chain_api_plugin::plugin_startup() {
app().get_plugin<http_plugin>().add_api({ app().get_plugin<http_plugin>().add_api({
CHAIN_RO_CALL(get_info), CHAIN_RO_CALL(get_info),
CHAIN_RO_CALL(get_block), CHAIN_RO_CALL(get_block),
CHAIN_RO_CALL(get_types),
CHAIN_RW_CALL(push_block), CHAIN_RW_CALL(push_block),
CHAIN_RW_CALL(push_transaction) CHAIN_RW_CALL(push_transaction)
}); });
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <eos/native_contract/native_contract_chain_initializer.hpp> #include <eos/native_contract/native_contract_chain_initializer.hpp>
#include <fc/io/json.hpp> #include <fc/io/json.hpp>
#include <fc/variant.hpp>
namespace eos { namespace eos {
...@@ -16,6 +17,8 @@ using fc::flat_map; ...@@ -16,6 +17,8 @@ using fc::flat_map;
using chain::block_id_type; using chain::block_id_type;
using chain::fork_database; using chain::fork_database;
using chain::block_log; using chain::block_log;
using chain::type_index;
using chain::by_scope_name;
class chain_plugin_impl { class chain_plugin_impl {
public: public:
...@@ -162,6 +165,23 @@ read_only::get_block_results read_only::get_block(const read_only::get_block_par ...@@ -162,6 +165,23 @@ read_only::get_block_results read_only::get_block(const read_only::get_block_par
"Could not find block: ${block}", ("block", params.block_num_or_id)); "Could not find block: ${block}", ("block", params.block_num_or_id));
} }
read_only::get_types_results read_only::get_types(const get_types_params& params) const {
auto& _db = app().get_plugin<database_plugin>().db();
auto& index = _db.get_index<type_index, by_scope_name>();
auto range = index.equal_range( boost::make_tuple( params.account_name ) );
get_types_results res;
for( const auto& to : boost::make_iterator_range( range.first, range.second ) ) {
fc::variant v;
fc::to_variant(to, v);
res.emplace_back(v);
}
return res;
}
read_write::push_block_results read_write::push_block(const read_write::push_block_params& params) { read_write::push_block_results read_write::push_block(const read_write::push_block_params& params) {
db.push_block(params); db.push_block(params);
return read_write::push_block_results(); return read_write::push_block_results();
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <eos/database_plugin/database_plugin.hpp> #include <eos/database_plugin/database_plugin.hpp>
namespace fc { class variant; }
namespace eos { namespace eos {
using eos::chain::chain_controller; using eos::chain::chain_controller;
using std::unique_ptr; using std::unique_ptr;
...@@ -35,6 +37,12 @@ public: ...@@ -35,6 +37,12 @@ public:
}; };
using get_block_results = chain::signed_block; using get_block_results = chain::signed_block;
get_block_results get_block(const get_block_params& params) const; get_block_results get_block(const get_block_params& params) const;
struct get_types_params {
string account_name;
};
using get_types_results = std::vector<fc::variant>;
get_types_results get_types(const get_types_params& params) const;
}; };
class read_write { class read_write {
...@@ -89,3 +97,4 @@ FC_REFLECT(eos::chain_apis::read_only::get_info_results, ...@@ -89,3 +97,4 @@ FC_REFLECT(eos::chain_apis::read_only::get_info_results,
(head_block_num)(head_block_id)(head_block_time)(head_block_producer) (head_block_num)(head_block_id)(head_block_time)(head_block_producer)
(recent_slots)(participation_rate)) (recent_slots)(participation_rate))
FC_REFLECT(eos::chain_apis::read_only::get_block_params, (block_num_or_id)) FC_REFLECT(eos::chain_apis::read_only::get_block_params, (block_num_or_id))
FC_REFLECT(eos::chain_apis::read_only::get_types_params, (account_name))
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册