tezos_client 0.4.9 → 0.4.11

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: d68c46e8ce54db3ab5deaaec705d5bb3f746706aaf35f592687f5282bf847225
4
- data.tar.gz: f5d7effdcd2a84cebf396b2901189371bc9e2f47f092aa23fbae3bdcccd764c5
3
+ metadata.gz: c0a4f06598c871a6a091162764772e2314c0e066f3a802cf272bd123010c99a8
4
+ data.tar.gz: 379749cd74ba26165beda45f4379c84bd48ab1cd1380d142f7a1c298b8c41c97
5
5
  SHA512:
6
- metadata.gz: a6edec149c2d3b5390cc97c761015511e6012b5524d5dfeb0cb3a68965c28b47af5780690e66ec8b6ef8f9e67c914b2527c26b7e413bb1a7f69f2d42db2ddd07
7
- data.tar.gz: 22c34b38fd4cd477a4c4687a5db02ed0bce9fa0f70daae778ea78fbc6bca505836dd1ea6768a644f270807e33269efb54a02dfa3ec0eb9e57ad63ca8c1f5b079
6
+ metadata.gz: f9dba5d7b1d7ed4189fd19f798e6a0d472f81d216e6809323187a5b3328aac9c4b5d2c06145486762c1f80b8a9f2658901f57f811b1ab2c90606d852cdd15b18
7
+ data.tar.gz: 653e578e0b6593fc9186e449cc5af8646ee3b331e9f31000ad316ce6c078d1aba7282a39d8d2f42f709abade18ad4791d4866cce44d8de1b59c411c14646ee29
data/.gitignore CHANGED
@@ -11,4 +11,7 @@
11
11
  .rspec_status
12
12
 
13
13
  # Rubymine configuration file
14
- .idea/*
14
+ .idea/*
15
+
16
+ # vim ctags
17
+ .tags
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tezos_client (0.4.9)
4
+ tezos_client (0.4.11)
5
5
  activesupport (~> 5.2.3)
6
6
  base58 (~> 0.2.3)
7
7
  bip_mnemonic (~> 0.0.2)
@@ -37,6 +37,7 @@ GEM
37
37
  base58 (0.2.3)
38
38
  bip_mnemonic (0.0.4)
39
39
  builder (3.2.3)
40
+ coderay (1.1.2)
40
41
  concurrent-ruby (1.1.5)
41
42
  crack (0.4.3)
42
43
  safe_yaml (~> 1.0.0)
@@ -73,6 +74,9 @@ GEM
73
74
  parallel (1.17.0)
74
75
  parser (2.6.4.0)
75
76
  ast (~> 2.4.0)
77
+ pry (0.12.2)
78
+ coderay (~> 1.1.0)
79
+ method_source (~> 0.9.0)
76
80
  public_suffix (4.0.1)
77
81
  rack (2.0.7)
78
82
  rack-test (1.1.0)
@@ -147,6 +151,7 @@ PLATFORMS
147
151
 
148
152
  DEPENDENCIES
149
153
  bundler (~> 1.16)
154
+ pry
150
155
  rake (~> 10.0)
151
156
  rspec (~> 3.0)
152
157
  rubocop-rails_config
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TezosClient
4
+ class ComputeOperationArgsCounters
5
+ def initialize(pending_operations:, operation_args:)
6
+ @pending_operations = pending_operations
7
+ @operation_args = Marshal.load(Marshal.dump(operation_args)) # deep copy of the object
8
+ end
9
+
10
+ def call
11
+ max_counter_by_source = group_by_max_counter(
12
+ @pending_operations["applied"].map { |operation| operation["contents"] }
13
+ .flatten
14
+ .select { |content| content.has_key?("source") }
15
+ )
16
+
17
+ @operation_args.each do |operation|
18
+ source = operation[:source]
19
+ # do not update the counter of an operation not present in the mempool
20
+ next unless max_counter_by_source[source]
21
+
22
+ operation[:counter] = (max_counter_by_source[source].to_i + 1).to_s
23
+ # update max_counter_by_source as if the current operation was added to the mempool
24
+ max_counter_by_source[source] = operation[:counter]
25
+ end
26
+
27
+ @operation_args
28
+ end
29
+
30
+ private
31
+ def group_by_max_counter(arr)
32
+ arr.map(&:with_indifferent_access)
33
+ .group_by { |hsh| hsh[:source] }
34
+ .each_with_object({}) do |(source, contents), acc|
35
+ acc[source] = contents.max_by { |content| content[:counter].to_i }[:counter]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,6 @@
1
+ require "tezos_client/compute_operation_args_counters"
1
2
 
2
3
  class TezosClient
3
-
4
4
  class OperationMgr
5
5
  include Crypto
6
6
  using CurrencyUtils
@@ -16,12 +16,17 @@ class TezosClient
16
16
  @signed_operation_args_h = nil
17
17
  @branch = args[:branch]
18
18
  @protocol = args[:protocol]
19
+ @ignore_counter_error = args[:ignore_counter_error]
19
20
  end
20
21
 
21
22
  def multiple_operations?
22
23
  @multiple_operations
23
24
  end
24
25
 
26
+ def ignore_counter_error?
27
+ !!@ignore_counter_error
28
+ end
29
+
25
30
  def single_operation?
26
31
  !multiple_operations?
27
32
  end
@@ -86,9 +91,8 @@ class TezosClient
86
91
 
87
92
  def test_and_broadcast
88
93
  simulate_res = simulate
89
-
90
-
91
94
  op_id = broadcast
95
+
92
96
  {
93
97
  operation_id: op_id,
94
98
  operation_results: simulate_res[:operation_results],
@@ -108,9 +112,12 @@ class TezosClient
108
112
 
109
113
  operation_results = rpc_responses.map do |rpc_response|
110
114
  metadata = rpc_response[:metadata]
115
+
111
116
  total_consumed_storage += compute_consumed_storage(metadata)
112
117
  consumed_gas = compute_consumed_gas(metadata)
113
118
  total_consumed_gas += consumed_gas
119
+
120
+ metadata[:operation_result][:consumed_gas] = consumed_gas if metadata.key? :operation_result
114
121
  metadata[:operation_result]
115
122
  end
116
123
 
@@ -123,11 +130,11 @@ class TezosClient
123
130
  end
124
131
 
125
132
  def compute_consumed_gas(metadata)
126
- consumed_gas = (metadata.dig(:operation_result, :consumed_gas) || "0").to_i.from_satoshi
133
+ consumed_gas = (metadata.dig(:operation_result, :consumed_gas) || "0").to_i
127
134
 
128
135
  if metadata.key?(:internal_operation_results)
129
136
  metadata[:internal_operation_results].each do |internal_operation_result|
130
- consumed_gas += (internal_operation_result[:result][:consumed_gas] || "0").to_i.from_satoshi
137
+ consumed_gas += (internal_operation_result[:result][:consumed_gas] || "0").to_i
131
138
  end
132
139
  end
133
140
  consumed_gas
@@ -149,6 +156,11 @@ class TezosClient
149
156
  end
150
157
 
151
158
  def broadcast
159
+ self.rpc_operation_args = ::TezosClient::ComputeOperationArgsCounters.new(
160
+ pending_operations: rpc_interface.pending_operations,
161
+ operation_args: rpc_operation_args
162
+ ).call if ignore_counter_error?
163
+
152
164
  rpc_interface.broadcast_operation(signed_hex)
153
165
  end
154
166
 
@@ -1,6 +1,6 @@
1
1
  class TezosClient
2
2
  class Operation
3
- delegate :run, :preapply, :test_and_broadcast, :simulate, :signed_hex, to: :operation_mgr
3
+ delegate :run, :preapply, :test_and_broadcast, :broadcast, :simulate, :signed_hex, to: :operation_mgr
4
4
 
5
5
  def initialize(rpc_interface:, **args)
6
6
  @rpc_interface = rpc_interface
@@ -27,7 +27,7 @@ class TezosClient
27
27
  end
28
28
 
29
29
  def operation_options
30
- @args.slice(:secret_key, :protocol, :branch)
30
+ @args.slice(:secret_key, :protocol, :branch, :ignore_counter_error)
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TezosClient
4
- VERSION = "0.4.9"
4
+ VERSION = "0.4.11"
5
5
  end
data/lib/tezos_client.rb CHANGED
@@ -29,7 +29,6 @@ require "tezos_client/client_interface"
29
29
  require "tezos_client/rpc_interface"
30
30
  require "tezos_client/liquidity_interface"
31
31
 
32
-
33
32
  class TezosClient
34
33
  using CurrencyUtils
35
34
  using StringUtils
data/tezos_client.gemspec CHANGED
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "rubocop-rails_config"
40
40
  spec.add_development_dependency "webmock"
41
41
  spec.add_development_dependency "vcr", "~> 4.0.0"
42
+ spec.add_development_dependency "pry"
42
43
 
43
44
  spec.add_dependency "base58", "~> 0.2.3"
44
45
  spec.add_dependency "httparty", "~> 0.17.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tezos_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Michard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-20 00:00:00.000000000 Z
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 4.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: base58
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +234,7 @@ files:
220
234
  - lib/tezos_client/client_interface/key.rb
221
235
  - lib/tezos_client/client_interface/misc.rb
222
236
  - lib/tezos_client/commands.rb
237
+ - lib/tezos_client/compute_operation_args_counters.rb
223
238
  - lib/tezos_client/crypto.rb
224
239
  - lib/tezos_client/currency_utils.rb
225
240
  - lib/tezos_client/encode_utils.rb