Skip to content

Commit

Permalink
Add get_supported_apis rpc api
Browse files Browse the repository at this point in the history
  • Loading branch information
conr2d committed Jan 11, 2019
1 parent 804261f commit 4205c24
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,22 @@ namespace eosio {
throw;
}
}

#define CALL(api_name, call_name, http_response_code) \
{std::string("/v1/" #api_name "/" #call_name), \
[&](string, string body, url_response_callback cb) mutable { \
try { \
if (body.empty()) body = "{}"; \
auto result = (*this).call_name(); \
cb(http_response_code, fc::json::to_string(result)); \
} catch (...) { \
http_plugin::handle_exception(#api_name, #call_name, body, cb); \
} \
}}

add_api({
CALL(node, get_supported_apis, 200)
});
}

void http_plugin::plugin_shutdown() {
Expand Down Expand Up @@ -615,4 +631,13 @@ namespace eosio {
return verbose_http_errors;
}

http_plugin::get_supported_apis_result http_plugin::get_supported_apis()const {
get_supported_apis_result result;

for (const auto& handler : my->url_handlers) {
result.apis.emplace_back(handler.first);
}

return result;
}
}
7 changes: 7 additions & 0 deletions plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ namespace eosio {

bool verbose_errors()const;

struct get_supported_apis_result {
vector<string> apis;
};

get_supported_apis_result get_supported_apis()const;

private:
std::unique_ptr<class http_plugin_impl> my;
};
Expand Down Expand Up @@ -152,3 +158,4 @@ namespace eosio {
FC_REFLECT(eosio::error_results::error_info::error_detail, (message)(file)(line_number)(method))
FC_REFLECT(eosio::error_results::error_info, (code)(name)(what)(details))
FC_REFLECT(eosio::error_results, (code)(message)(error))
FC_REFLECT(eosio::http_plugin::get_supported_apis_result, (apis))

0 comments on commit 4205c24

Please sign in to comment.