FC Updates from BitShares and myself #21
1 changed files with 24 additions and 26 deletions
|
|
@ -11,7 +11,7 @@ websocket_api_connection::websocket_api_connection( const std::shared_ptr<fc::ht
|
||||||
uint32_t max_depth )
|
uint32_t max_depth )
|
||||||
: api_connection(max_depth),_connection(c)
|
: api_connection(max_depth),_connection(c)
|
||||||
{
|
{
|
||||||
FC_ASSERT( c );
|
FC_ASSERT( _connection, "A valid websocket connection is required" );
|
||||||
_rpc_state.add_method( "call", [this]( const variants& args ) -> variant
|
_rpc_state.add_method( "call", [this]( const variants& args ) -> variant
|
||||||
{
|
{
|
||||||
FC_ASSERT( args.size() == 3 && args[2].is_array() );
|
FC_ASSERT( args.size() == 3 && args[2].is_array() );
|
||||||
|
|
@ -59,44 +59,42 @@ variant websocket_api_connection::send_call(
|
||||||
string method_name,
|
string method_name,
|
||||||
variants args /* = variants() */ )
|
variants args /* = variants() */ )
|
||||||
{
|
{
|
||||||
if( _connection )
|
if( !_connection ) // defensive check
|
||||||
{
|
return variant(); // TODO return an error?
|
||||||
|
|
||||||
auto request = _rpc_state.start_remote_call( "call", { api_id, std::move(method_name), std::move(args) } );
|
auto request = _rpc_state.start_remote_call( "call", { api_id, std::move(method_name), std::move(args) } );
|
||||||
_connection->send_message( fc::json::to_string( fc::variant( request, _max_conversion_depth ),
|
_connection->send_message( fc::json::to_string( fc::variant( request, _max_conversion_depth ),
|
||||||
fc::json::stringify_large_ints_and_doubles,
|
fc::json::stringify_large_ints_and_doubles,
|
||||||
_max_conversion_depth ) );
|
_max_conversion_depth ) );
|
||||||
return _rpc_state.wait_for_response( *request.id );
|
return _rpc_state.wait_for_response( *request.id );
|
||||||
}
|
}
|
||||||
return variant(); // TODO return an error
|
|
||||||
}
|
|
||||||
|
|
||||||
variant websocket_api_connection::send_callback(
|
variant websocket_api_connection::send_callback(
|
||||||
uint64_t callback_id,
|
uint64_t callback_id,
|
||||||
variants args /* = variants() */ )
|
variants args /* = variants() */ )
|
||||||
{
|
{
|
||||||
if( _connection )
|
if( !_connection ) // defensive check
|
||||||
{
|
return variant(); // TODO return an error?
|
||||||
|
|
||||||
auto request = _rpc_state.start_remote_call( "callback", { callback_id, std::move(args) } );
|
auto request = _rpc_state.start_remote_call( "callback", { callback_id, std::move(args) } );
|
||||||
_connection->send_message( fc::json::to_string( fc::variant( request, _max_conversion_depth ),
|
_connection->send_message( fc::json::to_string( fc::variant( request, _max_conversion_depth ),
|
||||||
fc::json::stringify_large_ints_and_doubles,
|
fc::json::stringify_large_ints_and_doubles,
|
||||||
_max_conversion_depth ) );
|
_max_conversion_depth ) );
|
||||||
return _rpc_state.wait_for_response( *request.id );
|
return _rpc_state.wait_for_response( *request.id );
|
||||||
}
|
}
|
||||||
return variant(); // TODO return an error
|
|
||||||
}
|
|
||||||
|
|
||||||
void websocket_api_connection::send_notice(
|
void websocket_api_connection::send_notice(
|
||||||
uint64_t callback_id,
|
uint64_t callback_id,
|
||||||
variants args /* = variants() */ )
|
variants args /* = variants() */ )
|
||||||
{
|
{
|
||||||
if( _connection )
|
if( !_connection ) // defensive check
|
||||||
{
|
return;
|
||||||
|
|
||||||
fc::rpc::request req{ optional<uint64_t>(), "notice", { callback_id, std::move(args) } };
|
fc::rpc::request req{ optional<uint64_t>(), "notice", { callback_id, std::move(args) } };
|
||||||
_connection->send_message( fc::json::to_string( fc::variant( req, _max_conversion_depth ),
|
_connection->send_message( fc::json::to_string( fc::variant( req, _max_conversion_depth ),
|
||||||
fc::json::stringify_large_ints_and_doubles,
|
fc::json::stringify_large_ints_and_doubles,
|
||||||
_max_conversion_depth ) );
|
_max_conversion_depth ) );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::string websocket_api_connection::on_message(
|
std::string websocket_api_connection::on_message(
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue