hive-ruby 1.0.0.pre.1

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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +54 -0
  3. data/CONTRIBUTING.md +79 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +91 -0
  6. data/LICENSE +21 -0
  7. data/README.md +248 -0
  8. data/Rakefile +358 -0
  9. data/gource.sh +6 -0
  10. data/hive-ruby.gemspec +40 -0
  11. data/images/Anthony Martin.png +0 -0
  12. data/lib/hive.rb +89 -0
  13. data/lib/hive/api.rb +223 -0
  14. data/lib/hive/base_error.rb +218 -0
  15. data/lib/hive/block_api.rb +78 -0
  16. data/lib/hive/bridge.rb +12 -0
  17. data/lib/hive/broadcast.rb +1334 -0
  18. data/lib/hive/chain_config.rb +34 -0
  19. data/lib/hive/fallback.rb +287 -0
  20. data/lib/hive/formatter.rb +14 -0
  21. data/lib/hive/jsonrpc.rb +112 -0
  22. data/lib/hive/marshal.rb +231 -0
  23. data/lib/hive/mixins/jsonable.rb +37 -0
  24. data/lib/hive/mixins/retriable.rb +58 -0
  25. data/lib/hive/mixins/serializable.rb +45 -0
  26. data/lib/hive/operation.rb +141 -0
  27. data/lib/hive/operation/account_create.rb +10 -0
  28. data/lib/hive/operation/account_create_with_delegation.rb +12 -0
  29. data/lib/hive/operation/account_update.rb +8 -0
  30. data/lib/hive/operation/account_witness_proxy.rb +4 -0
  31. data/lib/hive/operation/account_witness_vote.rb +5 -0
  32. data/lib/hive/operation/cancel_transfer_from_savings.rb +4 -0
  33. data/lib/hive/operation/challenge_authority.rb +5 -0
  34. data/lib/hive/operation/change_recovery_account.rb +5 -0
  35. data/lib/hive/operation/claim_account.rb +5 -0
  36. data/lib/hive/operation/claim_reward_balance.rb +6 -0
  37. data/lib/hive/operation/comment.rb +9 -0
  38. data/lib/hive/operation/comment_options.rb +10 -0
  39. data/lib/hive/operation/convert.rb +5 -0
  40. data/lib/hive/operation/create_claimed_account.rb +10 -0
  41. data/lib/hive/operation/custom.rb +5 -0
  42. data/lib/hive/operation/custom_binary.rb +8 -0
  43. data/lib/hive/operation/custom_json.rb +6 -0
  44. data/lib/hive/operation/decline_voting_rights.rb +4 -0
  45. data/lib/hive/operation/delegate_vesting_shares.rb +5 -0
  46. data/lib/hive/operation/delete_comment.rb +4 -0
  47. data/lib/hive/operation/escrow_approve.rb +8 -0
  48. data/lib/hive/operation/escrow_dispute.rb +7 -0
  49. data/lib/hive/operation/escrow_release.rb +10 -0
  50. data/lib/hive/operation/escrow_transfer.rb +12 -0
  51. data/lib/hive/operation/feed_publish.rb +4 -0
  52. data/lib/hive/operation/limit_order_cancel.rb +4 -0
  53. data/lib/hive/operation/limit_order_create.rb +8 -0
  54. data/lib/hive/operation/limit_order_create2.rb +8 -0
  55. data/lib/hive/operation/prove_authority.rb +4 -0
  56. data/lib/hive/operation/recover_account.rb +6 -0
  57. data/lib/hive/operation/report_over_production.rb +5 -0
  58. data/lib/hive/operation/request_account_recovery.rb +6 -0
  59. data/lib/hive/operation/reset_account.rb +5 -0
  60. data/lib/hive/operation/set_reset_account.rb +5 -0
  61. data/lib/hive/operation/set_withdraw_vesting_route.rb +6 -0
  62. data/lib/hive/operation/transfer.rb +6 -0
  63. data/lib/hive/operation/transfer_from_savings.rb +7 -0
  64. data/lib/hive/operation/transfer_to_savings.rb +6 -0
  65. data/lib/hive/operation/transfer_to_vesting.rb +5 -0
  66. data/lib/hive/operation/vote.rb +6 -0
  67. data/lib/hive/operation/withdraw_vesting.rb +4 -0
  68. data/lib/hive/operation/witness_set_properties.rb +5 -0
  69. data/lib/hive/operation/witness_update.rb +7 -0
  70. data/lib/hive/rpc/base_client.rb +179 -0
  71. data/lib/hive/rpc/http_client.rb +143 -0
  72. data/lib/hive/rpc/thread_safe_http_client.rb +35 -0
  73. data/lib/hive/stream.rb +385 -0
  74. data/lib/hive/transaction.rb +115 -0
  75. data/lib/hive/transaction_builder.rb +406 -0
  76. data/lib/hive/type/amount.rb +126 -0
  77. data/lib/hive/type/base_type.rb +10 -0
  78. data/lib/hive/utils.rb +17 -0
  79. data/lib/hive/version.rb +4 -0
  80. metadata +502 -0
@@ -0,0 +1,34 @@
1
+ module Hive
2
+ module ChainConfig
3
+ EXPIRE_IN_SECS = 600
4
+ EXPIRE_IN_SECS_PROPOSAL = 24 * 60 * 60
5
+
6
+ NETWORKS_HIVE_LEGACY_CHAIN_ID = '0000000000000000000000000000000000000000000000000000000000000000'
7
+ NETWORKS_HIVE_CHAIN_ID = 'beeab0de00000000000000000000000000000000000000000000000000000000'
8
+ NETWORKS_HIVE_ADDRESS_PREFIX = 'STM'
9
+ NETWORKS_HIVE_CORE_ASSET = ["0", 3, "@@000000021"] # HIVE
10
+ NETWORKS_HIVE_DEBT_ASSET = ["0", 3, "@@000000013"] # HBD
11
+ NETWORKS_HIVE_VEST_ASSET = ["0", 6, "@@000000037"] # VESTS
12
+ NETWORKS_HIVE_DEFAULT_NODE = 'https://api.openhive.network'
13
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://anyx.io'
14
+ # NETWORKS_HIVE_DEFAULT_NODE = 'http://anyx.io'
15
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://api.hivekings.com'
16
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://api.hive.blog'
17
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://api.openhive.network'
18
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://techcoderx.com'
19
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://rpc.esteem.app'
20
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://hived.privex.io'
21
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://api.pharesim.me'
22
+ # NETWORKS_HIVE_DEFAULT_NODE = 'https://rpc.ausbit.dev'
23
+
24
+ NETWORKS_TEST_CHAIN_ID = '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32'
25
+ NETWORKS_TEST_ADDRESS_PREFIX = 'TST'
26
+ NETWORKS_TEST_CORE_ASSET = ["0", 3, "@@000000021"] # TESTS
27
+ NETWORKS_TEST_DEBT_ASSET = ["0", 3, "@@000000013"] # TBD
28
+ NETWORKS_TEST_VEST_ASSET = ["0", 6, "@@000000037"] # VESTS
29
+ NETWORKS_TEST_DEFAULT_NODE = 'https://testnet-api.openhive.network'
30
+ # NETWORKS_TEST_DEFAULT_NODE = 'https://hive-test-beeabode.roelandp.nl'
31
+
32
+ NETWORK_CHAIN_IDS = [NETWORKS_HIVE_CHAIN_ID, NETWORKS_TEST_CHAIN_ID]
33
+ end
34
+ end
@@ -0,0 +1,287 @@
1
+ module Hive::Fallback
2
+ API_METHODS = {
3
+ account_by_key_api: [
4
+ :get_key_references
5
+ ],
6
+ block_api: [
7
+ :get_block,
8
+ :get_block_header
9
+ ],
10
+ condenser_api: [
11
+ :broadcast_block,
12
+ :broadcast_transaction,
13
+ :broadcast_transaction_synchronous,
14
+ :get_account_count,
15
+ :get_account_history,
16
+ :get_account_references,
17
+ :get_account_reputations,
18
+ :get_account_votes,
19
+ :get_accounts,
20
+ :get_active_votes,
21
+ :get_active_witnesses,
22
+ :get_block,
23
+ :get_block_header,
24
+ :get_blog,
25
+ :get_blog_authors,
26
+ :get_blog_entries,
27
+ :get_chain_properties,
28
+ :get_comment_discussions_by_payout,
29
+ :get_config,
30
+ :get_content,
31
+ :get_content_replies,
32
+ :get_conversion_requests,
33
+ :get_current_median_history_price,
34
+ :get_discussions_by_active,
35
+ :get_discussions_by_author_before_date,
36
+ :get_discussions_by_blog,
37
+ :get_discussions_by_cashout,
38
+ :get_discussions_by_children,
39
+ :get_discussions_by_comments,
40
+ :get_discussions_by_created,
41
+ :get_discussions_by_feed,
42
+ :get_discussions_by_hot,
43
+ :get_discussions_by_promoted,
44
+ :get_discussions_by_trending,
45
+ :get_discussions_by_votes,
46
+ :get_dynamic_global_properties,
47
+ :get_escrow,
48
+ :get_expiring_vesting_delegations,
49
+ :get_feed,
50
+ :get_feed_entries,
51
+ :get_feed_history,
52
+ :get_follow_count,
53
+ :get_followers,
54
+ :get_following,
55
+ :get_hardfork_version,
56
+ :get_key_references,
57
+ :get_market_history,
58
+ :get_market_history_buckets,
59
+ :get_next_scheduled_hardfork,
60
+ :get_open_orders,
61
+ :get_ops_in_block,
62
+ :get_order_book,
63
+ :get_owner_history,
64
+ :get_post_discussions_by_payout,
65
+ :get_potential_signatures,
66
+ :get_reblogged_by,
67
+ :get_recent_trades,
68
+ :get_recovery_request,
69
+ :get_replies_by_last_update,
70
+ :get_required_signatures,
71
+ :get_reward_fund,
72
+ :get_savings_withdraw_from,
73
+ :get_savings_withdraw_to,
74
+ :get_state,
75
+ :get_tags_used_by_author,
76
+ :get_ticker,
77
+ :get_trade_history,
78
+ :get_transaction,
79
+ :get_transaction_hex,
80
+ :get_trending_tags,
81
+ :get_version,
82
+ :get_vesting_delegations,
83
+ :get_volume,
84
+ :get_withdraw_routes,
85
+ :get_witness_by_account,
86
+ :get_witness_count,
87
+ :get_witness_schedule,
88
+ :get_witnesses,
89
+ :get_witnesses_by_vote,
90
+ :lookup_account_names,
91
+ :lookup_accounts,
92
+ :lookup_witness_accounts,
93
+ :verify_account_authority,
94
+ :verify_authority,
95
+ :find_proposals,
96
+ :list_proposal_votes,
97
+ :list_proposals
98
+ ],
99
+ database_api: [
100
+ :find_account_recovery_requests,
101
+ :find_accounts,
102
+ :find_change_recovery_account_requests,
103
+ :find_comments,
104
+ :find_decline_voting_rights_requests,
105
+ :find_escrows,
106
+ :find_limit_orders,
107
+ :find_owner_histories,
108
+ :find_savings_withdrawals,
109
+ :find_sbd_conversion_requests,
110
+ :find_vesting_delegation_expirations,
111
+ :find_vesting_delegations,
112
+ :find_votes,
113
+ :find_withdraw_vesting_routes,
114
+ :find_witnesses,
115
+ :get_active_witnesses,
116
+ :get_config,
117
+ :get_current_price_feed,
118
+ :get_dynamic_global_properties,
119
+ :get_feed_history,
120
+ :get_hardfork_properties,
121
+ :get_order_book,
122
+ :get_potential_signatures,
123
+ :get_required_signatures,
124
+ :get_reward_funds,
125
+ :get_transaction_hex,
126
+ :get_version,
127
+ :get_witness_schedule,
128
+ :list_account_recovery_requests,
129
+ :list_accounts,
130
+ :list_change_recovery_account_requests,
131
+ :list_comments,
132
+ :list_decline_voting_rights_requests,
133
+ :list_escrows,
134
+ :list_limit_orders,
135
+ :list_owner_histories,
136
+ :list_savings_withdrawals,
137
+ :list_sbd_conversion_requests,
138
+ :list_vesting_delegation_expirations,
139
+ :list_vesting_delegations,
140
+ :list_votes,
141
+ :list_withdraw_vesting_routes,
142
+ :list_witness_votes,
143
+ :list_witnesses,
144
+ :verify_account_authority,
145
+ :verify_authority,
146
+ :verify_signatures,
147
+ :find_proposals,
148
+ :list_proposal_votes,
149
+ :list_proposals
150
+ ],
151
+ follow_api: [
152
+ :get_account_reputations,
153
+ :get_blog,
154
+ :get_blog_authors,
155
+ :get_blog_entries,
156
+ :get_feed,
157
+ :get_feed_entries,
158
+ :get_follow_count,
159
+ :get_followers,
160
+ :get_following,
161
+ :get_reblogged_by
162
+ ],
163
+ jsonrpc: [
164
+ :get_methods,
165
+ :get_signature
166
+ ],
167
+ market_history_api: [
168
+ :get_market_history,
169
+ :get_market_history_buckets,
170
+ :get_order_book,
171
+ :get_recent_trades,
172
+ :get_ticker,
173
+ :get_trade_history,
174
+ :get_volume
175
+ ],
176
+ network_broadcast_api: [
177
+ :broadcast_block,
178
+ :broadcast_transaction
179
+ ],
180
+ rc_api: [
181
+ :find_rc_accounts,
182
+ :get_resource_params,
183
+ :get_resource_pool
184
+ ],
185
+ tags_api: [
186
+ :get_active_votes,
187
+ :get_comment_discussions_by_payout,
188
+ :get_content_replies,
189
+ :get_discussion,
190
+ :get_discussions_by_active,
191
+ :get_discussions_by_author_before_date,
192
+ :get_discussions_by_blog,
193
+ :get_discussions_by_cashout,
194
+ :get_discussions_by_children,
195
+ :get_discussions_by_comments,
196
+ :get_discussions_by_created,
197
+ :get_discussions_by_feed,
198
+ :get_discussions_by_hot,
199
+ :get_discussions_by_promoted,
200
+ :get_discussions_by_trending,
201
+ :get_discussions_by_votes,
202
+ :get_post_discussions_by_payout,
203
+ :get_replies_by_last_update,
204
+ :get_tags_used_by_author,
205
+ :get_trending_tags
206
+ ],
207
+ reputation_api: [
208
+ :get_account_reputations
209
+ ],
210
+ bridge: [
211
+ :account_notifications,
212
+ :get_community,
213
+ :get_ranked_posts,
214
+ :list_all_subscriptions,
215
+ :list_community_roles,
216
+ ]
217
+ }
218
+
219
+ API_METHOD_SIGNATURES = {
220
+ database_api: {
221
+ find_account_recovery_requests: {accounts: []},
222
+ find_accounts: {accounts: []},
223
+ find_change_recovery_account_requests: {accounts: []},
224
+ find_comments: {comments: []},
225
+ find_decline_voting_rights_requests: {accounts: []},
226
+ find_escrows: {from: String},
227
+ find_limit_orders: {account: String},
228
+ find_owner_histories: {owner: String},
229
+ find_proposals: {proposal_ids: []},
230
+ find_savings_withdrawals: {account: String},
231
+ find_sbd_conversion_requests: {account: String},
232
+ find_vesting_delegation_expirations: {account: String},
233
+ find_vesting_delegations: {account: String},
234
+ find_votes: {author: String, permlink: String},
235
+ find_withdraw_vesting_routes: {account: String, order: String},
236
+ find_witnesses: {owners: []},
237
+ get_active_witnesses: {},
238
+ get_config: {},
239
+ get_current_price_feed: {},
240
+ get_dynamic_global_properties: {},
241
+ get_feed_history: {},
242
+ get_hardfork_properties: {},
243
+ get_order_book: {limit: Integer},
244
+ get_potential_signatures: {trx: {}},
245
+ get_required_signatures: {trx: {}, available_keys: []},
246
+ get_reward_funds: {},
247
+ get_transaction_hex: {trx: {}},
248
+ get_version: {},
249
+ get_witness_schedule: {},
250
+ list_account_recovery_requests: {start: NilClass, limit: Integer, order: String},
251
+ list_accounts: {start: NilClass, limit: Integer, order: String},
252
+ list_change_recovery_account_requests: {start: NilClass, limit: Integer, order: String},
253
+ list_comments: {start: NilClass, limit: Integer, order: String},
254
+ list_decline_voting_rights_requests: {start: NilClass, limit: Integer, order: String},
255
+ list_escrows: {start: NilClass, limit: Integer, order: String},
256
+ list_limit_orders: {start: NilClass, limit: Integer, order: String},
257
+ list_owner_histories: {start: NilClass, limit: Integer},
258
+ list_proposal_votes: {start: NilClass, limit: Integer, order: String, order_direction: String, status: String},
259
+ list_proposals: {start: NilClass, limit: Integer, order: String, order_direction: String, status: String},
260
+ list_savings_withdrawals: {start: NilClass, limit: Integer, order: String},
261
+ list_sbd_conversion_requests: {start: NilClass, limit: Integer, order: String},
262
+ list_vesting_delegation_expirations: {start: NilClass, limit: Integer, order: String},
263
+ list_vesting_delegations: {start: NilClass, limit: Integer, order: String},
264
+ list_votes: {start: NilClass, limit: Integer, order: String},
265
+ list_withdraw_vesting_routes: {start: NilClass, limit: Integer, order: String},
266
+ list_witness_votes: {start: NilClass, limit: Integer, order: String},
267
+ list_witnesses: {start: NilClass, limit: Integer, order: String},
268
+ verify_account_authority: {account: String, signers: []},
269
+ verify_authority: {trx: {}},
270
+ verify_signatures: {hash: String, signatures: [], required_owner: [], required_active: [], required_posting: [], required_other: []}
271
+ },
272
+ jsonrpc: {
273
+ get_methods: {},
274
+ get_signature: {method: String}
275
+ },
276
+ reputation_api: {
277
+ get_account_reputations: {account_lower_bound: String, limit: Integer}
278
+ },
279
+ bridge: {
280
+ account_notifications: {account: String, limit: Integer},
281
+ get_community: {name: String, observer: String},
282
+ get_ranked_posts: {sort: String, tag: String, observer: String, limit: Integer},
283
+ list_all_subscriptions: {account: String},
284
+ list_community_roles: {community: String}
285
+ }
286
+ }
287
+ end
@@ -0,0 +1,14 @@
1
+ module Hive
2
+ class Formatter
3
+ def self.reputation(raw)
4
+ raw = raw.to_i
5
+ neg = raw < 0
6
+ level = Math.log10(raw.abs)
7
+ level = [level - 9, 0].max
8
+ level = (neg ? -1 : 1) * level
9
+ level = (level * 9) + 25
10
+
11
+ level.round(1)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,112 @@
1
+ module Hive
2
+ # {Jsonrpc} allows you to inspect the available methods offered by a node.
3
+ # If a node runs a plugin you want, then all of the API methods it can exposes
4
+ # will automatically be available. This API is used internally to determine
5
+ # which APIs and methods are available on the node you specify.
6
+ #
7
+ # In theory, if a new plugin is created and enabled by the node, it will be
8
+ # available by this library without needing an update to its code.
9
+ class Jsonrpc < Api
10
+ API_METHODS = %i(get_signature get_methods)
11
+
12
+ # APIs that the RPC server will (or likely will) respond to that is
13
+ # maintained outside the view of jsonrpc.
14
+ UNLISTED_APIS = %i(bridge)
15
+
16
+ def self.api_methods
17
+ @api_methods ||= {}
18
+ end
19
+
20
+ # Might help diagnose a cluster that has asymmetric plugin definitions.
21
+ def self.reset_api_methods
22
+ @api_methods = nil
23
+ end
24
+
25
+ def initialize(options = {})
26
+ @api_name = self.class.api_name = :jsonrpc
27
+ @methods = API_METHODS
28
+ super
29
+ end
30
+
31
+ def get_api_methods(&block)
32
+ api_methods = self.class.api_methods[@rpc_client.uri.to_s]
33
+
34
+ if api_methods.nil?
35
+ get_methods do |result, error, rpc_id|
36
+ raise NotAppBaseError, "#{@rpc_client.uri} does not appear to run AppBase" unless defined? result.map
37
+
38
+ methods = result.map do |method|
39
+ method.split('.').map(&:to_sym)
40
+ end
41
+
42
+ api_methods = Hashie::Mash.new
43
+
44
+ methods.each do |api, method|
45
+ api_methods[api] ||= []
46
+ api_methods[api] << method
47
+ end
48
+
49
+ self.class.api_methods[@rpc_client.uri.to_s] = api_methods
50
+ end
51
+ end
52
+
53
+ if !!block
54
+ api_methods.each do |api, methods|
55
+ yield api, methods
56
+ end
57
+ else
58
+ return api_methods
59
+ end
60
+ end
61
+
62
+ def get_all_signatures(&block)
63
+ request_object = []
64
+ method_names = []
65
+ method_map = {}
66
+ signatures = {}
67
+ offset = 0
68
+
69
+ get_api_methods do |api, methods|
70
+ request_object += methods.map do |method|
71
+ method_name = "#{api}.#{method}"
72
+ method_names << method_name
73
+ current_rpc_id = @rpc_client.rpc_id
74
+ offset += 1
75
+ method_map[current_rpc_id] = [api, method]
76
+
77
+ {
78
+ jsonrpc: '2.0',
79
+ id: current_rpc_id,
80
+ method: 'jsonrpc.get_signature',
81
+ params: {method: method_name}
82
+ }
83
+ end
84
+ end
85
+
86
+ chunks = if request_object.size > Hive::RPC::HttpClient::JSON_RPC_BATCH_SIZE_MAXIMUM
87
+ request_object.each_slice(Hive::RPC::HttpClient::JSON_RPC_BATCH_SIZE_MAXIMUM)
88
+ else
89
+ request_object
90
+ end
91
+
92
+ for request_object in chunks do
93
+ @rpc_client.rpc_batch_execute(request_object: request_object) do |result, error, id|
94
+ api, method = method_map[id]
95
+ api = api.to_sym
96
+ method = method.to_sym
97
+
98
+ signatures[api] ||= {}
99
+ signatures[api][method] = result
100
+ end
101
+
102
+ if !!block
103
+ signatures.each do |api, methods|
104
+ yield api, methods
105
+ end
106
+ end
107
+ end
108
+
109
+ return signatures unless !!block
110
+ end
111
+ end
112
+ end