Skip to content

Commit

Permalink
feat: support manually config http timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Jul 8, 2020
1 parent 138dac0 commit 564b5e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ckb/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class API
attr_reader :multi_sign_secp_cell_type_hash
attr_reader :multi_sign_secp_group_out_point

def initialize(host: CKB::RPC::DEFAULT_URL, mode: MODE::TESTNET)
@rpc = CKB::RPC.new(host: host)
def initialize(host: CKB::RPC::DEFAULT_URL, mode: MODE::TESTNET, timeout_config: {})
@rpc = CKB::RPC.new(host: host, timeout_config: timeout_config)
if mode == MODE::TESTNET || mode == MODE::MAINNET
# For testnet chain, we can assume the second cell of the first transaction
# in the genesis block contains default lock script we can use here.
Expand Down
5 changes: 4 additions & 1 deletion lib/ckb/rpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ class RPC

DEFAULT_URL = "http://localhost:8114"

def initialize(host: DEFAULT_URL)
def initialize(host: DEFAULT_URL, timeout_config: {})
@uri = URI(host)
@http = Net::HTTP::Persistent.new
@http.open_timeout = timeout_config[:open_timeout] if timeout_config[:open_timeout]
@http.read_timeout = timeout_config[:read_timeout] if timeout_config[:read_timeout]
@http.write_timeout = timeout_config[:write_timeout] if timeout_config[:write_timeout]
end

def method_missing(method, *params)
Expand Down

0 comments on commit 564b5e4

Please sign in to comment.