From d8c7fbaddd30f9f3e1c975bc1775042b84500728 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 3 Jul 2019 13:17:08 +0900 Subject: [PATCH 1/6] chore(deps): Bump bundle bitcoin-secp256k1 to v0.5.2 --- Gemfile.lock | 4 ++-- ckb-sdk-ruby.gemspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2bca8e05..ccb09806 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: ckb-sdk-ruby (0.15.0) - bitcoin-secp256k1 (~> 0.5.0) + bitcoin-secp256k1 (~> 0.5.2) net-http-persistent (~> 3.0.0) rbnacl (~> 6.0, >= 6.0.1) @@ -10,7 +10,7 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.0) - bitcoin-secp256k1 (0.5.1) + bitcoin-secp256k1 (0.5.2) ffi (>= 1.9.25) coderay (1.1.2) connection_pool (2.2.2) diff --git a/ckb-sdk-ruby.gemspec b/ckb-sdk-ruby.gemspec index 359f398b..85152565 100644 --- a/ckb-sdk-ruby.gemspec +++ b/ckb-sdk-ruby.gemspec @@ -43,5 +43,5 @@ Gem::Specification.new do |spec| spec.add_dependency "net-http-persistent", "~> 3.0.0" spec.add_dependency "rbnacl", "~> 6.0", ">= 6.0.1" - spec.add_dependency "bitcoin-secp256k1", "~> 0.5.0" + spec.add_dependency "bitcoin-secp256k1", "~> 0.5.2" end From fbe6cc728b139d3ca8d7c281f51cb98a23c6e7e0 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Mon, 8 Jul 2019 11:26:59 +0800 Subject: [PATCH 2/6] chore: make lock hash public in wallet --- lib/ckb/wallet.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ckb/wallet.rb b/lib/ckb/wallet.rb index b00d8ef8..a8d9a90e 100644 --- a/lib/ckb/wallet.rb +++ b/lib/ckb/wallet.rb @@ -217,6 +217,10 @@ def block_assembler_config ).strip end + def lock_hash + @lock_hash ||= lock.to_hash + end + private # @param transaction [CKB::Transaction] @@ -250,10 +254,6 @@ def gather_inputs(capacity, min_capacity, min_charge_capacity) OpenStruct.new(inputs: inputs, capacities: input_capacities, witnesses: witnesses) end - def lock_hash - @lock_hash ||= lock.to_hash - end - # @return [CKB::Types::Script] def lock Types::Script.generate_lock( From a1d48cd068c699136819cb90360842706cd3dc0f Mon Sep 17 00:00:00 2001 From: classicalliu Date: Mon, 8 Jul 2019 15:26:24 +0800 Subject: [PATCH 3/6] chore: support fee in `send_capacity` --- lib/ckb/wallet.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/ckb/wallet.rb b/lib/ckb/wallet.rb index a8d9a90e..41914a80 100644 --- a/lib/ckb/wallet.rb +++ b/lib/ckb/wallet.rb @@ -59,7 +59,8 @@ def get_balance # @param capacity [Integer] # @param data [String ] "0x..." # @param key [CKB::Key | String] Key or private key hex string - def generate_tx(target_address, capacity, data = "0x", key: nil) + # @param fee [Integer] transaction fee, in shannon + def generate_tx(target_address, capacity, data = "0x", key: nil, fee: 0) key = get_key(key) output = Types::Output.new( @@ -79,12 +80,13 @@ def generate_tx(target_address, capacity, data = "0x", key: nil) i = gather_inputs( capacity, output.calculate_min_capacity, - charge_output.calculate_min_capacity + charge_output.calculate_min_capacity, + fee ) input_capacities = i.capacities outputs = [output] - charge_output.capacity = input_capacities - capacity + charge_output.capacity = input_capacities - (capacity + fee) outputs << charge_output if charge_output.capacity.to_i > 0 tx = Types::Transaction.new( @@ -103,8 +105,9 @@ def generate_tx(target_address, capacity, data = "0x", key: nil) # @param capacity [Integer] # @param data [String] "0x..." # @param key [CKB::Key | String] Key or private key hex string - def send_capacity(target_address, capacity, data = "0x", key: nil) - tx = generate_tx(target_address, capacity, data, key: key) + # @param fee [Integer] transaction fee, in shannon + def send_capacity(target_address, capacity, data = "0x", key: nil, fee: 0) + tx = generate_tx(target_address, capacity, data, key: key, fee: fee) send_transaction(tx) end @@ -141,7 +144,7 @@ def deposit_to_dao(capacity, key: nil) deps: [api.system_script_out_point], inputs: i.inputs, outputs: outputs, - witnesses: i.witnesses, + witnesses: i.witnesses ) tx_hash = api.compute_transaction_hash(tx) send_transaction(tx.sign(key, tx_hash)) @@ -230,9 +233,12 @@ def send_transaction(transaction) # @param capacity [Integer] # @param min_capacity [Integer] - def gather_inputs(capacity, min_capacity, min_charge_capacity) + # @param min_charge_capacity [Integer] + # @param fee [Integer] + def gather_inputs(capacity, min_capacity, min_charge_capacity, fee) raise "capacity cannot be less than #{min_capacity}" if capacity < min_capacity + total_capacities = capacity + fee input_capacities = 0 inputs = [] witnesses = [] @@ -245,11 +251,11 @@ def gather_inputs(capacity, min_capacity, min_charge_capacity) witnesses << Types::Witness.new(data: []) input_capacities += cell.capacity.to_i - diff = input_capacities - capacity + diff = input_capacities - total_capacities break if diff >= min_charge_capacity || diff.zero? end - raise "Capacity not enough!" if input_capacities < capacity + raise "Capacity not enough!" if input_capacities < total_capacities OpenStruct.new(inputs: inputs, capacities: input_capacities, witnesses: witnesses) end From 7c8539018a24249d579e033986674a9ae3582b55 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Mon, 8 Jul 2019 16:36:45 +0800 Subject: [PATCH 4/6] fix: charge => change --- lib/ckb/wallet.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/ckb/wallet.rb b/lib/ckb/wallet.rb index 41914a80..986b6ef4 100644 --- a/lib/ckb/wallet.rb +++ b/lib/ckb/wallet.rb @@ -72,7 +72,7 @@ def generate_tx(target_address, capacity, data = "0x", key: nil, fee: 0) ) ) - charge_output = Types::Output.new( + change_output = Types::Output.new( capacity: 0, lock: lock ) @@ -80,14 +80,14 @@ def generate_tx(target_address, capacity, data = "0x", key: nil, fee: 0) i = gather_inputs( capacity, output.calculate_min_capacity, - charge_output.calculate_min_capacity, + change_output.calculate_min_capacity, fee ) input_capacities = i.capacities outputs = [output] - charge_output.capacity = input_capacities - (capacity + fee) - outputs << charge_output if charge_output.capacity.to_i > 0 + change_output.capacity = input_capacities - (capacity + fee) + outputs << change_output if change_output.capacity.to_i > 0 tx = Types::Transaction.new( version: 0, @@ -123,7 +123,7 @@ def deposit_to_dao(capacity, key: nil) lock: Types::Script.generate_lock(addr.blake160, DAO_CODE_HASH) ) - charge_output = Types::Output.new( + change_output = Types::Output.new( capacity: 0, lock: lock ) @@ -131,13 +131,13 @@ def deposit_to_dao(capacity, key: nil) i = gather_inputs( capacity, output.calculate_min_capacity, - charge_output.calculate_min_capacity + change_output.calculate_min_capacity ) input_capacities = i.capacities outputs = [output] - charge_output.capacity = input_capacities - capacity - outputs << charge_output if charge_output.capacity.to_i > 0 + change_output.capacity = input_capacities - capacity + outputs << change_output if change_output.capacity.to_i > 0 tx = Types::Transaction.new( version: 0, @@ -233,9 +233,9 @@ def send_transaction(transaction) # @param capacity [Integer] # @param min_capacity [Integer] - # @param min_charge_capacity [Integer] + # @param min_change_capacity [Integer] # @param fee [Integer] - def gather_inputs(capacity, min_capacity, min_charge_capacity, fee) + def gather_inputs(capacity, min_capacity, min_change_capacity, fee) raise "capacity cannot be less than #{min_capacity}" if capacity < min_capacity total_capacities = capacity + fee @@ -252,7 +252,7 @@ def gather_inputs(capacity, min_capacity, min_charge_capacity, fee) input_capacities += cell.capacity.to_i diff = input_capacities - total_capacities - break if diff >= min_charge_capacity || diff.zero? + break if diff >= min_change_capacity || diff.zero? end raise "Capacity not enough!" if input_capacities < total_capacities From e97056f1cb1f9329e685d83b29b9aeb0e891c01c Mon Sep 17 00:00:00 2001 From: classicalliu Date: Sat, 13 Jul 2019 12:18:11 +0800 Subject: [PATCH 5/6] chore: bump version to v0.16.0 --- Gemfile.lock | 2 +- lib/ckb/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ccb09806..c72fbadc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ckb-sdk-ruby (0.15.0) + ckb-sdk-ruby (0.16.0) bitcoin-secp256k1 (~> 0.5.2) 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 aa838bd2..e2512d1a 100644 --- a/lib/ckb/version.rb +++ b/lib/ckb/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CKB - VERSION = "0.15.0" + VERSION = "0.16.0" end From 4dcc050b362ed176bd7a6d03999d4f4e8b5e9eb5 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Sat, 13 Jul 2019 12:29:58 +0800 Subject: [PATCH 6/6] docs: update CHANGELOG for v0.16.0 --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 174d79a2..7d219c30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [v0.16.0](https://github.com/nervosnetwork/ckb-sdk-ruby/compare/v0.15.0...v0.16.0) (2019-07-13) + + +### Bug Fixes + +* charge => change ([7c85390](https://github.com/nervosnetwork/ckb-sdk-ruby/commit/7c85390)) + +### Features + +* support `fee` in `send_capacity` ([a1d48cd](https://github.com/nervosnetwork/ckb-sdk-ruby/commit/a1d48cd)) + # [v0.15.0](https://github.com/nervosnetwork/ckb-sdk-ruby/compare/v0.14.0...v0.15.0) (2019-06-29)