Skip to content
Snippets Groups Projects
Commit 1d0b2114 authored by Anthony Martin's avatar Anthony Martin
Browse files

make it easier to patch in alternative rpc clients

parent aeb78088
No related branches found
No related tags found
No related merge requests found
...@@ -39,8 +39,8 @@ module Steem ...@@ -39,8 +39,8 @@ module Steem
attr_accessor :chain, :methods attr_accessor :chain, :methods
# Use this for debugging naive thread handler. # Use this for debugging naive thread handler.
# DEFAULT_RPC_CLIENT = RPC::BaseClient # DEFAULT_RPC_CLIENT_CLASS = RPC::BaseClient
DEFAULT_RPC_CLIENT = RPC::ThreadSafeHttpClient DEFAULT_RPC_CLIENT_CLASS = RPC::ThreadSafeHttpClient
def self.api_name=(api_name) def self.api_name=(api_name)
@api_name = api_name.to_s. @api_name = api_name.to_s.
...@@ -65,11 +65,22 @@ module Steem ...@@ -65,11 +65,22 @@ module Steem
@jsonrpc @jsonrpc
end end
# Override this if you want to use your own client.
def self.default_rpc_client_class
DEFAULT_RPC_CLIENT_CLASS
end
def initialize(options = {}) def initialize(options = {})
@chain = options[:chain] || :steem @chain = options[:chain] || :steem
@error_pipe = options[:error_pipe] || STDERR @error_pipe = options[:error_pipe] || STDERR
@api_name = self.class.api_name ||= :condenser_api @api_name = self.class.api_name ||= :condenser_api
@rpc_client = options[:rpc_client] || DEFAULT_RPC_CLIENT.new(options.merge(api_name: @api_name))
@rpc_client = if !!options[:rpc_client]
options[:rpc_client]
else
rpc_client_class = self.class.default_rpc_client_class
rpc_client_class.new(options.merge(api_name: @api_name))
end
if @api_name == :jsonrpc if @api_name == :jsonrpc
Api::jsonrpc = self Api::jsonrpc = self
......
...@@ -3,7 +3,7 @@ module Steem ...@@ -3,7 +3,7 @@ module Steem
class BaseClient class BaseClient
include ChainConfig include ChainConfig
attr_accessor :chain, :error_pipe attr_accessor :url, :chain, :error_pipe
# @private # @private
MAX_TIMEOUT_RETRY_COUNT = 100 MAX_TIMEOUT_RETRY_COUNT = 100
...@@ -27,7 +27,7 @@ module Steem ...@@ -27,7 +27,7 @@ module Steem
end end
def uri def uri
@uri ||= URI.parse(@url) @uri ||= URI.parse(url)
end end
# Adds a request object to the stack. Usually, this method is called # Adds a request object to the stack. Usually, this method is called
......
...@@ -16,7 +16,8 @@ module Steem ...@@ -16,7 +16,8 @@ module Steem
# http status code of 200 and HTML page. # http status code of 200 and HTML page.
# #
# @private # @private
TIMEOUT_ERRORS = [Net::OpenTimeout, Net::ReadTimeout, JSON::ParserError] TIMEOUT_ERRORS = [Net::OpenTimeout, JSON::ParserError, Net::ReadTimeout,
Errno::EBADF, Errno::ECONNREFUSED, IOError]
# @private # @private
POST_HEADERS = { POST_HEADERS = {
...@@ -66,7 +67,7 @@ module Steem ...@@ -66,7 +67,7 @@ module Steem
end end
if request_object.size > JSON_RPC_BATCH_SIZE_MAXIMUM if request_object.size > JSON_RPC_BATCH_SIZE_MAXIMUM
raise JsonRpcBatchMaximumSizeExceededError, 'Maximum json-rpc-batch is 50 elements.' raise JsonRpcBatchMaximumSizeExceededError, "Maximum json-rpc-batch is #{JSON_RPC_BATCH_SIZE_MAXIMUM} elements."
end end
request.body = if request_object.class == Hash request.body = if request_object.class == Hash
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment