Skip to content

Commit 18fb5b5

Browse files
authored
Merge pull request #24 from imacchiato/set_mining_fee
Add ability to set mining fee in forwarding address
2 parents 3d0bac7 + 824832f commit 18fb5b5

25 files changed

Lines changed: 3201 additions & 23 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Gemfile.lock
1+
Gemfile.lock
2+
spec/config.yml

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
source 'https://rubygems.org'
22

3-
gemspec
3+
gemspec

Gemfile.lock

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@ PATH
88
GEM
99
remote: https://rubygems.org/
1010
specs:
11+
activesupport (5.0.0)
12+
concurrent-ruby (~> 1.0, >= 1.0.2)
13+
i18n (~> 0.7)
14+
minitest (~> 5.1)
15+
tzinfo (~> 1.1)
16+
addressable (2.4.0)
1117
bitcoin-ruby (0.0.6)
1218
coderay (1.1.0)
19+
concurrent-ruby (1.0.2)
20+
crack (0.4.3)
21+
safe_yaml (~> 1.0.0)
1322
diff-lcs (1.2.5)
1423
ffi (1.9.8)
24+
hashdiff (0.3.0)
25+
i18n (0.7.0)
1526
method_source (0.8.2)
27+
minitest (5.9.0)
1628
pry (0.10.1)
1729
coderay (~> 1.1.0)
1830
method_source (~> 0.8.1)
@@ -31,14 +43,29 @@ GEM
3143
diff-lcs (>= 1.2.0, < 2.0)
3244
rspec-support (~> 3.2.0)
3345
rspec-support (3.2.2)
46+
safe_yaml (1.0.4)
3447
slop (3.6.0)
48+
thread_safe (0.3.5)
49+
tzinfo (1.2.2)
50+
thread_safe (~> 0.1)
51+
vcr (3.0.3)
52+
webmock (2.1.0)
53+
addressable (>= 2.3.6)
54+
crack (>= 0.3.2)
55+
hashdiff
3556

3657
PLATFORMS
3758
ruby
3859

3960
DEPENDENCIES
61+
activesupport
4062
blockcypher-ruby!
4163
bundler (~> 1.6)
4264
pry
4365
rake
4466
rspec
67+
vcr
68+
webmock
69+
70+
BUNDLED WITH
71+
1.13.1

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ For more information check the API docs at:
4444

4545
http://dev.blockcypher.com
4646

47+
## Development
48+
49+
- Copy `spec/config.yml.sample` to `spec/config.yml` and put your test API token
50+
- `rspec spec`
51+
4752
## Contributors
4853

4954
Contributions from [CoinHako](http://www.coinhako.com) and [meXBT](https://mexbt.com)

blockcypher-ruby.gemspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ Gem::Specification.new do |s|
1616
s.add_development_dependency "rake"
1717
s.add_development_dependency "rspec"
1818
s.add_development_dependency "pry"
19+
s.add_development_dependency "activesupport"
20+
s.add_development_dependency "vcr"
21+
s.add_development_dependency "webmock"
1922
end

lib/blockcypher/api.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,17 @@ def event_webhook_delete(id)
287287
# Payments and Forwarding API
288288
##################
289289

290-
def create_forwarding_address(destination, callback_url: nil, enable_confirmations: false)
290+
def create_forwarding_address(
291+
destination,
292+
callback_url: nil,
293+
enable_confirmations: false,
294+
mining_fees_satoshis: nil
295+
)
291296
payload = {
292297
destination: destination,
293298
callback_url: callback_url,
294-
enable_confirmations: enable_confirmations
299+
enable_confirmations: enable_confirmations,
300+
mining_fees_satoshis: mining_fees_satoshis,
295301
}
296302
api_http_post('/payments', json_payload: payload)
297303
end

spec/blockcypher/api_spec.rb

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
require 'blockcypher'
1+
require 'spec_helper'
22

33
module BlockCypher
44

5-
describe Api do
5+
describe Api, vcr: {record: :once} do
66
let(:api) do
77
BlockCypher::Api.new({
8-
api_token: 'testtoken',
8+
api_token: CONFIG[:api_token],
99
currency: BlockCypher::BCY,
1010
network: BlockCypher::TEST_NET,
1111
version: BlockCypher::V1
1212
})
1313
end
1414

15+
let(:addr1) { api.address_generate }
16+
let(:addr2) { api.address_generate }
1517
context '#address_generate' do
1618
it 'should generate new addresses' do
17-
$addr1 = api.address_generate
18-
$addr2 = api.address_generate
19-
expect($addr1["address"]).to be_a(String)
20-
expect($addr2["address"]).to be_a(String)
19+
expect(addr1["address"]).to be_a(String)
20+
expect(addr2["address"]).to be_a(String)
2121
end
2222
end
2323

24-
let(:address_1) { $addr1["address"].to_s }
25-
let(:address_1_private_key) { $addr1["private"].to_s }
24+
let(:address_1) { addr1["address"].to_s }
25+
let(:address_1_private_key) { addr1["private"].to_s }
2626

27-
let(:address_2) { $addr2["address"].to_s }
28-
let(:address_2_private_key) { $addr2["private"].to_s }
27+
let(:address_2) { addr2["address"].to_s }
28+
let(:address_2_private_key) { addr2["private"].to_s }
2929

3030
context '#faucet' do
3131
it 'should fund a bcy test address with the faucet' do
@@ -74,16 +74,15 @@ module BlockCypher
7474
expect(forward_details["input_address"].length).to be(34) # Ok this isn't strictly true but..
7575
end
7676

77-
it 'allows creating a payment forward with a callback' do
78-
forward_details = api.create_forwarding_address(address_1, callback_url: "http://test.com/foo")
79-
expect(forward_details["callback_url"]).to eql("http://test.com/foo")
80-
expect(forward_details["enable_confirmations"]).to be nil
81-
end
82-
83-
it 'allows creating a payment forward with a callback and confirmation notifications enabled' do
84-
forward_details = api.create_forwarding_address(address_1, callback_url: "http://test.com/foo", enable_confirmations: true)
77+
it 'allows creating a payment forward with options' do
78+
forward_details = api.create_forwarding_address(address_1, {
79+
callback_url: "http://test.com/foo",
80+
enable_confirmations: true,
81+
mining_fees_satoshis: 20_000,
82+
})
8583
expect(forward_details["callback_url"]).to eql("http://test.com/foo")
8684
expect(forward_details["enable_confirmations"]).to be true
85+
expect(forward_details["mining_fees_satoshis"]).to be 20_000
8786
end
8887

8988
it 'is possible to use the alias create_payments_forwarding' do

spec/config.yml.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
api_token: testtoken-changeme

0 commit comments

Comments
 (0)