rubybear 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +77 -0
  4. data/LICENSE +41 -0
  5. data/README.md +559 -0
  6. data/Rakefile +140 -0
  7. data/gource.sh +8 -0
  8. data/images/Anthony Martin.png +0 -0
  9. data/images/Marvin Hofmann.jpg +0 -0
  10. data/images/Marvin Hofmann.png +0 -0
  11. data/lib/bears.rb +17 -0
  12. data/lib/rubybear.rb +45 -0
  13. data/lib/rubybear/account_by_key_api.rb +7 -0
  14. data/lib/rubybear/account_history_api.rb +15 -0
  15. data/lib/rubybear/api.rb +907 -0
  16. data/lib/rubybear/base_error.rb +23 -0
  17. data/lib/rubybear/block_api.rb +14 -0
  18. data/lib/rubybear/broadcast_operations.json +500 -0
  19. data/lib/rubybear/chain.rb +299 -0
  20. data/lib/rubybear/chain_config.rb +22 -0
  21. data/lib/rubybear/chain_stats_api.rb +15 -0
  22. data/lib/rubybear/condenser_api.rb +99 -0
  23. data/lib/rubybear/database_api.rb +5 -0
  24. data/lib/rubybear/error_parser.rb +228 -0
  25. data/lib/rubybear/follow_api.rb +7 -0
  26. data/lib/rubybear/logger.rb +20 -0
  27. data/lib/rubybear/market_history_api.rb +19 -0
  28. data/lib/rubybear/methods.json +498 -0
  29. data/lib/rubybear/mixins/acts_as_poster.rb +124 -0
  30. data/lib/rubybear/mixins/acts_as_voter.rb +50 -0
  31. data/lib/rubybear/mixins/acts_as_wallet.rb +67 -0
  32. data/lib/rubybear/network_broadcast_api.rb +7 -0
  33. data/lib/rubybear/operation.rb +101 -0
  34. data/lib/rubybear/operation_ids.rb +98 -0
  35. data/lib/rubybear/operation_types.rb +139 -0
  36. data/lib/rubybear/stream.rb +527 -0
  37. data/lib/rubybear/tag_api.rb +33 -0
  38. data/lib/rubybear/transaction.rb +306 -0
  39. data/lib/rubybear/type/amount.rb +57 -0
  40. data/lib/rubybear/type/array.rb +17 -0
  41. data/lib/rubybear/type/beneficiaries.rb +29 -0
  42. data/lib/rubybear/type/future.rb +18 -0
  43. data/lib/rubybear/type/hash.rb +17 -0
  44. data/lib/rubybear/type/permission.rb +19 -0
  45. data/lib/rubybear/type/point_in_time.rb +19 -0
  46. data/lib/rubybear/type/price.rb +25 -0
  47. data/lib/rubybear/type/public_key.rb +18 -0
  48. data/lib/rubybear/type/serializer.rb +12 -0
  49. data/lib/rubybear/type/u_int16.rb +19 -0
  50. data/lib/rubybear/type/u_int32.rb +19 -0
  51. data/lib/rubybear/utils.rb +170 -0
  52. data/lib/rubybear/version.rb +4 -0
  53. data/rubybear.gemspec +40 -0
  54. metadata +412 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9476e281a285a4c7e99d47c1d802a22bf898b2727ec67366ee8e5371a5d45eb6
4
+ data.tar.gz: 15b98b10a58c6444759930c5e2bd96ed521599506561e9abe7ecf1a50138f9eb
5
+ SHA512:
6
+ metadata.gz: 825f0511ef7d5e0a7002d8ae85ae0d9aadf6f94d1a7fc92dc52827e0c1bf7180663c39a9a9155cdaa6492ad275ca1004ccf99593f5941e53acf677cef70b2e4b
7
+ data.tar.gz: 2580d9ed972a118a39861c4914ba82c627ab9f02a2955ca99adaebaa466334b4f5eae522c53eaee2f1afc699dcb685d51cc915d518913b659ff785502d10e054
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubybear (0.0.1)
5
+ awesome_print (~> 1.7, >= 1.7.0)
6
+ bitcoin-ruby (~> 0.0, >= 0.0.11)
7
+ ffi (~> 1.9, >= 1.9.18)
8
+ hashie (~> 3.5, >= 3.5.5)
9
+ json (~> 2.0, >= 2.0.2)
10
+ logging (~> 2.2, >= 2.2.0)
11
+ net-http-persistent (>= 2.5.2)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ addressable (2.5.2)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ awesome_print (1.8.0)
19
+ bitcoin-ruby (0.0.18)
20
+ coderay (1.1.2)
21
+ connection_pool (2.2.2)
22
+ crack (0.4.3)
23
+ safe_yaml (~> 1.0.0)
24
+ docile (1.3.1)
25
+ ffi (1.9.25)
26
+ hashdiff (0.3.7)
27
+ hashie (3.6.0)
28
+ json (2.1.0)
29
+ little-plugger (1.1.4)
30
+ logging (2.2.2)
31
+ little-plugger (~> 1.1)
32
+ multi_json (~> 1.10)
33
+ method_source (0.9.2)
34
+ minitest (5.11.3)
35
+ minitest-line (0.6.5)
36
+ minitest (~> 5.0)
37
+ minitest-proveit (1.0.0)
38
+ minitest (> 5, < 7)
39
+ multi_json (1.13.1)
40
+ net-http-persistent (3.0.0)
41
+ connection_pool (~> 2.2)
42
+ pry (0.12.2)
43
+ coderay (~> 1.1.0)
44
+ method_source (~> 0.9.0)
45
+ public_suffix (3.0.3)
46
+ rake (12.3.1)
47
+ safe_yaml (1.0.4)
48
+ simplecov (0.16.1)
49
+ docile (~> 1.1)
50
+ json (>= 1.8, < 3)
51
+ simplecov-html (~> 0.10.0)
52
+ simplecov-html (0.10.2)
53
+ vcr (4.0.0)
54
+ webmock (3.4.2)
55
+ addressable (>= 2.3.6)
56
+ crack (>= 0.3.2)
57
+ hashdiff
58
+ yard (0.9.16)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ bundler (~> 1.15, >= 1.15.4)
65
+ minitest (~> 5.10, >= 5.10.3)
66
+ minitest-line (~> 0.6.3)
67
+ minitest-proveit (~> 1.0, >= 1.0.0)
68
+ pry (~> 0.11, >= 0.11.3)
69
+ rubybear!
70
+ rake (~> 12.1, >= 12.1.0)
71
+ simplecov (~> 0.16.1)
72
+ vcr (~> 4.0, >= 4.0.0)
73
+ webmock (~> 3.1, >= 3.1.0)
74
+ yard (~> 0.9.9)
75
+
76
+ BUNDLED WITH
77
+ 1.16.5
data/LICENSE ADDED
@@ -0,0 +1,41 @@
1
+ CC0 1.0 Universal (CC0 1.0)
2
+ Public Domain Dedication
3
+ https://creativecommons.org/publicdomain/zero/1.0/
4
+
5
+ This is a human-readable summary of the Legal Code:
6
+ https://creativecommons.org/publicdomain/zero/1.0/legalcode
7
+
8
+ Disclaimer
9
+
10
+ The Commons Deed is not a legal instrument. It is simply a handy reference for
11
+ understanding the CC0 Legal Code, a human-readable expression of some of its key
12
+ terms. Think of it as the user-friendly interface to the CC0 Legal Code beneath.
13
+ This Deed itself has no legal value, and its contents do not appear in CC0.
14
+ Creative Commons is not a law firm and does not provide legal services.
15
+ Distributing, displaying, or linking to this Commons Deed does not create an
16
+ attorney-client relationship.
17
+
18
+ Creative Commons has not verified the copyright status of any work to which CC0
19
+ has been applied. CC makes no warranties about any work or its copyright status
20
+ in any jurisdiction, and disclaims all liability for all uses of any work.
21
+
22
+ No Copyright
23
+
24
+ The person who associated a work with this deed has dedicated the work to the
25
+ public domain by waiving all of his or her rights to the work worldwide under
26
+ copyright law, including all related and neighboring rights, to the extent
27
+ allowed by law.
28
+
29
+ You can copy, modify, distribute and perform the work, even for commercial
30
+ purposes, all without asking permission. See Other Information below.
31
+
32
+ Other Information
33
+
34
+ * In no way are the patent or trademark rights of any person affected by CC0,
35
+ nor are the rights that other persons may have in the work or in how the work
36
+ is used, such as publicity or privacy rights.
37
+ * Unless expressly stated otherwise, the person who associated a work with this
38
+ deed makes no warranties about the work, and disclaims liability for all uses
39
+ of the work, to the fullest extent permitted by applicable law.
40
+ * When using or citing the work, you should not imply endorsement by the author
41
+ or the affirmer.
@@ -0,0 +1,559 @@
1
+ [![Build Status](https://travis-ci.org/bearshares/rubybear.svg?branch=master)](https://travis-ci.org/bearshares/rubybear)
2
+ [![Code Climate](https://codeclimate.com/github/bearshares/rubybear/badges/gpa.svg)](https://codeclimate.com/github/bearshares/rubybear)
3
+ [![Test Coverage](https://codeclimate.com/github/bearshares/rubybear/badges/coverage.svg)](https://codeclimate.com/github/bearshares/rubybear)
4
+ [![Inline docs](http://inch-ci.org/github/bearshares/rubybear.svg?branch=master&style=shields)](http://inch-ci.org/github/bearshares/rubybear)
5
+
6
+ [rubybear](https://github.com/bearshares/rubybear)
7
+ ========
8
+
9
+ #### BEARS Ruby API Client
10
+
11
+ Rubybear is an API Client for interaction with the BEARS network using Ruby.
12
+
13
+ #### Changes in v0.4.0
14
+
15
+ * Gem updates
16
+ * **AppBase Support**
17
+ * Defaulting to `condenser_api.*` in `Rubybear::Api` (see below)
18
+ * Handle/recover from new `AppBase` errors.
19
+ * `Rubybear::Stream` now detects if it's stalled and takes action if it has to wait too long for a new block.
20
+ 1. Exponential back-off for stalls so that the node doesn't get slammed.
21
+ 2. Short delays (3 times block production) only result in a warning.
22
+ 3. Long delays (6 times block production) may try to switch to an alternate node.
23
+ * Fixed internal logging bug that would open too many files.
24
+ * This fix also mitigates issues like `SSL Verify` problems (similar to [#12](https://github.com/bearshares/rubybear/issues/12))
25
+ * Dropped GOLOS support.
26
+
27
+ **Appbase is now supported.**
28
+
29
+ If you were already using `Rubybear::Api` then there is nothing to change. But if you made use of other API classes, like `Rubybear::FollowApi`, then the method signatures have changed.
30
+
31
+ **Pre-AppBase:**
32
+
33
+ ```ruby
34
+ api = Rubybear::FollowApi.new
35
+
36
+ api.get_followers('inertia', 0, 'blog', 10)
37
+ ```
38
+
39
+ **New Signature:**
40
+
41
+ ```ruby
42
+ api = Rubybear::FollowApi.new
43
+
44
+ api.get_followers(account: 'inertia', start: 0, type: 'blog', limit: 10)
45
+ ```
46
+
47
+ *-- or --*
48
+
49
+ **Switch to Condenser API:**
50
+
51
+ The other strategy for using this version of Rubybear is to just switch away from classes like `Rubybear::FollowApi` over to `Rubybear::Api` (also known as `Rubybear::CondenserApi`) instead. Then you don't have to update individual method calls.
52
+
53
+ ```ruby
54
+ api = Rubybear::Api.new
55
+
56
+ api.get_followers('inertia', 0, 'blog', 10)
57
+ ```
58
+
59
+ **Note about GOLOS**
60
+
61
+ GOLOS is no longer supported in Rubybear. If you want to continue to use GOLOS, you'll need to branch from v0.3.15 (pre-appbase) and add WebSockets support because GOLOS completely dropped JSON-RPC over HTTP clients support for some reason
62
+
63
+ Rubybear has never and will never use WebSockets due to its server scalability requirements.
64
+
65
+ From a client perspective, WebSockets is *great*. **I have nothing against WebSockets.** So I might get around to it at some point, but GOLOS won't be part of Rubybear anymore mainly because GOLOS has no plans to implement AppBase.
66
+
67
+ #### Changes in v0.3.0
68
+
69
+ * Gem updates
70
+ * Added failover subroutines (see Failover section, below).
71
+ * Added method closures support (aka passing a block to yield).
72
+ * You can now stream virtual operations (see Streaming section, below).
73
+ * Added more [documentation](http://www.rubydoc.info/gems/rubybear).
74
+ * Added/expanded more api namespaces: `::BlockApi`, `::CondenserApi`, `::TagApi`
75
+ * Addressed an issue with logging on certain Windows configurations.
76
+
77
+ #### Fixes in v0.2.3
78
+
79
+ * Gem updates
80
+ * Added low-level support for persistence and retrying API requests.
81
+ * Now using exponential back-off for retries.
82
+ * Detecting presence of `transaction_ids` (if enabled by the node).
83
+ * Default for `Hashie` warnings now go to `/dev/null`, where they belong.
84
+ * Added stray methods/operations.
85
+
86
+ #### Fixes in v0.2.2
87
+
88
+ * Gem updates
89
+ * Improved support for datatypes and handlers.
90
+ * UTF-8 handled more smoothly.
91
+ * Simplified operation construction.
92
+ * Improved keep-alive defaults.
93
+ * Better streaming reliability.
94
+
95
+ ---
96
+
97
+ Also see: [Documentation](http://www.rubydoc.info/gems/rubybear)
98
+
99
+ ---
100
+
101
+ ### Quick Start
102
+
103
+ Add the gem to your Gemfile:
104
+
105
+ ```ruby
106
+ gem 'rubybear'
107
+ ```
108
+
109
+ Then:
110
+
111
+ ```bash
112
+ $ bundle install
113
+ ```
114
+
115
+ If you don't have `bundler`, see the next section.
116
+
117
+ ### Prerequisites
118
+
119
+ `minimum ruby version: 2.2`
120
+
121
+ #### Linux
122
+
123
+ ```bash
124
+ $ sudo apt-get install ruby-full git openssl libssl1.0.0 libssl-dev
125
+ $ gem install bundler
126
+ ```
127
+
128
+ #### macOS
129
+
130
+ ```
131
+ $ gem install bundler
132
+ ```
133
+
134
+ ### Usage
135
+
136
+ ```ruby
137
+ require 'rubybear'
138
+
139
+ api = Rubybear::Api.new
140
+ api.get_dynamic_global_properties do |properties|
141
+ properties.virtual_supply
142
+ end
143
+ => "271342874.337 BEARS"
144
+ ```
145
+
146
+ ... or ...
147
+
148
+ ```ruby
149
+ require 'rubybear'
150
+
151
+ api = Rubybear::Api.new
152
+ response = api.get_dynamic_global_properties
153
+ response.result.virtual_supply
154
+ => "271342874.337 BEARS"
155
+ ```
156
+
157
+ #### Follower API
158
+
159
+ ```ruby
160
+ api = Rubybear::FollowApi.new
161
+ api.get_followers(account: 'inertia', start: 0, type: 'blog', limit: 100) do |followers|
162
+ followers.map(&:follower)
163
+ end
164
+ => ["a11at",
165
+ "abarefootpoet",
166
+ "abit",
167
+ "alexgr",
168
+ "alexoz",
169
+ "andressilvera",
170
+ "applecrisp",
171
+ "arrowj",
172
+ "artificial",
173
+ "ash",
174
+ "ausbitbank",
175
+ "beachbum",
176
+ "ben99",
177
+ "benadapt",
178
+ .
179
+ .
180
+ .
181
+ "bearszine"]
182
+ ```
183
+
184
+ #### Streaming
185
+
186
+ Here's an example of how to use a streaming instance to listen for votes:
187
+
188
+ ```ruby
189
+ require 'rubybear'
190
+
191
+ stream = Rubybear::Stream.new
192
+
193
+ stream.operations(:vote) do |op|
194
+ print "#{op.voter} voted for #{op.author}"
195
+ puts " (weight: #{op.weight / 100.0}%)"
196
+ end
197
+ ```
198
+
199
+ The output would look like this and continue until interrupted.
200
+
201
+ ```
202
+ richman voted for krnel (weight: 100.0%)
203
+ rainchen voted for rainchen (weight: 100.0%)
204
+ richman voted for exploretraveler (weight: 100.0%)
205
+ jlufer voted for michaelstobiersk (weight: 100.0%)
206
+ jlufer voted for michaelstobiersk (weight: 100.0%)
207
+ patelincho voted for borishaifa (weight: 100.0%)
208
+ richman voted for vetvso (weight: 100.0%)
209
+ jlufer voted for michaelstobiersk (weight: 100.0%)
210
+ richman voted for orcish (weight: 100.0%)
211
+ demotruk voted for skeptic (weight: -100.0%)
212
+ photorealistic voted for oecp85 (weight: 100.0%)
213
+ meesterboom voted for rubenalexander (weight: 100.0%)
214
+ thecurator voted for robyneggs (weight: 40.0%)
215
+ richman voted for originate (weight: 100.0%)
216
+ helikopterben voted for etcmike (weight: 100.0%)
217
+ .
218
+ .
219
+ .
220
+ ```
221
+
222
+ You can also just stream all operations like this:
223
+
224
+ ```ruby
225
+ stream.operations do |op|
226
+ puts op.to_json
227
+ end
228
+ ```
229
+
230
+ Example of the output:
231
+
232
+ ```json
233
+ {
234
+ "vote":{
235
+ "voter":"abudar",
236
+ "author":"rangkangandroid",
237
+ "permlink":"the-kalinga-tattoo-maker",
238
+ "weight":10000
239
+ }
240
+ }
241
+ {
242
+ "vote":{
243
+ "voter":"shenburen",
244
+ "author":"masteryoda",
245
+ "permlink":"daily-payouts-leaderboards-september-16",
246
+ "weight":10000
247
+ }
248
+ }
249
+ {
250
+ "vote":{
251
+ "voter":"stiletto",
252
+ "author":"fyrstikken",
253
+ "permlink":"everybody-hating-me",
254
+ "weight":2500
255
+ }
256
+ }
257
+ {
258
+ "comment":{
259
+ "parent_author":"mariandavp",
260
+ "parent_permlink":"re-onceuponatime-re-mariandavp-the-bridge-original-artwork-by-mariandavp-20160906t182016608z",
261
+ "author":"onceuponatime",
262
+ "permlink":"re-mariandavp-re-onceuponatime-re-mariandavp-the-bridge-original-artwork-by-mariandavp-20160917t054726763z",
263
+ "title":"",
264
+ "body":"https://www.bearsimg.com/images/2016/09/17/oldcomputerpics551cb14c.jpg",
265
+ "json_metadata":"{\"tags\":[\"art\"],\"image\":[\"https://www.bearsimg.com/images/2016/09/17/oldcomputerpics551cb14c.jpg\"]}"
266
+ }
267
+ }
268
+ {
269
+ "vote":{
270
+ "voter":"abudar",
271
+ "author":"rangkangandroid",
272
+ "permlink":"the-journey-north-through-the-eyes-of-kalinga-tradition",
273
+ "weight":10000
274
+ }
275
+ }
276
+ {
277
+ "limit_order_cancel":{
278
+ "owner":"fnait",
279
+ "orderid":2755220300
280
+ }
281
+ }
282
+ .
283
+ .
284
+ .
285
+ ```
286
+
287
+ You can also stream virtual operations:
288
+
289
+ ```ruby
290
+ stream.operations(:producer_reward) do |op|
291
+ puts "#{op.producer} got a reward: #{op.coining_shares}"
292
+ end
293
+ ```
294
+
295
+ Example of the output:
296
+
297
+ ```
298
+ anyx got a reward: 390.974648 COINS
299
+ gtg got a reward: 390.974647 COINS
300
+ someguy123 got a reward: 390.974646 COINS
301
+ jesta got a reward: 390.974646 COINS
302
+ blocktrades got a reward: 390.974645 COINS
303
+ timcliff got a reward: 390.974644 COINS
304
+ bhuz got a reward: 1961.046504 COINS
305
+ .
306
+ .
307
+ .
308
+ ```
309
+
310
+ Transactions are supported:
311
+
312
+ ```ruby
313
+ stream.transactions do |tx, trx_id|
314
+ puts "[#{trx_id}] #{tx.to_json}"
315
+ end
316
+ ```
317
+
318
+ Example of the output:
319
+
320
+ ```json
321
+ {
322
+ "ref_block_num":59860,
323
+ "ref_block_prefix":2619183808,
324
+ "expiration":"2016-09-17T06:03:21",
325
+ "operations":[
326
+ [
327
+ "custom_json",
328
+ {
329
+ "required_auths":[
330
+
331
+ ],
332
+ "required_posting_auths":[
333
+ "acidpanda"
334
+ ],
335
+ "id":"follow",
336
+ "json":"[\"follow\",{\"follower\":\"acidpanda\",\"following\":\"gavvet\",\"what\":[\"blog\"]}]"
337
+ }
338
+ ]
339
+ ],
340
+ "extensions":[],
341
+ "signatures":[
342
+ "2048d7e32cc843adea0e11aa617dc9cdc773d0e9a0a0d0cd58d67a9fcd8fa2d2305d1bb611ac219fbd3b6a77ab60071df94fe193aae33591ee669cc7404d4e4ec4"
343
+ ]
344
+ }
345
+ .
346
+ .
347
+ .
348
+ ```
349
+
350
+ Even whole blocks:
351
+
352
+ ```ruby
353
+ stream.blocks do |bk, num|
354
+ puts "[#{num}] #{bk.to_json}"
355
+ end
356
+ ```
357
+
358
+ Example of the output:
359
+
360
+ ```json
361
+ {
362
+ "previous":"004cea0d46a4b91cffe7bb71763ad2ab854c6efd",
363
+ "timestamp":"2016-09-17T06:05:51",
364
+ "witness":"boatymcboatface",
365
+ "transaction_merkle_root":"0000000000000000000000000000000000000000",
366
+ "extensions":[],
367
+ "witness_signature":"2034b0d7398ed1c0d7511ac76c6dedaf227e609dc2676d13f926ddd1e9df7fa9cb254af122a4a82dc619a1091c87293cbd9e2db1b51404fdc8fb62f8e5f37b4625",
368
+ "transactions":[]
369
+ }
370
+ .
371
+ .
372
+ .
373
+ ```
374
+
375
+ #### Transaction Signing
376
+
377
+ Rubybear supports transaction signing, so you can use it to vote:
378
+
379
+ ```ruby
380
+ tx = Rubybear::Transaction.new(wif: 'Your Wif Here')
381
+ vote = {
382
+ type: :vote,
383
+ voter: 'xeroc',
384
+ author: 'xeroc',
385
+ permlink: 'piston',
386
+ weight: 10000
387
+ }
388
+
389
+ tx.operations << vote
390
+ tx.process(true)
391
+ ```
392
+
393
+ You can also post/comment:
394
+
395
+ ```ruby
396
+ tx = Rubybear::Transaction.new(wif: 'Your Wif Here')
397
+ comment = {
398
+ type: :comment,
399
+ parent_permlink: 'test',
400
+ author: 'your-account',
401
+ permlink: 'something-unique',
402
+ title: 'Rubybear Can Post Comments!',
403
+ body: 'Yep, this post was created by Rubybear in `ruby`.',
404
+ json_metadata: '',
405
+ parent_author: ''
406
+ }
407
+
408
+ tx.operations << comment
409
+ tx.process(true)
410
+ ```
411
+
412
+ Transfers:
413
+
414
+ ```ruby
415
+ tx = Rubybear::Transaction.new(wif: 'Your Wif Here')
416
+ transfer = {
417
+ type: :transfer,
418
+ from: 'ned',
419
+ to: 'inertia',
420
+ amount: '100000.000 BSD',
421
+ memo: 'Wow, inertia! Rubybear is great!'
422
+ }
423
+
424
+ tx.operations << transfer
425
+ tx.process(true)
426
+ ```
427
+
428
+ There's a complete list of operations known to Rubybear in [`broadcast_operations.json`](https://github.com/bearshares/rubybear/blob/master/lib/rubybear/broadcast_operations.json).
429
+
430
+ ## Failover
431
+
432
+ Rubybear supports failover for situations where a node has, for example, become unresponsive. When creating a new instance of `::Api`, `::Stream`, and `::Transaction`, you may provide a list of alternative nodes, or leave them out to use the default list. For example:
433
+
434
+ ```ruby
435
+ options = {
436
+ url: 'https://api.bearshares.com',
437
+ failover_urls: [
438
+ 'https://api.bearsharesstage.com',
439
+ 'https://api.bears.house'
440
+ ]
441
+ }
442
+
443
+ api = Rubybear::Api.new(options)
444
+ ```
445
+
446
+ In a nutshell, the way this works is Rubybear will try a node and proceed until it encounters an error, then retry the request. If it encounters a second error within 5 minutes, it will abandon the node and try a random one from `failover_urls`.
447
+
448
+ It'll keep doing this until it runs out of failovers, then it will reset the configuration and go back to the original node.
449
+
450
+ Rubybear uses an exponential back-off subroutine to avoid slamming nodes when they act up.
451
+
452
+ There's an additional behavior in `::Stream`. When a node responds with a block out of sequence, it will use the failover logic above. Although this is not a network layer failure, it is a bad result that may indicate a problem on the node, so a new node is picked.
453
+
454
+ There is another rare scenario involving `::Transaction` broadcasts that's handled by the failover logic: When a node responds with a network error *after* a signed transaction is accepted, Rubybear will do a look-up to find the accepted signature in order to avoid triggering a `dupe_check` error from the blockchain. This subroutine might take up to five minutes to execute in the worst possible situation. To disable this behavior, use the `recover_transactions_on_error` and set it to `false`, e.g.:
455
+
456
+ ```ruby
457
+ tx = Rubybear::Transaction.new(wif: wif, recover_transactions_on_error: false)
458
+ ```
459
+
460
+ ## Debugging
461
+
462
+ To enable debugging, set environment `LOG=DEBUG` before launching your app. E.g.:
463
+
464
+ ```bash
465
+ $ LOG=DEBUG irb -rrubybear
466
+ ```
467
+
468
+ This will enable debugging for the `irb` session.
469
+
470
+ ## Troubleshooting
471
+
472
+ ## Problem: My log is full of `Unable to perform request ... retrying ...` messages.
473
+
474
+ ```
475
+ W, [2017-10-10T11:38:30.035318 #6743] WARN -- : database_api.get_dynamic_global_properties :: Unable to perform request: too many connection resets (due to Net::ReadTimeout - Net::ReadTimeout) after 0 requests on 26665356, last used 1507660710.035165 seconds ago :: cause: Net::ReadTimeout, retrying ...
476
+ ```
477
+
478
+ This is caused by network interruptions. If these messages happen once in a while, they can be ignored. Rubybear will retry the request and move on. If there are more frequent warnings, this will trigger the failover logic and pick a new node, if one has been configured (which is true by default). See the Failover section above.
479
+
480
+ ## Problem: My log is full of `Invalid block sequence` messages.
481
+
482
+ ```
483
+ W, [2017-10-10T13:53:24.327177 #6938] WARN -- : Invalid block sequence at height: 16217674
484
+ ```
485
+
486
+ This is a similar situation to `Unable to perform request ... retrying ...`. Rubybear::Stream will retry and failover if needed. It is happening because the node has responded with a block out of order and ::Stream is ignoring this block, then retrying.
487
+
488
+ ## Problem: What does the `Stream behind` error mean?
489
+
490
+ ```
491
+ W, [2017-10-09T17:15:59.164484 #6231] WARN -- : Stream behind by 6118 blocks (about 305.9 minutes).
492
+ ```
493
+
494
+ ## Solution:
495
+
496
+ This is an error produced by `::Stream` when it notices that the current block is falling too far behind the head block. One solution is to just restart the stream and see if it happens again. If you see a message like this occasionally, but otherwise the stream seems to keep up, it probably was able to recover on its own.
497
+
498
+ There can be several root causes. Resources like memory and CPU might be taxed. The network connection might be too slow for what you're doing. Remember, you're downloading each and every block, not just the operations you want.
499
+
500
+ If you have excluded system resources as the root cause, then you should take a look at your code. If you're doing anything that takes longer than 3 seconds per block, `::Stream` can fall behind. When this happens, `::Stream` will try to catch up without displaying a warning. But once you fall 400 blocks behind (~20 minutes), you'll start to get the warning messages.
501
+
502
+ Verify your code is not doing too much between blocks.
503
+
504
+ ## Problem: I'm getting an endless loop: `#<OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=error: certificate verify failed>`
505
+
506
+ ## Solution:
507
+
508
+ You're probably creating too many threads or you don't have enough resources for what you're doing. One option for you is to avoid persistent HTTP by passing `persist: false`.
509
+
510
+ Doing this will impact performance because each API call will be a separate socket call. All of the constructors accept `persist: false`., e.g.:
511
+
512
+ ```ruby
513
+ api = Rubybear::Api.new(persist: false)
514
+ ```
515
+
516
+ ... or ...
517
+
518
+ ```ruby
519
+ stream = Rubybear::Stream.new(persist: false)
520
+ ```
521
+
522
+ ... or ...
523
+
524
+ ```ruby
525
+ tx = Rubybear::Transaction.new(options.merge(persist: false, wif: wif))
526
+ ```
527
+
528
+ Also see troubleshooting discussion about this situation:
529
+
530
+ https://github.com/bearshares/rubybear/issues/12
531
+
532
+ ## Tests
533
+
534
+ * Clone the client repository into a directory of your choice:
535
+ * `git clone https://github.com/bearshares/rubybear.git`
536
+ * Navigate into the new folder
537
+ * `cd rubybear`
538
+ * Basic tests can be invoked as follows:
539
+ * `rake`
540
+ * To run tests with parallelization and local code coverage:
541
+ * `HELL_ENABLED=true rake`
542
+ * To run a stream test on the live BEARS blockchain with debug logging enabled:
543
+ * `LOG=DEBUG rake test_live_stream`
544
+
545
+ ---
546
+
547
+ <center>
548
+ <img src="http://www.bearsimg.com/images/2016/08/19/RubybearCoolingFan-54in-Webfdcb1.png" />
549
+ </center>
550
+
551
+ See my previous Ruby How To posts in: [#rubybear](https://bearshares.com/created/rubybear) [#ruby](https://bearshares.com/created/ruby)
552
+
553
+ ## Get in touch!
554
+
555
+ If you're using Rubybear, I'd love to hear from you. Drop me a line and tell me what you think! I'm @inertia on BEARS.
556
+
557
+ ## License
558
+
559
+ I don't believe in intellectual "property". If you do, consider Rubybear as licensed under a Creative Commons [![CC0](http://i.creativecommons.org/p/zero/1.0/80x15.png)](http://creativecommons.org/publicdomain/zero/1.0/) License.