BitShares-Core
7.0.2
BitShares blockchain node software and command-line wallet software
|
Go to the documentation of this file.
5 namespace fc {
namespace rpc {
18 FC_ASSERT( args.size() == 3 && args[2].is_array() );
20 if( args[0].is_string() )
26 api_id = args[0].as_uint64();
31 args[2].get_array() );
36 FC_ASSERT( args.size() == 2 && args[1].is_array() );
43 FC_ASSERT( args.size() == 2 && args[1].is_array() );
53 _connection->on_message_handler( [
this](
const std::string& msg ){
59 _connection->on_http_handler( [
this](
const std::string& msg ){
64 if( reply.
error->code == -32603 )
66 else if( reply.
error->code <= -32600 )
113 uint64_t callback_id,
138 return response(
variant(), { -32600,
"Batch requests not supported" },
"2.0" );
141 return response(
variant(), { -32600,
"Invalid JSON request" },
"2.0" );
146 && !var_obj[
"id"].is_string() && !var_obj[
"id"].is_numeric() && !var_obj[
"id"].is_null() )
149 if( var_obj.
contains(
"method" ) && ( !var_obj[
"method"].is_string() || var_obj[
"method"].get_string() ==
"" ) )
150 return response(
variant(), { -32600,
"Missing or invalid method" },
"2.0" );
152 if( var_obj.
contains(
"jsonrpc" ) && ( !var_obj[
"jsonrpc"].is_string() || var_obj[
"jsonrpc"] !=
"2.0" ) )
153 return response(
variant(), { -32600,
"Unsupported JSON-RPC version" },
"2.0" );
157 if( var_obj.
contains(
"params" ) && var_obj[
"params"].is_object() )
158 return response(
variant(), { -32602,
"Named parameters not supported" },
"2.0" );
160 if( var_obj.
contains(
"params" ) && !var_obj[
"params"].is_array() )
168 if( !var_obj.
contains(
"id" ) || ( var_obj[
"id"].is_null() && !var_obj.
contains(
"jsonrpc" ) ) )
169 return response(
variant(), { -32600,
"Missing or invalid id" },
"2.0" );
176 return response(
variant(), { -32600,
"Missing method or result or error" },
"2.0" );
205 elog(
"API call execution time limit exceeded. method: ${m} params: ${p} time: ${t}",
208 wlog(
"API call execution time nearing limit. method: ${m} params: ${p} time: ${t}",
215 catch (
const fc::method_not_found_exception& e )
219 variant( (fc::exception) e, _max_conversion_depth ) }, call.
jsonrpc );
225 variant( e, _max_conversion_depth ) },
228 catch (
const std::exception& e )
230 elog(
"Internal error - ${e}", (
"e",e.what()) );
231 return response( call.
id,
error_object{ -32603,
"Internal error", variant( e.what(), _max_conversion_depth ) },
236 elog(
"Internal error while processing RPC request" );
void handle_reply(const response &response)
microseconds milliseconds(int64_t s)
An order-perserving dictionary of variant's.
void add_method(const std::string &name, method m)
virtual variant send_callback(uint64_t callback_id, variants args=variants()) override
fc::rpc::state _rpc_state
std::string body_as_string
Used to generate a useful error report when an exception is thrown.
~websocket_api_connection()
bool contains(const char *key) const
variant wait_for_response(const variant &request_id)
uint64_t as_uint64() const
optional< std::string > jsonrpc
void on_unhandled(const std::function< variant(const string &, const variants &)> &unhandled)
static variant from_string(const string &utf8_str, parse_type ptype=legacy_parser, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
static string to_string(const variant &v, output_formatting format=stringify_large_ints_and_doubles, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
@ stringify_large_ints_and_doubles
fc::signal< void()> closed
std::vector< variant > variants
response on_message(const std::string &message)
request start_remote_call(const string &method_name, variants args)
T as(uint32_t max_depth) const
optional< std::string > jsonrpc
virtual variant send_call(api_id_type api_id, string method_name, variants args=variants()) override
response on_request(const variant &message)
void on_response(const variant &message)
optional< fc::variant > result
virtual void send_notice(uint64_t callback_id, variants args=variants()) override
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
variant_object & get_object()
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
void receive_notice(uint64_t callback_id, const variants &args=variants()) const
variant receive_call(api_id_type api_id, const string &method_name, const variants &args=variants()) const
const uint32_t _max_conversion_depth
variant receive_callback(uint64_t callback_id, const variants &args=variants()) const
std::shared_ptr< fc::http::websocket_connection > _connection
websocket_api_connection(const std::shared_ptr< fc::http::websocket_connection > &c, uint32_t max_conversion_depth)
variant local_call(const string &method_name, const variants &args)
provides stack-based nullable value similar to boost::optional
optional< error_object > error