sibit 0.14.3 → 0.14.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3746b345c4e7b36083c7a2377e4a5449532116978e38f964ac558046670fb5d
4
- data.tar.gz: 480071555f2cc5e4b15a81274b526fb74a75c223d7b98a98226a134dd87e0e03
3
+ metadata.gz: 6d3a384cb5eabf6eeb7b52a49ee9fff8be0c8ff7c848fa8d57c7bbb38ef300ad
4
+ data.tar.gz: 74dc8d68b3865c9ac3d1ddf363724eab2f59e7de3a03f69eadf1914503c4f5f8
5
5
  SHA512:
6
- metadata.gz: '097f3d44a66b8ef449e26429ec068bc8395258d80a2e0d5f520f9af24f5e0323d1f83f2f41e691d9daee570fb9527288c4b721ffdfa43762eafd1ef8c62d8095'
7
- data.tar.gz: 8e9d7c89c01e6d537d159e16af0facdffbee6ea1ed4c16104a1c1fd33e4342b0a0a44bc7b3b5b2b5b45e11fa0fd222b4ac8e54aa4de6a75e416e4837540bc796
6
+ metadata.gz: f572ddce51c449495092bb8ba8c0eb8752bf9852c8b01b5e57fd7d5f6550dd328f57a5a106ec0cf43402c1475cd0e05c58e4ecd02ee485adc32b372750e24f49
7
+ data.tar.gz: c9ed3aed73e9b7e1beda8bdaa55209b6f1b7fc52047c6f494c21b4d7704be560c42541e7db6ebd49e9dddf77db517dd4dd9fbd2c99019b93599e73e948d9a848
@@ -104,8 +104,27 @@ 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
- raise Sibit::Error, 'block() not implemented yet'
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
+ }
109
128
  end
110
129
  end
111
130
  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.3'
29
+ VERSION = '0.14.4'
30
30
  end
@@ -0,0 +1,49 @@
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
+
29
+ # Sibit::Blockchain test.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2019-2020 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestBlockchain < Minitest::Test
34
+ def test_fetch_block
35
+ # WebMock.allow_net_connect!
36
+ hash = '0000000000000000000f676241aabc9b62b748d26192a44bc25720c34de27d19'
37
+ stub_request(:get, "https://blockchain.info/rawblock/#{hash}")
38
+ .to_return(body: '{"next_block": "n", "prev_block": "p", "hash": "h",
39
+ "tx": [{"hash": "h1", "out": [{"hash": "oh", "value": 123}]}]}')
40
+ sibit = Sibit::Blockchain.new
41
+ json = sibit.block(hash)
42
+ assert(json[:next])
43
+ assert(json[:previous])
44
+ assert_equal('h', json[:hash])
45
+ assert(json[:txns].is_a?(Array))
46
+ assert_equal('h1', json[:txns][0][:hash])
47
+ assert(json[:txns][0][:outputs].is_a?(Array))
48
+ end
49
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-24 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -295,6 +295,7 @@ files:
295
295
  - sibit.gemspec
296
296
  - test/test__helper.rb
297
297
  - test/test_bitcoinchain.rb
298
+ - test/test_blockchain.rb
298
299
  - test/test_btc.rb
299
300
  - test/test_fake.rb
300
301
  - test/test_json.rb
@@ -330,6 +331,7 @@ test_files:
330
331
  - features/support/env.rb
331
332
  - test/test__helper.rb
332
333
  - test/test_bitcoinchain.rb
334
+ - test/test_blockchain.rb
333
335
  - test/test_btc.rb
334
336
  - test/test_fake.rb
335
337
  - test/test_json.rb