Skip to content

Commit 564b5e4

Browse files
committed
feat: support manually config http timeout
1 parent 138dac0 commit 564b5e4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/ckb/api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class API
2121
attr_reader :multi_sign_secp_cell_type_hash
2222
attr_reader :multi_sign_secp_group_out_point
2323

24-
def initialize(host: CKB::RPC::DEFAULT_URL, mode: MODE::TESTNET)
25-
@rpc = CKB::RPC.new(host: host)
24+
def initialize(host: CKB::RPC::DEFAULT_URL, mode: MODE::TESTNET, timeout_config: {})
25+
@rpc = CKB::RPC.new(host: host, timeout_config: timeout_config)
2626
if mode == MODE::TESTNET || mode == MODE::MAINNET
2727
# For testnet chain, we can assume the second cell of the first transaction
2828
# in the genesis block contains default lock script we can use here.

lib/ckb/rpc.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ class RPC
2828

2929
DEFAULT_URL = "http://localhost:8114"
3030

31-
def initialize(host: DEFAULT_URL)
31+
def initialize(host: DEFAULT_URL, timeout_config: {})
3232
@uri = URI(host)
3333
@http = Net::HTTP::Persistent.new
34+
@http.open_timeout = timeout_config[:open_timeout] if timeout_config[:open_timeout]
35+
@http.read_timeout = timeout_config[:read_timeout] if timeout_config[:read_timeout]
36+
@http.write_timeout = timeout_config[:write_timeout] if timeout_config[:write_timeout]
3437
end
3538

3639
def method_missing(method, *params)

0 commit comments

Comments
 (0)