sibit 0.14.4 → 0.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d3a384cb5eabf6eeb7b52a49ee9fff8be0c8ff7c848fa8d57c7bbb38ef300ad
4
- data.tar.gz: 74dc8d68b3865c9ac3d1ddf363724eab2f59e7de3a03f69eadf1914503c4f5f8
3
+ metadata.gz: 1f5687f2fe1a1104c3beb596b08818f0a9526405df9e6022c68a47f575549c16
4
+ data.tar.gz: ee3f5f71d21739855368af24ac879b4e5b4577e59f605515a662893d778cc447
5
5
  SHA512:
6
- metadata.gz: f572ddce51c449495092bb8ba8c0eb8752bf9852c8b01b5e57fd7d5f6550dd328f57a5a106ec0cf43402c1475cd0e05c58e4ecd02ee485adc32b372750e24f49
7
- data.tar.gz: c9ed3aed73e9b7e1beda8bdaa55209b6f1b7fc52047c6f494c21b4d7704be560c42541e7db6ebd49e9dddf77db517dd4dd9fbd2c99019b93599e73e948d9a848
6
+ metadata.gz: df736816b94d5975dcd6c589ab48467f3907a42091c1e032f4ef7dc8f8c89c082409555d45957d93ea74b0b3cb98bd19c53c1091df66ab7288211218f1af0b57
7
+ data.tar.gz: bd341019c48a1738e6cc7f788827dbb625c7b0f8756267efbbed1efc19245c21b9cd75bc121596a89ce4ab8a010151c91b876daf9c21441fde0b2e72d1c1a283
@@ -84,6 +84,9 @@ class Sibit
84
84
  URI("https://api-r.bitcoinchain.com/v1/block/#{hash}")
85
85
  )[0]
86
86
  raise Sibit::Error, "The block #{hash} is not found" if head.nil?
87
+ txs = Sibit::Json.new(http: @http, log: @log).get(
88
+ URI("https://api-r.bitcoinchain.com/v1/block/txs/#{hash}")
89
+ )
87
90
  nxt = head['next_block']
88
91
  nxt = nil if nxt == '0000000000000000000000000000000000000000000000000000000000000000'
89
92
  {
@@ -91,15 +94,13 @@ class Sibit
91
94
  orphan: !head['is_main'],
92
95
  next: nxt,
93
96
  previous: head['prev_block'],
94
- txns: Sibit::Json.new(http: @http, log: @log).get(
95
- URI("https://api-r.bitcoinchain.com/v1/block/txs/#{hash}")
96
- )[0]['txs'].map do |t|
97
+ txns: txs[0]['txs'].map do |t|
97
98
  {
98
99
  hash: t['self_hash'],
99
- outputs: t['outputs'].select { |o| o['spent'] }.map do |o|
100
+ outputs: t['outputs'].map do |o|
100
101
  {
101
102
  address: o['receiver'],
102
- value: o['value']
103
+ value: o['value'] * 100_000_000
103
104
  }
104
105
  end
105
106
  }
@@ -104,27 +104,28 @@ class Sibit
104
104
  end
105
105
 
106
106
  # This method should fetch a Blockchain block and return as a hash.
107
- def block(hash)
108
- json = Sibit::Json.new(http: @http, log: @log).get(
109
- URI("https://blockchain.info/rawblock/#{hash}")
110
- )
111
- {
112
- hash: json['hash'],
113
- orphan: !json['main_chain'],
114
- next: json['next_block'][0],
115
- previous: json['prev_block'],
116
- txns: json['tx'].map do |t|
117
- {
118
- hash: t['hash'],
119
- outputs: t['out'].map do |o|
120
- {
121
- address: o['hash'],
122
- value: o['value']
123
- }
124
- end
125
- }
126
- end
127
- }
107
+ def block(_hash)
108
+ raise Sibit::Error, 'Blockchain.com API fails to return next_block'
109
+ # json = Sibit::Json.new(http: @http, log: @log).get(
110
+ # URI("https://blockchain.info/rawblock/#{hash}")
111
+ # )
112
+ # {
113
+ # hash: json['hash'],
114
+ # orphan: !json['main_chain'],
115
+ # next: json['next_block'][0],
116
+ # previous: json['prev_block'],
117
+ # txns: json['tx'].map do |t|
118
+ # {
119
+ # hash: t['hash'],
120
+ # outputs: t['out'].map do |o|
121
+ # {
122
+ # address: o['addr'],
123
+ # value: o['value']
124
+ # }
125
+ # end
126
+ # }
127
+ # end
128
+ # }
128
129
  end
129
130
  end
130
131
  end
data/lib/sibit/version.rb CHANGED
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.14.4'
29
+ VERSION = '0.14.5'
30
30
  end
data/lib/sibit.rb CHANGED
@@ -175,7 +175,8 @@ class Sibit
175
175
  #
176
176
  # The callback will be called with three arguments:
177
177
  # 1) Bitcoin address of the receiver, 2) transaction hash, 3) amount
178
- # in satoshi.
178
+ # in satoshi. The callback should return non-false if the transaction
179
+ # found was useful.
179
180
  def scan(start, max: 4)
180
181
  block = start
181
182
  count = 0
@@ -202,8 +203,9 @@ class Sibit
202
203
  checked_outputs += 1
203
204
  hash = "#{t[:hash]}:#{i}"
204
205
  satoshi = o[:value]
205
- yield(address, hash, satoshi)
206
- @log.info("Bitcoin tx found at #{hash} for #{satoshi} sent to #{address}")
206
+ if yield(address, hash, satoshi)
207
+ @log.info("Bitcoin tx found at #{hash} for #{satoshi} sent to #{address}")
208
+ end
207
209
  end
208
210
  checked += 1
209
211
  end
@@ -32,7 +32,7 @@ require_relative '../lib/sibit/blockchain'
32
32
  # License:: MIT
33
33
  class TestBlockchain < Minitest::Test
34
34
  def test_fetch_block
35
- # WebMock.allow_net_connect!
35
+ skip
36
36
  hash = '0000000000000000000f676241aabc9b62b748d26192a44bc25720c34de27d19'
37
37
  stub_request(:get, "https://blockchain.info/rawblock/#{hash}")
38
38
  .to_return(body: '{"next_block": "n", "prev_block": "p", "hash": "h",
data/test/test_live.rb ADDED
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019-2020 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require 'webmock/minitest'
25
+ require 'json'
26
+ require_relative '../lib/sibit'
27
+ require_relative '../lib/sibit/blockchain'
28
+ require_relative '../lib/sibit/btc'
29
+ require_relative '../lib/sibit/bitcoinchain'
30
+
31
+ # Live tests.
32
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
+ # Copyright:: Copyright (c) 2019-2020 Yegor Bugayenko
34
+ # License:: MIT
35
+ class TestLive < Minitest::Test
36
+ def test_fetch_block
37
+ skip
38
+ for_each do |api|
39
+ hash = '000000003031a0e73735690c5a1ff2a4be82553b2a12b776fbd3a215dc8f778d'
40
+ json = api.block(hash)
41
+ assert_equal(hash, json[:hash])
42
+ assert(json[:txns].is_a?(Array))
43
+ assert_equal(1, json[:txns].length)
44
+ assert_equal(
45
+ '20251a76e64e920e58291a30d4b212939aae976baca40e70818ceaa596fb9d37',
46
+ json[:txns][0][:hash]
47
+ )
48
+ assert(json[:txns][0][:outputs].is_a?(Array))
49
+ assert_equal(1, json[:txns][0][:outputs].length)
50
+ out = json[:txns][0][:outputs][0]
51
+ assert_equal('1GkQmKAmHtNfnD3LHhTkewJxKHVSta4m2a', out[:address])
52
+ assert_equal(5_000_000_000, out[:value])
53
+ assert(json[:next], 'Next block not found')
54
+ assert(json[:previous], 'Previous block not found')
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def for_each
61
+ WebMock.allow_net_connect!
62
+ [Sibit::Btc.new, Sibit::Bitcoinchain.new, Sibit::Blockchain.new].each do |api|
63
+ begin
64
+ yield api
65
+ rescue Sibit::Error => e
66
+ puts e.message
67
+ end
68
+ end
69
+ end
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.4
4
+ version: 0.14.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -299,6 +299,7 @@ files:
299
299
  - test/test_btc.rb
300
300
  - test/test_fake.rb
301
301
  - test/test_json.rb
302
+ - test/test_live.rb
302
303
  - test/test_sibit.rb
303
304
  homepage: http://github.com/yegor256/sibit
304
305
  licenses:
@@ -335,4 +336,5 @@ test_files:
335
336
  - test/test_btc.rb
336
337
  - test/test_fake.rb
337
338
  - test/test_json.rb
339
+ - test/test_live.rb
338
340
  - test/test_sibit.rb