hive-ruby 1.0.0.pre.1 → 1.0.0.pre.2

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: f12eb926857666814b1ddd99302952102c91299bba3d2efc9ffb75888f72c520
4
- data.tar.gz: e1103584e3aec71e89f336c3a044d54ad8f3f8bd0056fdf6d1cf694ce3c4f816
3
+ metadata.gz: 03ce4beaef9c60b95e78bcc6d5589f01ea02902a59a151669ce26a774bad3e20
4
+ data.tar.gz: f8f05b4c3763b3d06f20466bf691a7fd5d3d7ee0a808a99942d42d39086775e6
5
5
  SHA512:
6
- metadata.gz: 16e20294bf841fa651c9a236c499f659dbf10b136876e31acead394e4362f68583fcb846a86cd19cfdd7505c46dda22d13c05f008f290e1b92c4b7b36b2589dc
7
- data.tar.gz: 4c3104a416ce1010e6e4543bb9830aad3a884e7af34d8083d59f8b57d4043cdb3454a37eefe3927aeee516f9eda9c12109495deb7ec0252fd5d454d50b9d7222
6
+ metadata.gz: 295873eef303017a329752b385478249490232e6bd6fe8862ce91b1fab6da3c73a53c71ea14f989fa376fbdc93669895a4de9b25a415c64c32c936b998dcde0f
7
+ data.tar.gz: d32254187206ed4f704355ec768e67e6746b52c05f7a1da02682e5714db6034faca654f9c9492cbaecc14d476da9cfe2c78a14429aeedf3c93f5a6713a4e8e42
data/.gitignore CHANGED
@@ -43,7 +43,7 @@ build-iPhoneSimulator/
43
43
 
44
44
  # for a library or gem, you might want to ignore these files since the code is
45
45
  # intended to run in multiple environments; otherwise, check them in:
46
- # Gemfile.lock
46
+ Gemfile.lock
47
47
  # .ruby-version
48
48
  # .ruby-gemset
49
49
 
@@ -0,0 +1,17 @@
1
+ image: ruby:2.6.1-alpine
2
+
3
+ pages:
4
+ script:
5
+ - apk add --update --no-cache build-base libxml2-dev libxslt-dev libstdc++ tzdata mariadb-dev nodejs ca-certificates yarn
6
+ - bundle install --path vendor
7
+ - bundle exec yard
8
+ - rm -rf public
9
+ - mv doc public
10
+ artifacts:
11
+ paths:
12
+ - public
13
+ cache:
14
+ paths:
15
+ - vendor
16
+ only:
17
+ - master
Binary file
Binary file
Binary file
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.1'
21
21
  spec.add_development_dependency 'rake', '~> 13.0.1', '>= 12.3.0'
22
- spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
22
+ spec.add_development_dependency 'minitest', '~> 5.14', '>= 5.10.3'
23
23
  spec.add_development_dependency 'minitest-line', '~> 0.6', '>= 0.6.4'
24
24
  spec.add_development_dependency 'minitest-proveit', '~> 1.0', '>= 1.0.0'
25
25
  spec.add_development_dependency 'webmock', '~> 3.3', '>= 3.3.0'
26
26
  spec.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
27
- spec.add_development_dependency 'vcr', '~> 5.1', '>= 4.0.0'
27
+ spec.add_development_dependency 'vcr', '~> 6.0', '>= 4.0.0'
28
28
  spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.12'
29
29
  spec.add_development_dependency 'pry', '~> 0.11', '>= 0.11.3'
30
30
  spec.add_development_dependency 'awesome_print', '~> 1.8', '>= 1.8.0'
@@ -16,6 +16,7 @@ require 'hive/operation'
16
16
  require 'hive/operation/account_create.rb'
17
17
  require 'hive/operation/account_create_with_delegation.rb'
18
18
  require 'hive/operation/account_update.rb'
19
+ require 'hive/operation/account_update2.rb'
19
20
  require 'hive/operation/account_witness_proxy.rb'
20
21
  require 'hive/operation/account_witness_vote.rb'
21
22
  require 'hive/operation/cancel_transfer_from_savings.rb'
@@ -27,6 +28,7 @@ require 'hive/operation/comment.rb'
27
28
  require 'hive/operation/comment_options.rb'
28
29
  require 'hive/operation/convert.rb'
29
30
  require 'hive/operation/create_claimed_account.rb'
31
+ require 'hive/operation/create_proposal.rb'
30
32
  require 'hive/operation/custom.rb'
31
33
  require 'hive/operation/custom_binary.rb'
32
34
  require 'hive/operation/custom_json.rb'
@@ -43,6 +45,7 @@ require 'hive/operation/limit_order_create.rb'
43
45
  require 'hive/operation/limit_order_create2.rb'
44
46
  require 'hive/operation/prove_authority.rb'
45
47
  require 'hive/operation/recover_account.rb'
48
+ require 'hive/operation/remove_proposal.rb'
46
49
  require 'hive/operation/report_over_production.rb'
47
50
  require 'hive/operation/request_account_recovery.rb'
48
51
  require 'hive/operation/reset_account.rb'
@@ -52,6 +55,7 @@ require 'hive/operation/transfer.rb'
52
55
  require 'hive/operation/transfer_from_savings.rb'
53
56
  require 'hive/operation/transfer_to_savings.rb'
54
57
  require 'hive/operation/transfer_to_vesting.rb'
58
+ require 'hive/operation/update_proposal_votes.rb'
55
59
  require 'hive/operation/vote.rb'
56
60
  require 'hive/operation/withdraw_vesting.rb'
57
61
  require 'hive/operation/witness_update.rb'
@@ -74,6 +74,10 @@ module Hive
74
74
  raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
75
75
  end
76
76
 
77
+ if error.message.include? 'Invalid parameter'
78
+ raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
79
+ end
80
+
77
81
  if error.message.include? 'blk->transactions.size() > itr->trx_in_block'
78
82
  raise Hive::VirtualOperationsNotAllowedError, "#{context}: #{error.message}", build_backtrace(error)
79
83
  end
@@ -122,6 +126,10 @@ module Hive
122
126
  raise Hive::UpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
123
127
  end
124
128
 
129
+ if error.message.include? 'Request Timeout'
130
+ raise Hive::RequestTimeoutUpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
131
+ end
132
+
125
133
  if error.message.include? 'Bad or missing upstream response'
126
134
  raise Hive::BadOrMissingUpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
127
135
  end
@@ -205,6 +213,7 @@ module Hive
205
213
  class UpstreamResponseError < RemoteNodeError; end
206
214
  class RemoteDatabaseLockError < UpstreamResponseError; end
207
215
  class PluginNotEnabledError < UpstreamResponseError; end
216
+ class RequestTimeoutUpstreamResponseError < UpstreamResponseError; end
208
217
  class BadOrMissingUpstreamResponseError < UpstreamResponseError; end
209
218
  class TransactionIndexDisabledError < BaseError; end
210
219
  class NotAppBaseError < BaseError; end
@@ -52,7 +52,7 @@ module Hive
52
52
 
53
53
  if !!block
54
54
  index = 0
55
- @rpc_client.rpc_batch_execute(request_object: request_object) do |result, error, id|
55
+ @rpc_client.rpc_batch_execute(api_name: self.class.api_name, request_object: request_object) do |result, error, id|
56
56
  block_num = sub_range.to_a[index]
57
57
  index = index + 1
58
58
 
@@ -66,7 +66,7 @@ module Hive
66
66
  else
67
67
  blocks = []
68
68
 
69
- @rpc_client.rpc_batch_execute(request_object: request_object) do |result, error, id|
69
+ @rpc_client.rpc_batch_execute(api_name: self.class.api_name, request_object: request_object) do |result, error, id|
70
70
  blocks << result
71
71
  end
72
72
  end
@@ -713,31 +713,29 @@ module Hive
713
713
  params = options[:params]
714
714
  check_required_fields(params, *required_fields)
715
715
 
716
- if !!(account_creation_fee = params[:props][:account_creation_fee] rescue nil)
717
- params[:props][:account_creation_fee] = normalize_amount(options.merge amount: account_creation_fee, serialize: true)
716
+ props = params[:props]
717
+
718
+ if !!(account_creation_fee = props[:account_creation_fee] rescue nil)
719
+ props[:account_creation_fee] = hexlify normalize_amount(options.merge amount: account_creation_fee, serialize: true)
718
720
  end
719
721
 
720
- if !!(sbd_exchange_rate = params[:props][:sbd_exchange_rate] rescue nil)
721
- params[:props][:sbd_exchange_rate][:base] = normalize_amount(options.merge amount: sbd_exchange_rate[:base], serialize: true)
722
- params[:props][:sbd_exchange_rate][:quote] = normalize_amount(options.merge amount: sbd_exchange_rate[:quote], serialize: true)
723
- params[:props][:sbd_exchange_rate] = params[:props][:sbd_exchange_rate].to_json
722
+ if !!(sbd_exchange_rate = props[:sbd_exchange_rate] rescue nil)
723
+ props[:sbd_exchange_rate][:base] = normalize_amount(options.merge amount: sbd_exchange_rate[:base], serialize: true)
724
+ props[:sbd_exchange_rate][:quote] = normalize_amount(options.merge amount: sbd_exchange_rate[:quote], serialize: true)
725
+ props[:sbd_exchange_rate] = hexlify props[:sbd_exchange_rate].to_json
724
726
  end
725
727
 
726
728
  %i(key new_signing_key).each do |key|
727
- if !!params[key] && params[key].size == 53
728
- params[key] = params[key][3..-1]
729
+ if !!props[key] && props[key].length == 53
730
+ props[key] = hexlify props[key][3..-1]
729
731
  end
730
732
  end
731
733
 
732
- %i(account_creation_fee sbd_exchange_rate url new_signing_key).each do |key|
733
- next unless !!params[:props][key]
734
-
735
- val = params[:props][key].to_s
736
-
737
- params[:props][key] = hexlify val unless val =~ /^[0-9A-F]+$/i
734
+ if !!(val = props[:url])
735
+ props[:url] = hexlify val unless val =~ /^[0-9A-F]+$/i
738
736
  end
739
737
 
740
- params[:props] = params[:props].to_a
738
+ params[:props] = props.sort_by{|k,v| k}
741
739
 
742
740
  params[:extensions] ||= []
743
741
  ops = [[:witness_set_properties, params]]
@@ -1239,7 +1237,124 @@ module Hive
1239
1237
 
1240
1238
  process(options.merge(ops: ops), &block)
1241
1239
  end
1242
-
1240
+
1241
+ # @param options [Hash] options
1242
+ # @option options [String] :wif Posting wif
1243
+ # @option options [Hash] :params
1244
+ # * :account (String) Account claiming rewards.
1245
+ # * :reward_steem (Amount) Amount of HIVE to claim.
1246
+ # * :reward_sbd (Amount) Amount of HBD to claim.
1247
+ # * :reward_vests (Amount) Amount of VESTS to claim.
1248
+ # @option options [Boolean] :pretend Just validate, do not broadcast.
1249
+ # @see https://developers.hive.io/apidefinitions/broadcast-ops.html#broadcast_ops_claim_reward_balance
1250
+ def self.claim_reward_balance(options, &block)
1251
+ required_fields = %i(account)
1252
+ params = options[:params]
1253
+
1254
+ check_required_fields(params, *required_fields)
1255
+
1256
+ params[:reward_steem] = normalize_amount(options.merge amount: params[:reward_steem])
1257
+ params[:reward_sbd] = normalize_amount(options.merge amount: params[:reward_sbd])
1258
+ params[:reward_vests] = normalize_amount(options.merge amount: params[:reward_vests])
1259
+
1260
+ ops = [[:claim_reward_balance, params]]
1261
+
1262
+ process(options.merge(ops: ops), &block)
1263
+ end
1264
+
1265
+ # @param options [Hash] options
1266
+ # @option options [String] :wif Active wif
1267
+ # @option options [Hash] :params
1268
+ # * :account (String) Account being updated.
1269
+ # * :metadata (Hash) Metadata of the account, becomes `json_metadata`.
1270
+ # * :json_metadata (String) String version of `metadata` (use one or the other).
1271
+ # @option options [Boolean] :pretend Just validate, do not broadcast.
1272
+ # @see https://developers.hive.io/apidefinitions/broadcast-ops.html#broadcast_ops_account_update2
1273
+ def self.account_update2(options, &block)
1274
+ required_fields = %i(account)
1275
+ params = options[:params]
1276
+
1277
+ check_required_fields(params, *required_fields)
1278
+
1279
+ if !!params[:metadata] && !!params[:json_metadata]
1280
+ raise Hive::ArgumentError, 'Assign either metadata or json_metadata, not both.'
1281
+ end
1282
+
1283
+ metadata = params.delete(:metadata) || {}
1284
+ metadata ||= (JSON[params[:json_metadata]] || nil) || {}
1285
+ params[:json_metadata] = metadata.to_json
1286
+
1287
+ ops = [[:account_update2, params]]
1288
+
1289
+ process(options.merge(ops: ops), &block)
1290
+ end
1291
+
1292
+ # @param options [Hash] options
1293
+ # @option options [String] :wif Active wif
1294
+ # @option options [Hash] :params
1295
+ # * :creator (String) Creator of the new proposal.
1296
+ # * :receiver (String) Reciever of `daily_pay` (or creator if empty)
1297
+ # * :start_date (String) When the proposal starts.
1298
+ # * :end_date (String) When the proposal ends.
1299
+ # * :daily_pay (String) Daily pay in HBD starting on the `start_date` and ending on the `end_date`.
1300
+ # * :subject (String) Subject of the proposal.
1301
+ # * :permlink (String) Proposal permlink must point to the article posted by creator or receiver.
1302
+ # @option options [Boolean] :pretend Just validate, do not broadcast.
1303
+ # @see https://developers.hive.io/apidefinitions/broadcast-ops.html#broadcast_ops_create_proposal
1304
+ def self.create_proposal(options, &block)
1305
+ required_fields = %i(creator start_date end_date daily_pay subject permlink)
1306
+ params = options[:params]
1307
+
1308
+ check_required_fields(params, *required_fields)
1309
+
1310
+ params[:start_date] = Time.parse(params[:start_date].to_s)
1311
+ params[:start_date] = params[:start_date].strftime('%Y-%m-%dT%H:%M:%S')
1312
+ params[:end_date] = Time.parse(params[:end_date].to_s)
1313
+ params[:end_date] = params[:end_date].strftime('%Y-%m-%dT%H:%M:%S')
1314
+ params[:daily_pay] = normalize_amount(options.merge amount: params[:daily_pay])
1315
+
1316
+ ops = [[:create_proposal, params]]
1317
+
1318
+ process(options.merge(ops: ops), &block)
1319
+ end
1320
+
1321
+ # @param options [Hash] options
1322
+ # @option options [String] :wif Active wif
1323
+ # @option options [Hash] :params
1324
+ # * :voter (String) Account doing approval (or removing approval).
1325
+ # * :proposal_ids (Array<Integer>) Proposals to approve (or remove approval) for.
1326
+ # * :approve (Boolean) Approve or unapprove.
1327
+ # @option options [Boolean] :pretend Just validate, do not broadcast.
1328
+ # @see https://developers.hive.io/apidefinitions/broadcast-ops.html#broadcast_ops_update_proposal_votes
1329
+ def self.update_proposal_votes(options, &block)
1330
+ required_fields = %i(voter proposal_ids approve)
1331
+ params = options[:params]
1332
+
1333
+ check_required_fields(params, *required_fields)
1334
+
1335
+ ops = [[:update_proposal_votes, params]]
1336
+
1337
+ process(options.merge(ops: ops), &block)
1338
+ end
1339
+
1340
+ # @param options [Hash] options
1341
+ # @option options [String] :wif Active wif
1342
+ # @option options [Hash] :params
1343
+ # * :proposal_owner (String) Creator of the proposal.
1344
+ # * :proposal_ids (Array<Integer>) Proposals to remove.
1345
+ # @option options [Boolean] :pretend Just validate, do not broadcast.
1346
+ # @see https://developers.hive.io/apidefinitions/broadcast-ops.html#broadcast_ops_update_proposal_votes
1347
+ def self.remove_proposal(options, &block)
1348
+ required_fields = %i(proposal_owner proposal_ids)
1349
+ params = options[:params]
1350
+
1351
+ check_required_fields(params, *required_fields)
1352
+
1353
+ ops = [[:remove_proposal, params]]
1354
+
1355
+ process(options.merge(ops: ops), &block)
1356
+ end
1357
+
1243
1358
  # @param options [Hash] options
1244
1359
  # @option options [Array<Array<Hash>] :ops Operations to process.
1245
1360
  # @option options [Boolean] :pretend Just validate, do not broadcast.
@@ -208,11 +208,25 @@ module Hive::Fallback
208
208
  :get_account_reputations
209
209
  ],
210
210
  bridge: [
211
+ :normalize_post,
212
+ :get_post_header,
213
+ :get_discussion,
214
+ :get_post,
215
+ :get_account_posts,
216
+ :get_ranked_posts,
217
+ :get_profile,
218
+ :get_trending_topics,
219
+ :post_notifications,
211
220
  :account_notifications,
221
+ :unread_notifications,
222
+ :get_payout_stats,
212
223
  :get_community,
213
- :get_ranked_posts,
224
+ :get_community_context,
225
+ :list_pop_communities,
226
+ :list_subscribers,
214
227
  :list_all_subscriptions,
215
228
  :list_community_roles,
229
+ :list_communities
216
230
  ]
217
231
  }
218
232
 
@@ -277,11 +291,25 @@ module Hive::Fallback
277
291
  get_account_reputations: {account_lower_bound: String, limit: Integer}
278
292
  },
279
293
  bridge: {
280
- account_notifications: {account: String, limit: Integer},
294
+ normalize_post: {post: Hash},
295
+ get_post_header: {author: String, permlink: String},
296
+ get_discussion: {author: String, permlink: String},
297
+ get_post: {author: String, permlink: String, observer: String},
298
+ get_account_posts: {sort: String, account: String, start_account: String, start_permlink: String, limit: Integer, observer: String},
299
+ get_ranked_posts: {sort: String, tag: String, observer: String, limit: Integer, start_author: String, start_permlink: String},
300
+ get_profile: {account: String, observer: String},
301
+ get_trending_topics: {limit: Integer, observer: String},
302
+ post_notifications: {author: String, permlink: String, min_score: Integer, last_id: String, limit: Integer},
303
+ account_notifications: {account: String, min_score: Integer, last_id: Integer, limit: Integer},
304
+ unread_notifications: {account: String, min_score: Integer},
305
+ get_payout_stats: {limit: Integer},
281
306
  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}
307
+ get_community_context: {name: String, account: String},
308
+ list_communities: {last: String, limit: Integer, query: String, sort: String, observer: String},
309
+ list_pop_communities: {limit: Integer},
310
+ list_community_roles: {community: String, last: String, limit: Integer},
311
+ list_subscribers: {community: String},
312
+ list_all_subscriptions: {account: String}
285
313
  }
286
314
  }
287
315
  end
@@ -90,7 +90,7 @@ module Hive
90
90
  end
91
91
 
92
92
  for request_object in chunks do
93
- @rpc_client.rpc_batch_execute(request_object: request_object) do |result, error, id|
93
+ @rpc_client.rpc_batch_execute(api_name: self.class.api_name, request_object: request_object) do |result, error, id|
94
94
  api, method = method_map[id]
95
95
  api = api.to_sym
96
96
  method = method.to_sym
@@ -159,17 +159,16 @@ module Hive
159
159
  key = string.to_sym
160
160
  properties[key] = case key
161
161
  when :account_creation_fee then Hive::Type::Amount.new(string)
162
- when :account_subsidy_budget then scan(3)
163
- when :account_subsidy_decay, :maximum_block_size then uint32
164
- when :url then string
162
+ # when :account_subsidy_budget then int32
163
+ # when :account_subsidy_decay, :maximum_block_size then uint32
165
164
  when :sbd_exchange_rate
166
165
  JSON[string].tap do |rate|
167
166
  rate["base"] = Hive::Type::Amount.new(rate["base"])
168
167
  rate["quote"] = Hive::Type::Amount.new(rate["quote"])
169
168
  end
170
- when :sbd_interest_rate then uint16
171
- when :key, :new_signing_key then @prefix + scan(50)
172
- else; raise "Unknown witness property: #{key}"
169
+ # when :sbd_interest_rate then uint16
170
+ when :url, :key, :new_signing_key then string
171
+ else; warn "Unsupported witness property: #{key}"
173
172
  end
174
173
  end
175
174
 
@@ -180,6 +179,10 @@ module Hive
180
179
  unsigned_char == 0 and [] or raise "Found non-empty array."
181
180
  end
182
181
 
182
+ def uint64_array
183
+ varint.times{ uint64 }
184
+ end
185
+
183
186
  def transaction(options = {})
184
187
  trx = options[:trx] || Transaction.new
185
188
 
@@ -6,7 +6,7 @@ module Hive
6
6
  KNOWN_TYPES = NUMERIC_TYPES + %i(boolean string raw_bytes point_in_time
7
7
  public_key amount price authority optional_authority
8
8
  comment_options_extensions beneficiaries chain_properties required_auths
9
- witness_properties empty_array lambda)
9
+ witness_properties uint64_array empty_array lambda)
10
10
 
11
11
  module ClassMethods
12
12
  def def_attr key_pair
@@ -5,7 +5,7 @@ module Hive
5
5
  include Utils
6
6
 
7
7
  # IDs derrived from:
8
- # https://github.com/openhive-network/hive/blob/127a441fbac2f06804359968bda83b66e602c891/libraries/protocol/include/steem/protocol/operations.hpp
8
+ # https://gitlab.syncad.com/hive/hive/-/blob/master/libraries/protocol/include/steem/protocol/operations.hpp
9
9
 
10
10
  IDS = [
11
11
  :vote_operation,
@@ -60,6 +60,10 @@ module Hive
60
60
  :delegate_vesting_shares_operation,
61
61
  :account_create_with_delegation_operation,
62
62
  :witness_set_properties_operation,
63
+ :account_update2_operation,
64
+ :create_proposal_operation,
65
+ :update_proposal_votes_operation,
66
+ :remove_proposal_operation,
63
67
 
64
68
  # SMT operations
65
69
  :claim_reward_balance2_operation,
@@ -0,0 +1,4 @@
1
+ class Hive::Operation::AccountUpdate2 < Hive::Operation
2
+ def_attr account: :string
3
+ def_attr json_metadata: :string
4
+ end
@@ -0,0 +1,9 @@
1
+ class Hive::Operation::CreateProposal < Hive::Operation
2
+ def_attr creator: :string
3
+ def_attr receiver: :string
4
+ def_attr start_date: :point_in_time
5
+ def_attr end_date: :point_in_time
6
+ def_attr daily_pay: :amount
7
+ def_attr subject: :string
8
+ def_attr permlink: :string
9
+ end
@@ -0,0 +1,4 @@
1
+ class Hive::Operation::RemoveProposal < Hive::Operation
2
+ def_attr proposal_owner: :string
3
+ def_attr proposal_ids: :uint64_array
4
+ end
@@ -0,0 +1,5 @@
1
+ class Hive::Operation::UpdateProposalVotes < Hive::Operation
2
+ def_attr voter: :string
3
+ def_attr proposal_ids: :uint64_array
4
+ def_attr approve: :boolean
5
+ end
@@ -17,7 +17,8 @@ module Hive
17
17
  #
18
18
  # @private
19
19
  TIMEOUT_ERRORS = [Net::OpenTimeout, JSON::ParserError, Net::ReadTimeout,
20
- Errno::EBADF, IOError, Errno::ENETDOWN, Hive::RemoteDatabaseLockError]
20
+ Errno::EBADF, IOError, Errno::ENETDOWN, Hive::RemoteDatabaseLockError,
21
+ Hive::RequestTimeoutUpstreamResponseError, Hive::RemoteNodeError]
21
22
 
22
23
  # @private
23
24
  POST_HEADERS = {
@@ -57,8 +58,10 @@ module Hive
57
58
  def rpc_execute(api_name = @api_name, api_method = nil, options = {}, &block)
58
59
  reset_timeout
59
60
 
60
- catch :tota_cera_pila do; begin
61
- request = http_post
61
+ response = nil
62
+
63
+ loop do
64
+ request = http_post(api_name)
62
65
 
63
66
  request_object = if !!api_name && !!api_method
64
67
  put(api_name, api_method, options)
@@ -80,11 +83,11 @@ module Hive
80
83
 
81
84
  response = catch :http_request do; begin; http_request(request)
82
85
  rescue *TIMEOUT_ERRORS => e
83
- throw retry_timeout(:http_request, e)
86
+ retry_timeout(:http_request, e) and redo
84
87
  end; end
85
88
 
86
89
  if response.nil?
87
- throw retry_timeout(:tota_cera_pila, 'response was nil')
90
+ retry_timeout(:tota_cera_pila, 'response was nil') and redo
88
91
  end
89
92
 
90
93
  case response.code
@@ -108,6 +111,9 @@ module Hive
108
111
  else; response
109
112
  end
110
113
 
114
+ timeout_detected = false
115
+ timeout_cause = nil
116
+
111
117
  [response].flatten.each_with_index do |r, i|
112
118
  if defined?(r.error) && !!r.error
113
119
  if !!r.error.message
@@ -116,7 +122,10 @@ module Hive
116
122
  rpc_args = [request_object].flatten[i]
117
123
  raise_error_response rpc_method_name, rpc_args, r
118
124
  rescue *TIMEOUT_ERRORS => e
119
- throw retry_timeout(:tota_cera_pila, e)
125
+ timeout_detected = true
126
+ timeout_cause = nil
127
+
128
+ break # fail fast
120
129
  end
121
130
  else
122
131
  raise Hive::ArgumentError, r.error.inspect
@@ -124,19 +133,29 @@ module Hive
124
133
  end
125
134
  end
126
135
 
136
+ if timeout_detected
137
+ retry_timeout(:tota_cera_pila, timeout_cause) and redo
138
+ end
139
+
127
140
  yield_response response, &block
128
141
  when '504' # Gateway Timeout
129
- throw retry_timeout(:tota_cera_pila, response.body)
142
+ retry_timeout(:tota_cera_pila, response.body) and redo
130
143
  when '502' # Bad Gateway
131
- throw retry_timeout(:tota_cera_pila, response.body)
144
+ retry_timeout(:tota_cera_pila, response.body) and redo
132
145
  else
133
146
  raise UnknownError, "#{api_name}.#{api_method}: #{response.body}"
134
147
  end
135
- end; end
148
+
149
+ break # success!
150
+ end
151
+
152
+ response
136
153
  end
137
154
 
138
155
  def rpc_batch_execute(options = {}, &block)
139
- yield_response rpc_execute(nil, nil, options), &block
156
+ api_name = options[:api_name]
157
+
158
+ yield_response rpc_execute(api_name, nil, options), &block
140
159
  end
141
160
  end
142
161
  end
@@ -10,13 +10,20 @@ module Hive
10
10
  class ThreadSafeHttpClient < HttpClient
11
11
  SEMAPHORE = Mutex.new.freeze
12
12
 
13
- # Same as #{HttpClient#http_post}, but scoped to each thread so it is
14
- # thread safe.
15
- def http_post
13
+ # Same as #{HttpClient#http_post}, but scoped to each thread, uri, and
14
+ # api_name so it is thread safe.
15
+ def http_post(api_name)
16
+ raise "Namespace required." if api_name.nil?
17
+
16
18
  thread = Thread.current
17
- http_post = thread.thread_variable_get(:http_post)
18
- http_post ||= Net::HTTP::Post.new(uri.request_uri, POST_HEADERS)
19
- thread.thread_variable_set(:http_post, http_post)
19
+ http_posts = thread.thread_variable_get(:http_posts) || {}
20
+
21
+ SEMAPHORE.synchronize do
22
+ http_posts[[uri, api_name]] ||= Net::HTTP::Post.new(uri.request_uri, POST_HEADERS)
23
+ thread.thread_variable_set(:http_posts, http_posts)
24
+ end
25
+
26
+ http_posts[[uri, api_name]]
20
27
  end
21
28
 
22
29
  def http_request(request); SEMAPHORE.synchronize{super}; end
@@ -1,4 +1,4 @@
1
1
  module Hive
2
- VERSION = '1.0.0-1'
2
+ VERSION = '1.0.0-2'
3
3
  AGENT_ID = "hive-ruby/#{VERSION}"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.1
4
+ version: 1.0.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2020-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,22 +54,22 @@ dependencies:
54
54
  name: minitest
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '5.10'
60
57
  - - ">="
61
58
  - !ruby/object:Gem::Version
62
59
  version: 5.10.3
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '5.14'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '5.10'
70
67
  - - ">="
71
68
  - !ruby/object:Gem::Version
72
69
  version: 5.10.3
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '5.14'
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: minitest-line
75
75
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +159,7 @@ dependencies:
159
159
  version: 4.0.0
160
160
  - - "~>"
161
161
  - !ruby/object:Gem::Version
162
- version: '5.1'
162
+ version: '6.0'
163
163
  type: :development
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
@@ -169,7 +169,7 @@ dependencies:
169
169
  version: 4.0.0
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '5.1'
172
+ version: '6.0'
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: yard
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -398,12 +398,15 @@ extensions: []
398
398
  extra_rdoc_files: []
399
399
  files:
400
400
  - ".gitignore"
401
+ - ".gitlab-ci.yml"
401
402
  - CONTRIBUTING.md
402
403
  - Gemfile
403
- - Gemfile.lock
404
404
  - LICENSE
405
405
  - README.md
406
406
  - Rakefile
407
+ - assets/logo-128.png
408
+ - assets/logo.png
409
+ - assets/logo.xcf
407
410
  - gource.sh
408
411
  - hive-ruby.gemspec
409
412
  - images/Anthony Martin.png
@@ -425,6 +428,7 @@ files:
425
428
  - lib/hive/operation/account_create.rb
426
429
  - lib/hive/operation/account_create_with_delegation.rb
427
430
  - lib/hive/operation/account_update.rb
431
+ - lib/hive/operation/account_update2.rb
428
432
  - lib/hive/operation/account_witness_proxy.rb
429
433
  - lib/hive/operation/account_witness_vote.rb
430
434
  - lib/hive/operation/cancel_transfer_from_savings.rb
@@ -436,6 +440,7 @@ files:
436
440
  - lib/hive/operation/comment_options.rb
437
441
  - lib/hive/operation/convert.rb
438
442
  - lib/hive/operation/create_claimed_account.rb
443
+ - lib/hive/operation/create_proposal.rb
439
444
  - lib/hive/operation/custom.rb
440
445
  - lib/hive/operation/custom_binary.rb
441
446
  - lib/hive/operation/custom_json.rb
@@ -452,6 +457,7 @@ files:
452
457
  - lib/hive/operation/limit_order_create2.rb
453
458
  - lib/hive/operation/prove_authority.rb
454
459
  - lib/hive/operation/recover_account.rb
460
+ - lib/hive/operation/remove_proposal.rb
455
461
  - lib/hive/operation/report_over_production.rb
456
462
  - lib/hive/operation/request_account_recovery.rb
457
463
  - lib/hive/operation/reset_account.rb
@@ -461,6 +467,7 @@ files:
461
467
  - lib/hive/operation/transfer_from_savings.rb
462
468
  - lib/hive/operation/transfer_to_savings.rb
463
469
  - lib/hive/operation/transfer_to_vesting.rb
470
+ - lib/hive/operation/update_proposal_votes.rb
464
471
  - lib/hive/operation/vote.rb
465
472
  - lib/hive/operation/withdraw_vesting.rb
466
473
  - lib/hive/operation/witness_set_properties.rb
@@ -479,7 +486,7 @@ homepage: https://gitlab.syncad.com/hive/hive-ruby
479
486
  licenses:
480
487
  - MIT
481
488
  metadata: {}
482
- post_install_message:
489
+ post_install_message:
483
490
  rdoc_options: []
484
491
  require_paths:
485
492
  - lib
@@ -494,9 +501,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
494
501
  - !ruby/object:Gem::Version
495
502
  version: 1.3.1
496
503
  requirements: []
497
- rubyforge_project:
498
- rubygems_version: 2.7.10
499
- signing_key:
504
+ rubygems_version: 3.0.8
505
+ signing_key:
500
506
  specification_version: 4
501
507
  summary: Hive Ruby Client
502
508
  test_files: []
@@ -1,91 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- hive-ruby (1.0.0.pre.1)
5
- base58 (~> 0.2, >= 0.2.3)
6
- bindata (~> 2.4, >= 2.4.4)
7
- bitcoin-ruby (~> 0.0, >= 0.0.18)
8
- ffi (~> 1.9, >= 1.9.23)
9
- hashie (~> 3.5, >= 3.5.7)
10
- json (~> 2.1, >= 2.1.0)
11
- logging (~> 2.2, >= 2.2.0)
12
-
13
- GEM
14
- remote: https://rubygems.org/
15
- specs:
16
- addressable (2.7.0)
17
- public_suffix (>= 2.0.2, < 5.0)
18
- awesome_print (1.8.0)
19
- base58 (0.2.3)
20
- bindata (2.4.7)
21
- bitcoin-ruby (0.0.20)
22
- eventmachine
23
- ffi
24
- scrypt
25
- coderay (1.1.2)
26
- crack (0.4.3)
27
- safe_yaml (~> 1.0.0)
28
- docile (1.3.2)
29
- eventmachine (1.2.7)
30
- ffi (1.12.2)
31
- ffi-compiler (1.0.1)
32
- ffi (>= 1.0.0)
33
- rake
34
- hashdiff (1.0.1)
35
- hashie (3.6.0)
36
- io-console (0.5.6)
37
- irb (1.2.4)
38
- reline (>= 0.0.1)
39
- json (2.3.0)
40
- little-plugger (1.1.4)
41
- logging (2.2.2)
42
- little-plugger (~> 1.1)
43
- multi_json (~> 1.10)
44
- method_source (1.0.0)
45
- minitest (5.14.0)
46
- minitest-line (0.6.5)
47
- minitest (~> 5.0)
48
- minitest-proveit (1.0.0)
49
- minitest (> 5, < 7)
50
- multi_json (1.14.1)
51
- pry (0.13.1)
52
- coderay (~> 1.1)
53
- method_source (~> 1.0)
54
- public_suffix (4.0.4)
55
- rake (13.0.1)
56
- reline (0.1.4)
57
- io-console (~> 0.5)
58
- safe_yaml (1.0.5)
59
- scrypt (3.0.7)
60
- ffi-compiler (>= 1.0, < 2.0)
61
- simplecov (0.18.5)
62
- docile (~> 1.1)
63
- simplecov-html (~> 0.11)
64
- simplecov-html (0.12.2)
65
- vcr (5.1.0)
66
- webmock (3.8.3)
67
- addressable (>= 2.3.6)
68
- crack (>= 0.3.2)
69
- hashdiff (>= 0.4.0, < 2.0.0)
70
- yard (0.9.25)
71
-
72
- PLATFORMS
73
- ruby
74
-
75
- DEPENDENCIES
76
- awesome_print (~> 1.8, >= 1.8.0)
77
- bundler (~> 1.16, >= 1.16.1)
78
- hive-ruby!
79
- irb (~> 1.2, >= 1.2.3)
80
- minitest (~> 5.10, >= 5.10.3)
81
- minitest-line (~> 0.6, >= 0.6.4)
82
- minitest-proveit (~> 1.0, >= 1.0.0)
83
- pry (~> 0.11, >= 0.11.3)
84
- rake (~> 13.0.1, >= 12.3.0)
85
- simplecov (~> 0.15, >= 0.15.1)
86
- vcr (~> 5.1, >= 4.0.0)
87
- webmock (~> 3.3, >= 3.3.0)
88
- yard (~> 0.9, >= 0.9.12)
89
-
90
- BUNDLED WITH
91
- 1.16.6