From e690a71db921f2f95225aec46932155ab84c3be1 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Sat, 18 May 2019 11:30:22 +0800 Subject: [PATCH 1/5] fix: fix for gather_inputs when diff = 0 --- lib/ckb/wallet.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ckb/wallet.rb b/lib/ckb/wallet.rb index cd4db14f..c9e055c8 100644 --- a/lib/ckb/wallet.rb +++ b/lib/ckb/wallet.rb @@ -203,7 +203,8 @@ def gather_inputs(capacity, min_capacity) inputs << input input_capacities += cell.capacity.to_i - break if input_capacities >= capacity && (input_capacities - capacity) >= min_capacity + diff = input_capacities - capacity + break if input_capacities >= capacity && (diff >= min_capacity || diff.zero?) end raise "Not enough capacity!" if input_capacities < capacity From c60599ca19a1cae0621247b3a25d20468fcf114f Mon Sep 17 00:00:00 2001 From: classicalliu Date: Sat, 18 May 2019 12:27:09 +0800 Subject: [PATCH 2/5] docs: add ruby version requirement to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a1a269da..d4e25e5e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Ruby SDK for CKB ## Prerequisites +Require Ruby 2.4 and above. + Please be noted that the SDK depends on the [bitcoin-secp256k1](https://github.com/cryptape/ruby-bitcoin-secp256k1) gem and the [rbnacl](https://github.com/crypto-rb/rbnacl) gem, which require manual install of secp256k1 and libsodium library. Follow [this](https://github.com/cryptape/ruby-bitcoin-secp256k1#prerequisite) and [this](https://github.com/crypto-rb/rbnacl#installation) to install them locally. ## Installation From 041eb609dd356a5c678b618a5b1b65c9d33e5e4c Mon Sep 17 00:00:00 2001 From: quake wang Date: Sat, 18 May 2019 14:25:26 +0800 Subject: [PATCH 3/5] feat: persistent http client --- Gemfile.lock | 6 +++++- ckb-sdk-ruby.gemspec | 1 + lib/ckb/rpc.rb | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 56b1862f..e8b1e065 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: ckb-sdk-ruby (0.12.0) bitcoin-secp256k1 (~> 0.5.0) + net-http-persistent (~> 3.0.0) rbnacl (~> 6.0, >= 6.0.1) GEM @@ -12,10 +13,13 @@ GEM bitcoin-secp256k1 (0.5.1) ffi (>= 1.9.25) coderay (1.1.2) + connection_pool (2.2.2) diff-lcs (1.3) - ffi (1.10.0) + ffi (1.11.0) jaro_winkler (1.5.2) method_source (0.9.2) + net-http-persistent (3.0.1) + connection_pool (~> 2.2) parallel (1.14.0) parser (2.6.2.0) ast (~> 2.4.0) diff --git a/ckb-sdk-ruby.gemspec b/ckb-sdk-ruby.gemspec index 79309a62..341ab6fc 100644 --- a/ckb-sdk-ruby.gemspec +++ b/ckb-sdk-ruby.gemspec @@ -44,4 +44,5 @@ Gem::Specification.new do |spec| spec.add_dependency "rbnacl", "~> 6.0", ">= 6.0.1" spec.add_dependency "bitcoin-secp256k1", "~> 0.5.0" + spec.add_dependency "net-http-persistent", "~> 3.0.0" end diff --git a/lib/ckb/rpc.rb b/lib/ckb/rpc.rb index 23530110..671d7007 100644 --- a/lib/ckb/rpc.rb +++ b/lib/ckb/rpc.rb @@ -2,7 +2,7 @@ # rubocop:disable Naming/AccessorMethodName -require "net/http" +require 'net/http/persistent' require "json" require "uri" @@ -10,12 +10,13 @@ module CKB class RPCError < StandardError; end class RPC - attr_reader :uri + attr_reader :uri, :http DEFAULT_URL = "http://localhost:8114" def initialize(host: DEFAULT_URL) @uri = URI(host) + @http = Net::HTTP::Persistent.new end def genesis_block @@ -112,8 +113,7 @@ def inspect private def rpc_request(method, params: nil) - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Post.new(uri.request_uri) + request = Net::HTTP::Post.new("/") request.body = { id: 1, jsonrpc: "2.0", @@ -121,7 +121,7 @@ def rpc_request(method, params: nil) params: params }.to_json request["Content-Type"] = "application/json" - response = http.request(request) + response = http.request(uri, request) result = JSON.parse(response.body, symbolize_names: true) raise RPCError, "jsonrpc error: #{result[:error]}" if result[:error] From f2aaadf390445fd52f350b0fa6af497c1e60c843 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Sat, 18 May 2019 15:20:40 +0800 Subject: [PATCH 4/5] chore: update version to 0.12.1 --- Gemfile.lock | 2 +- lib/ckb/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e8b1e065..89534084 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ckb-sdk-ruby (0.12.0) + ckb-sdk-ruby (0.12.1) bitcoin-secp256k1 (~> 0.5.0) net-http-persistent (~> 3.0.0) rbnacl (~> 6.0, >= 6.0.1) diff --git a/lib/ckb/version.rb b/lib/ckb/version.rb index 79cb88c4..7bcfc412 100644 --- a/lib/ckb/version.rb +++ b/lib/ckb/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CKB - VERSION = "0.12.0" + VERSION = "0.12.1" end From ba3470c92f96b2e2bcf361996da8ae5d0f352f28 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Sat, 18 May 2019 15:22:03 +0800 Subject: [PATCH 5/5] docs: update CHANGELOG for v0.12.1 --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd808bf..8770bbda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,19 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.12.1](https://github.com/nervosnetwork/ckb-sdk-ruby/compare/v0.12.0...v0.12.1) (2019-05-18) + + +### Bug Fixes + +* fix for gather_inputs when diff = 0 ([e690a71](https://github.com/nervosnetwork/ckb-sdk-ruby/commit/e690a71)) + + +### Features + +* persistent http client ([041eb60](https://github.com/nervosnetwork/ckb-sdk-ruby/commit/041eb60)) + + # [0.12.0](https://github.com/nervosnetwork/ckb-sdk-ruby/compare/v0.11.0...v0.12.0) (2019-05-18)