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 +4 -4
- data/lib/sibit/blockchain.rb +21 -2
- data/lib/sibit/version.rb +1 -1
- data/test/test_blockchain.rb +49 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d3a384cb5eabf6eeb7b52a49ee9fff8be0c8ff7c848fa8d57c7bbb38ef300ad
|
4
|
+
data.tar.gz: 74dc8d68b3865c9ac3d1ddf363724eab2f59e7de3a03f69eadf1914503c4f5f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f572ddce51c449495092bb8ba8c0eb8752bf9852c8b01b5e57fd7d5f6550dd328f57a5a106ec0cf43402c1475cd0e05c58e4ecd02ee485adc32b372750e24f49
|
7
|
+
data.tar.gz: c9ed3aed73e9b7e1beda8bdaa55209b6f1b7fc52047c6f494c21b4d7704be560c42541e7db6ebd49e9dddf77db517dd4dd9fbd2c99019b93599e73e948d9a848
|
data/lib/sibit/blockchain.rb
CHANGED
@@ -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(
|
108
|
-
|
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
@@ -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.
|
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-
|
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
|