sibit 0.18.3 → 0.18.8

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: c6805c243e46030be83939f3f77aed146e40aa753693316b649fa465c8f1cacf
4
- data.tar.gz: 4ae1c9f68bc690ea3e73ef1686707c078bd262c4c98f87d6689c7c952bae9845
3
+ metadata.gz: 9754c11ebf54c9b04ce2b44bfc21f58a1758713d51c204b32c03e79e737db1e7
4
+ data.tar.gz: 3abeb42d2a54d543825f0da9244da1cff4c842180e58f94bc8694a38595852ce
5
5
  SHA512:
6
- metadata.gz: f496223f5853ec59fa7b2f4647d06ffc735d7a810cc23b09cecd7621e88657b3fbcdb1d897609060913246dc20e784b916d4d997fd909f1a69e0ace2249e99bb
7
- data.tar.gz: 2da853866f8a5db42323da57b79fbc244c7eccf9d58140a5b1faa33e218f72e12d31b025c1748ab582e86d8f5983166bed3b68ca40c5e92745537d2174072e8d
6
+ metadata.gz: 286f4ac1cbd4244fb7dd7a867e01f36bab27d5cb91813c7d7a5fe5ce9e2a01441eb917e65e8c8f2dc7af87714e71227bfda39ca21e3d5cdc03af26ff950068cf
7
+ data.tar.gz: 681f6f576a93c2ceb67c633022c57157026e8b516cd6a989ef56d7e1e2a6409859ab8db63e053a16ad34cca1046c6fa050354aa8b7113d3487b1376413b50f47
@@ -1,15 +1,11 @@
1
1
  assets:
2
2
  rubygems.yml: yegor256/home#assets/rubygems.yml
3
3
  install: |
4
- export GEM_HOME=~/.ruby
5
- export GEM_PATH=$GEM_HOME:$GEM_PATH
6
- sudo apt-get -y update
7
- sudo gem install pdd -v 0.20.5
8
- bundle install
4
+ pdd -f /dev/null
5
+ sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
9
6
  release:
10
7
  script: |-
11
8
  bundle exec rake
12
- rm -rf *.gem
13
9
  sed -i "s/1\.0\.snapshot/${tag}/g" lib/sibit/version.rb
14
10
  git add lib/sibit/version.rb
15
11
  git commit -m "version set to ${tag}"
@@ -19,7 +15,6 @@ release:
19
15
  merge:
20
16
  script: |-
21
17
  bundle exec rake
22
- pdd -f /dev/null
23
18
  deploy:
24
19
  script: |-
25
20
  echo "There is nothing to deploy"
data/README.md CHANGED
@@ -107,7 +107,7 @@ pkey = sibit.generate
107
107
  address = sibit.create(pkey)
108
108
  balance = sibit.balance(address)
109
109
  target = sibit.create(pkey) # where to send coins to
110
- change = sibit.create(pkey) # where the change will sent to
110
+ change = sibit.create(pkey) # where the change will be sent to
111
111
  tx = sibit.pay(10_000_000, 'XL', { address => pkey }, target, change)
112
112
  ```
113
113
 
@@ -236,6 +236,7 @@ class Sibit
236
236
  break
237
237
  end
238
238
  end
239
+ @log.info("Scanned from #{start} to #{json[:hash]} (#{count} blocks)")
239
240
  json[:hash]
240
241
  end
241
242
 
@@ -45,37 +45,47 @@ class Sibit
45
45
 
46
46
  # Current price of BTC in USD (float returned).
47
47
  def price(_currency = 'USD')
48
- raise Sibit::Error, 'Bitcoinchain API doesn\'t provide BTC price'
48
+ raise Sibit::NotSupportedError, 'Bitcoinchain API doesn\'t provide BTC price'
49
49
  end
50
50
 
51
51
  # The height of the block.
52
52
  def height(_hash)
53
- raise Sibit::Error, 'Bitcoinchain API doesn\'t provide height()'
53
+ raise Sibit::NotSupportedError, 'Bitcoinchain API doesn\'t provide height()'
54
54
  end
55
55
 
56
56
  # Get hash of the block after this one.
57
57
  def next_of(hash)
58
- nxt = Sibit::Json.new(http: @http, log: @log).get(
58
+ block = Sibit::Json.new(http: @http, log: @log).get(
59
59
  URI("https://api-r.bitcoinchain.com/v1/block/#{hash}")
60
- )[0]['next_block']
60
+ )[0]
61
+ raise Sibit::Error, "Block #{hash} not found" if block.nil?
62
+ nxt = block['next_block']
61
63
  nxt = nil if nxt == '0000000000000000000000000000000000000000000000000000000000000000'
64
+ @log.info("The block #{hash} is the latest, there is no next block") if nxt.nil?
65
+ @log.info("The next block of #{hash} is #{nxt}") unless nxt.nil?
62
66
  nxt
63
67
  end
64
68
 
65
69
  # Gets the balance of the address, in satoshi.
66
70
  def balance(address)
67
71
  json = Sibit::Json.new(http: @http, log: @log).get(
68
- URI("https://api-r.bitcoinchain.com/v1/address/#{address}")
72
+ URI("https://api-r.bitcoinchain.com/v1/address/#{address}"),
73
+ accept: [200, 409]
69
74
  )[0]
70
- raise Sibit::Error, "Address #{address} not found" if json.nil?
71
- b = (json['balance'] * 100_000_000).to_i
72
- @log.info("The balance of #{address} is #{b} satoshi")
75
+ b = json['balance']
76
+ if b.nil?
77
+ @log.info("The balance of #{address} is not visible")
78
+ return 0
79
+ end
80
+ b *= 100_000_000
81
+ b = b.to_i
82
+ @log.info("The balance of #{address} is #{b} satoshi (#{json['transactions']} txns)")
73
83
  b
74
84
  end
75
85
 
76
86
  # Get recommended fees, in satoshi per byte.
77
87
  def fees
78
- raise Sibit::Error, 'Not implemented yet'
88
+ raise Sibit::NotSupportedError, 'Not implemented yet'
79
89
  end
80
90
 
81
91
  # Gets the hash of the latest block.
@@ -89,12 +99,12 @@ class Sibit
89
99
 
90
100
  # Fetch all unspent outputs per address.
91
101
  def utxos(_sources)
92
- raise Sibit::Error, 'Not implemented yet'
102
+ raise Sibit::NotSupportedError, 'Not implemented yet'
93
103
  end
94
104
 
95
105
  # Push this transaction (in hex format) to the network.
96
106
  def push(_hex)
97
- raise Sibit::Error, 'Not implemented yet'
107
+ raise Sibit::NotSupportedError, 'Not implemented yet'
98
108
  end
99
109
 
100
110
  # This method should fetch a Blockchain block and return as a hash. Raises
@@ -59,7 +59,7 @@ class Sibit
59
59
 
60
60
  # Get hash of the block after this one.
61
61
  def next_of(_hash)
62
- raise Sibit::Error, 'Blockchain API doesn\'t provide next_of()'
62
+ raise Sibit::NotSupportedError, 'Blockchain API doesn\'t provide next_of()'
63
63
  end
64
64
 
65
65
  # The height of the block.
@@ -75,16 +75,17 @@ class Sibit
75
75
  # Gets the balance of the address, in satoshi.
76
76
  def balance(address)
77
77
  json = Sibit::Json.new(http: @http, log: @log).get(
78
- URI("https://blockchain.info/rawaddr/#{address}")
78
+ URI("https://blockchain.info/rawaddr/#{address}?limit=0"),
79
+ accept: [200, 500]
79
80
  )
80
- @log.info("Total transactions: #{json['n_tx']}")
81
- @log.info("Received/sent: #{json['total_received']}/#{json['total_sent']}")
82
- json['final_balance']
81
+ b = json['final_balance']
82
+ @log.info("The balance of #{address} is #{b} satoshi (#{json['n_tx']} txns)")
83
+ b
83
84
  end
84
85
 
85
86
  # Get recommended fees.
86
87
  def fees
87
- raise Sibit::Error, 'fees() is not provided by Blockchain API'
88
+ raise Sibit::NotSupportedError, 'fees() is not provided by Blockchain API'
88
89
  end
89
90
 
90
91
  # Fetch all unspent outputs per address. The argument is an array
@@ -47,18 +47,18 @@ class Sibit
47
47
 
48
48
  # Current price of BTC in USD (float returned).
49
49
  def price(_currency = 'USD')
50
- raise Sibit::Error, 'Blockchair doesn\'t provide BTC price'
50
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t provide BTC price'
51
51
  end
52
52
 
53
53
  # The height of the block.
54
54
  def height(_hash)
55
- raise Sibit::Error, 'Blockchair API doesn\'t provide height()'
55
+ raise Sibit::NotSupportedError, 'Blockchair API doesn\'t provide height()'
56
56
  end
57
57
 
58
58
  # Get hash of the block after this one.
59
59
  def next_of(_hash)
60
60
  # They don't provide next block hash
61
- raise Sibit::Error, 'Blockchair API doesn\'t provide next_of()'
61
+ raise Sibit::NotSupportedError, 'Blockchair API doesn\'t provide next_of()'
62
62
  end
63
63
 
64
64
  # Gets the balance of the address, in satoshi.
@@ -66,25 +66,29 @@ class Sibit
66
66
  json = Sibit::Json.new(http: @http, log: @log).get(
67
67
  URI("https://api.blockchair.com/bitcoin/dashboards/address/#{address}?#{the_key}")
68
68
  )['data'][address]
69
- raise Sibit::Error, "Address #{address} not found" if json.nil?
70
- b = json['address']['balance']
69
+ if json.nil?
70
+ @log.info("Address #{address} not found")
71
+ return 0
72
+ end
73
+ a = json['address']
74
+ b = a['balance']
71
75
  @log.info("The balance of #{address} is #{b} satoshi")
72
76
  b
73
77
  end
74
78
 
75
79
  # Get recommended fees, in satoshi per byte.
76
80
  def fees
77
- raise Sibit::Error, 'Not implemented yet'
81
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement fees()'
78
82
  end
79
83
 
80
84
  # Gets the hash of the latest block.
81
85
  def latest
82
- raise Sibit::Error, 'Not implemented yet'
86
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement latest()'
83
87
  end
84
88
 
85
89
  # Fetch all unspent outputs per address.
86
90
  def utxos(_sources)
87
- raise Sibit::Error, 'Not implemented yet'
91
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement utxos()'
88
92
  end
89
93
 
90
94
  # Push this transaction (in hex format) to the network.
@@ -93,11 +97,12 @@ class Sibit
93
97
  URI("https://api.blockchair.com/bitcoin/push/transaction?#{the_key}"),
94
98
  "data=#{hex}"
95
99
  )
100
+ @log.info("Transaction (#{hex.length} in hex) has been pushed to Blockchair")
96
101
  end
97
102
 
98
103
  # This method should fetch a Blockchain block and return as a hash.
99
104
  def block(_hash)
100
- raise Sibit::Error, 'Not implemented yet'
105
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement block()'
101
106
  end
102
107
 
103
108
  private
@@ -47,19 +47,18 @@ class Sibit
47
47
 
48
48
  # Current price of BTC in USD (float returned).
49
49
  def price(_currency = 'USD')
50
- raise Sibit::Error, 'Btc.com API doesn\'t provide prices'
50
+ raise Sibit::NotSupportedError, 'Btc.com API doesn\'t provide prices'
51
51
  end
52
52
 
53
53
  # Gets the balance of the address, in satoshi.
54
54
  def balance(address)
55
55
  uri = URI("https://chain.api.btc.com/v3/address/#{address}/unspent")
56
56
  json = Sibit::Json.new(http: @http, log: @log).get(uri)
57
- data = json['data']
58
- if data.nil?
57
+ if json['err_no'] == 1
59
58
  @log.info("The balance of #{address} is zero (not found)")
60
59
  return 0
61
60
  end
62
- txns = data['list']
61
+ txns = json['data']['list']
63
62
  balance = txns.map { |tx| tx['value'] }.inject(&:+) || 0
64
63
  @log.info("The balance of #{address} is #{balance}, total txns: #{txns.count}")
65
64
  balance
@@ -70,8 +69,12 @@ class Sibit
70
69
  head = Sibit::Json.new(http: @http, log: @log).get(
71
70
  URI("https://chain.api.btc.com/v3/block/#{hash}")
72
71
  )
73
- nxt = head['data']['next_block_hash']
72
+ data = head['data']
73
+ raise Sibit::Error, "The block #{hash} not found" if data.nil?
74
+ nxt = data['next_block_hash']
74
75
  nxt = nil if nxt == '0000000000000000000000000000000000000000000000000000000000000000'
76
+ @log.info("The block #{hash} is the latest, there is no next block") if nxt.nil?
77
+ @log.info("The next block of #{hash} is #{nxt}") unless nxt.nil?
75
78
  nxt
76
79
  end
77
80
 
@@ -80,21 +83,25 @@ class Sibit
80
83
  json = Sibit::Json.new(http: @http, log: @log).get(
81
84
  URI("https://chain.api.btc.com/v3/block/#{hash}")
82
85
  )
83
- h = json['data']['height']
86
+ data = json['data']
87
+ raise Sibit::Error, "The block #{hash} not found" if data.nil?
88
+ h = data['height']
84
89
  @log.info("The height of #{hash} is #{h}")
85
90
  h
86
91
  end
87
92
 
88
93
  # Get recommended fees, in satoshi per byte.
89
94
  def fees
90
- raise Sibit::Error, 'Btc.com doesn\'t provide recommended fees'
95
+ raise Sibit::NotSupportedError, 'Btc.com doesn\'t provide recommended fees'
91
96
  end
92
97
 
93
98
  # Gets the hash of the latest block.
94
99
  def latest
95
100
  uri = URI('https://chain.api.btc.com/v3/block/latest')
96
101
  json = Sibit::Json.new(http: @http, log: @log).get(uri)
97
- hash = json['data']['hash']
102
+ data = json['data']
103
+ raise Sibit::Error, 'The latest block not found' if data.nil?
104
+ hash = data['hash']
98
105
  @log.info("The hash of the latest block is #{hash}")
99
106
  hash
100
107
  end
@@ -106,7 +113,9 @@ class Sibit
106
113
  json = Sibit::Json.new(http: @http, log: @log).get(
107
114
  URI("https://chain.api.btc.com/v3/address/#{hash}/unspent")
108
115
  )
109
- json['data']['list'].each do |u|
116
+ data = json['data']
117
+ raise Sibit::Error, "The address #{hash} not found" if data.nil?
118
+ data['list'].each do |u|
110
119
  outs = Sibit::Json.new(http: @http, log: @log).get(
111
120
  URI("https://chain.api.btc.com/v3/tx/#{u['tx_hash']}?verbose=3")
112
121
  )['data']['outputs']
@@ -127,7 +136,7 @@ class Sibit
127
136
 
128
137
  # Push this transaction (in hex format) to the network.
129
138
  def push(_hex)
130
- raise Sibit::Error, 'Btc.com doesn\'t provide payment gateway'
139
+ raise Sibit::NotSupportedError, 'Btc.com doesn\'t provide payment gateway'
131
140
  end
132
141
 
133
142
  # This method should fetch a Blockchain block and return as a hash.
@@ -135,13 +144,15 @@ class Sibit
135
144
  head = Sibit::Json.new(http: @http, log: @log).get(
136
145
  URI("https://chain.api.btc.com/v3/block/#{hash}")
137
146
  )
138
- nxt = head['data']['next_block_hash']
147
+ data = head['data']
148
+ raise Sibit::Error, "The block #{hash} not found" if data.nil?
149
+ nxt = data['next_block_hash']
139
150
  nxt = nil if nxt == '0000000000000000000000000000000000000000000000000000000000000000'
140
151
  {
141
- hash: head['data']['hash'],
142
- orphan: head['data']['is_orphan'],
152
+ hash: data['hash'],
153
+ orphan: data['is_orphan'],
143
154
  next: nxt,
144
- previous: head['data']['prev_block_hash'],
155
+ previous: data['prev_block_hash'],
145
156
  txns: txns(hash)
146
157
  }
147
158
  end
@@ -54,41 +54,41 @@ class Sibit
54
54
 
55
55
  # Get hash of the block after this one.
56
56
  def next_of(_hash)
57
- raise Sibit::Error, 'Cex.io API doesn\'t provide next_of()'
57
+ raise Sibit::NotSupportedError, 'Cex.io API doesn\'t provide next_of()'
58
58
  end
59
59
 
60
60
  # Gets the balance of the address, in satoshi.
61
61
  def balance(_address)
62
- raise Sibit::Error, 'Cex.io doesn\'t implement balance()'
62
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement balance()'
63
63
  end
64
64
 
65
65
  # The height of the block.
66
66
  def height(_hash)
67
- raise Sibit::Error, 'Cex.io doesn\'t implement height()'
67
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement height()'
68
68
  end
69
69
 
70
70
  # Get recommended fees, in satoshi per byte.
71
71
  def fees
72
- raise Sibit::Error, 'Cex.io doesn\'t implement fees()'
72
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement fees()'
73
73
  end
74
74
 
75
75
  # Gets the hash of the latest block.
76
76
  def latest
77
- raise Sibit::Error, 'Cex.io doesn\'t implement latest()'
77
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement latest()'
78
78
  end
79
79
 
80
80
  # Fetch all unspent outputs per address.
81
81
  def utxos(_sources)
82
- raise Sibit::Error, 'Cex.io doesn\'t implement utxos()'
82
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement utxos()'
83
83
  end
84
84
 
85
85
  # Push this transaction (in hex format) to the network.
86
86
  def push(_hex)
87
- raise Sibit::Error, 'Cex.io doesn\'t implement push()'
87
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement push()'
88
88
  end
89
89
 
90
90
  def block(_hash)
91
- raise Sibit::Error, 'Cex.io doesn\'t implement block()'
91
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement block()'
92
92
  end
93
93
  end
94
94
  end
@@ -46,15 +46,18 @@ class Sibit
46
46
 
47
47
  # Current price of BTC in USD (float returned).
48
48
  def price(_currency = 'USD')
49
- raise Sibit::Error, 'Cryptoapis doesn\'t provide BTC price'
49
+ raise Sibit::NotSupportedError, 'Cryptoapis doesn\'t provide BTC price'
50
50
  end
51
51
 
52
52
  # Get hash of the block after this one.
53
53
  def next_of(hash)
54
- Sibit::Json.new(http: @http, log: @log).get(
54
+ nxt = Sibit::Json.new(http: @http, log: @log).get(
55
55
  URI("https://api.cryptoapis.io/v1/bc/btc/mainnet/blocks/#{hash}"),
56
56
  headers: headers
57
57
  )['payload']['hash']
58
+ @log.info("The block #{hash} is the latest, there is no next block") if nxt.nil?
59
+ @log.info("The next block of #{hash} is #{nxt}") unless nxt.nil?
60
+ nxt
58
61
  end
59
62
 
60
63
  # The height of the block.
@@ -81,7 +84,7 @@ class Sibit
81
84
 
82
85
  # Get recommended fees, in satoshi per byte.
83
86
  def fees
84
- raise Sibit::Error, 'Cryptoapis doesn\'t provide recommended fees'
87
+ raise Sibit::NotSupportedError, 'Cryptoapis doesn\'t provide recommended fees'
85
88
  end
86
89
 
87
90
  # Gets the hash of the latest block.
@@ -96,7 +99,7 @@ class Sibit
96
99
 
97
100
  # Fetch all unspent outputs per address.
98
101
  def utxos(_sources)
99
- raise Sibit::Error, 'Not implemented yet'
102
+ raise Sibit::NotSupportedError, 'Not implemented yet'
100
103
  end
101
104
 
102
105
  # Push this transaction (in hex format) to the network.
@@ -44,22 +44,22 @@ class Sibit
44
44
 
45
45
  # Current price of BTC in USD (float returned).
46
46
  def price(_currency)
47
- raise Sibit::Error, 'price() doesn\'t work here'
47
+ raise Sibit::NotSupportedError, 'price() doesn\'t work here'
48
48
  end
49
49
 
50
50
  # Gets the balance of the address, in satoshi.
51
51
  def balance(_address)
52
- raise Sibit::Error, 'balance() doesn\'t work here'
52
+ raise Sibit::NotSupportedError, 'balance() doesn\'t work here'
53
53
  end
54
54
 
55
55
  # Get hash of the block after this one.
56
56
  def next_of(_hash)
57
- raise Sibit::Error, 'Earn.com API doesn\'t provide next_of()'
57
+ raise Sibit::NotSupportedError, 'Earn.com API doesn\'t provide next_of()'
58
58
  end
59
59
 
60
60
  # The height of the block.
61
61
  def height(_hash)
62
- raise Sibit::Error, 'Earn API doesn\'t provide height()'
62
+ raise Sibit::NotSupportedError, 'Earn API doesn\'t provide height()'
63
63
  end
64
64
 
65
65
  # Get recommended fees, in satoshi per byte. The method returns
@@ -69,7 +69,7 @@ class Sibit
69
69
  URI('https://bitcoinfees.earn.com/api/v1/fees/recommended')
70
70
  )
71
71
  @log.info("Current recommended Bitcoin fees: \
72
- #{json['hourFee']}/#{json['halfHourFee']}/#{json['fastestFee']} sat/byte")
72
+ #{json['hourFee']}/#{json['halfHourFee']}/#{json['fastestFee']} sat/byte")
73
73
  {
74
74
  S: json['hourFee'] / 3,
75
75
  M: json['hourFee'],
@@ -80,22 +80,22 @@ class Sibit
80
80
 
81
81
  # Fetch all unspent outputs per address.
82
82
  def utxos(_sources)
83
- raise Sibit::Error, 'Not implemented yet'
83
+ raise Sibit::NotSupportedError, 'Not implemented yet'
84
84
  end
85
85
 
86
86
  # Push this transaction (in hex format) to the network.
87
87
  def push(_hex)
88
- raise Sibit::Error, 'Not implemented yet'
88
+ raise Sibit::NotSupportedError, 'Not implemented yet'
89
89
  end
90
90
 
91
91
  # Gets the hash of the latest block.
92
92
  def latest
93
- raise Sibit::Error, 'latest() doesn\'t work here'
93
+ raise Sibit::NotSupportedError, 'latest() doesn\'t work here'
94
94
  end
95
95
 
96
96
  # This method should fetch a Blockchain block and return as a hash.
97
97
  def block(_hash)
98
- raise Sibit::Error, 'block() doesn\'t work here'
98
+ raise Sibit::NotSupportedError, 'block() doesn\'t work here'
99
99
  end
100
100
  end
101
101
  end
@@ -28,4 +28,7 @@
28
28
  class Sibit
29
29
  # The error.
30
30
  class Error < StandardError; end
31
+
32
+ # The operation is not supported.
33
+ class NotSupportedError < Error; end
31
34
  end
@@ -48,7 +48,7 @@ class Sibit
48
48
  # Send GET request to the HTTP and return JSON response.
49
49
  # This method will also log the process and will validate the
50
50
  # response for correctness.
51
- def get(uri, headers: {})
51
+ def get(uri, headers: {}, accept: [200])
52
52
  start = Time.now
53
53
  res = @http.client(uri).get(
54
54
  "#{uri.path.empty? ? '/' : uri.path}#{uri.query ? "?#{uri.query}" : ''}",
@@ -59,7 +59,7 @@ class Sibit
59
59
  'Accept-Encoding' => ''
60
60
  }.merge(headers)
61
61
  )
62
- unless res.code == '200'
62
+ unless accept.include?(res.code.to_i)
63
63
  raise Sibit::Error, "Failed to retrieve #{uri} (#{res.code}): #{res.body}"
64
64
  end
65
65
  @log.info("GET #{uri}: #{res.code}/#{res.body.length}b in #{age(start)}")
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.18.3'
29
+ VERSION = '0.18.8'
30
30
  end
@@ -36,9 +36,9 @@ Gem::Specification.new do |s|
36
36
  s.version = Sibit::VERSION
37
37
  s.license = 'MIT'
38
38
  s.summary = 'Simple Bitcoin Client'
39
- s.description = 'This is a simple Bitcoin client, to use from command line \
40
- or from your Ruby app. You don\'t need to run any Bitcoin software, \
41
- no need to install anything, etc. All you need is just a command line \
39
+ s.description = 'This is a simple Bitcoin client, to use from command line
40
+ or from your Ruby app. You don\'t need to run any Bitcoin software,
41
+ no need to install anything, etc. All you need is just a command line
42
42
  and Ruby 2.3+.'
43
43
  s.authors = ['Yegor Bugayenko']
44
44
  s.email = 'yegor256@gmail.com'
@@ -34,7 +34,8 @@ class TestBlockchair < Minitest::Test
34
34
  def test_fetch_balance
35
35
  hash = '1GkQmKAmHtNfnD3LHhTkewJxKHVSta4m2a'
36
36
  stub_request(:get, "https://api.blockchair.com/bitcoin/dashboards/address/#{hash}")
37
- .to_return(body: "{\"data\": {\"#{hash}\": {\"address\": {\"balance\": 1}}}}")
37
+ .to_return(body: "{\"data\": {\"#{hash}\": {\"address\":
38
+ {\"balance\": 1, \"transactions\": []}}}}")
38
39
  sibit = Sibit::Blockchair.new
39
40
  satoshi = sibit.balance(hash)
40
41
  assert_equal(1, satoshi)
@@ -23,6 +23,7 @@
23
23
  require 'minitest/autorun'
24
24
  require 'webmock/minitest'
25
25
  require 'json'
26
+ require 'backtrace'
26
27
  require_relative '../lib/sibit'
27
28
 
28
29
  # Live tests.
@@ -60,6 +61,14 @@ class TestLive < Minitest::Test
60
61
  end
61
62
  end
62
63
 
64
+ def test_absent_balance
65
+ for_each do |api|
66
+ hash = '12NJ7DxjBMCkk7EFdb6nXnMsuJV1nAXGiM'
67
+ satoshi = api.balance(hash)
68
+ assert_equal(0, satoshi)
69
+ end
70
+ end
71
+
63
72
  def test_latest
64
73
  for_each do |api|
65
74
  hash = api.latest
@@ -108,14 +117,14 @@ class TestLive < Minitest::Test
108
117
  skip if ENV['skip_live']
109
118
  WebMock.allow_net_connect!
110
119
  apis = []
120
+ require_relative '../lib/sibit/btc'
121
+ apis << Sibit::Btc.new
111
122
  require_relative '../lib/sibit/blockchain'
112
123
  apis << Sibit::Blockchain.new
113
124
  require_relative '../lib/sibit/blockchair'
114
125
  apis << Sibit::Blockchair.new
115
126
  require_relative '../lib/sibit/cryptoapis'
116
127
  apis << Sibit::Cryptoapis.new('')
117
- require_relative '../lib/sibit/btc'
118
- apis << Sibit::Btc.new
119
128
  require_relative '../lib/sibit/cex'
120
129
  apis << Sibit::Cex.new
121
130
  require_relative '../lib/sibit/bitcoinchain'
@@ -124,7 +133,7 @@ class TestLive < Minitest::Test
124
133
  begin
125
134
  yield api
126
135
  rescue Sibit::Error => e
127
- puts e.message
136
+ puts Backtrace.new(e).to_s
128
137
  end
129
138
  end
130
139
  end
@@ -87,7 +87,7 @@ class TestSibit < Minitest::Test
87
87
  def test_get_balance
88
88
  stub_request(
89
89
  :get,
90
- 'https://blockchain.info/rawaddr/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f'
90
+ 'https://blockchain.info/rawaddr/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f?limit=0'
91
91
  ).to_return(body: '{"final_balance": 100}')
92
92
  sibit = Sibit.new
93
93
  balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
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.18.3
4
+ version: 0.18.8
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-27 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -249,9 +249,9 @@ dependencies:
249
249
  - !ruby/object:Gem::Version
250
250
  version: 3.7.6
251
251
  description: |-
252
- This is a simple Bitcoin client, to use from command line \
253
- or from your Ruby app. You don't need to run any Bitcoin software, \
254
- no need to install anything, etc. All you need is just a command line \
252
+ This is a simple Bitcoin client, to use from command line
253
+ or from your Ruby app. You don't need to run any Bitcoin software,
254
+ no need to install anything, etc. All you need is just a command line
255
255
  and Ruby 2.3+.
256
256
  email: yegor256@gmail.com
257
257
  executables: