-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo_history_api_plugin.cpp
53 lines (41 loc) · 1.9 KB
/
mongo_history_api_plugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include <eosio/mongo_history_api_plugin/mongo_history_api_plugin.hpp>
#include <eosio/chain/exceptions.hpp>
#include <fc/io/json.hpp>
namespace eosio {
using namespace eosio;
static appbase::abstract_plugin& _mongo_history_api_plugin = app().register_plugin<mongo_history_api_plugin>();
mongo_history_api_plugin::mongo_history_api_plugin(){}
mongo_history_api_plugin::~mongo_history_api_plugin(){}
void mongo_history_api_plugin::set_program_options(options_description&, options_description&) {}
void mongo_history_api_plugin::plugin_initialize(const variables_map&) {}
#define CALL(api_name, api_handle, api_namespace, call_name) \
{std::string("/v1/" #api_name "/" #call_name), \
[api_handle](string, string body, url_response_callback cb) mutable { \
try { \
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 (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
}}
#define CHAIN_RO_CALL(call_name) CALL(history, ro_api, mongo_history_apis::read_only, call_name)
//#define CHAIN_RW_CALL(call_name) CALL(history, rw_api, history_apis::read_write, call_name)
void mongo_history_api_plugin::plugin_startup() {
ilog( "starting mongo_history_api_plugin" );
auto ro_api = app().get_plugin<mongo_history_plugin>().get_read_only_api();
//auto rw_api = app().get_plugin<history_plugin>().get_read_write_api();
app().get_plugin<http_plugin>().add_api({
// CHAIN_RO_CALL(get_transaction),
CHAIN_RO_CALL(get_actions),
CHAIN_RO_CALL(get_transaction),
CHAIN_RO_CALL(get_key_accounts),
CHAIN_RO_CALL(get_controlled_accounts)
});
}
void mongo_history_api_plugin::plugin_shutdown() {}
}