tezos_client 1.2.3 → 1.3.0

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: 1edfdfe5f7332ebbe4ecafd4baa3f03998e02204e33f854d9f394ba84cbf98c3
4
- data.tar.gz: 7544eba6b1a6d602b24025a5c2831c1e803f53f92ae5f0925daa05a0b2ef3167
3
+ metadata.gz: a4b97cc7f2f7ce85618cf8e16ae7b921f7e4221b1e27a1ea52c415c309076cf1
4
+ data.tar.gz: 6ddca2df0566dc441cc0a3389f5a0f86d9015766118d775c27166b2bab2d247e
5
5
  SHA512:
6
- metadata.gz: 4a4e3ddacd06478d21821ce1e38ac5d731f2602d6cbca55e2440828de46c5933aaa8b77df00d3d989295ee325318ff53284725dc91d165ed32918cd2b3de9d8a
7
- data.tar.gz: 980264f44b9761e4f7e716675a5775d1b2f3cbfd6de5d09024154c53000a1a95cc3c168efe259c1fd7b78d9a877d23a6c0fa4feea8a8bda942b753122cf73bc7
6
+ metadata.gz: ba5a9ae1ab33a17abe2c263a687e03278ededd753d2baaadd999ea6350d15bc2de9ccd990aee1ca6db14acd794ec45174229b517997774d5442ad34a0526260d
7
+ data.tar.gz: 8044d64bb09b9f0c616413a1ed308ebec7e6c9af39700fcae6c134fab3ad6c785f86faf89863ee1e0cf857488ed040d8b7e56c2901cfdc9042335697798762b0
@@ -13,11 +13,11 @@ rvm:
13
13
  before_install:
14
14
  - sh travis-scripts/prepare-ubuntu.sh
15
15
  - mkdir -p $HOME/bin
16
- - curl -s https://SmartPy.io/SmartPyBasic/SmartPy.sh > SmartPy.sh
16
+ - curl -s https://smartpy.io/dev-20200912-bbb4b34cb579f3d52320c3d2aed8ebcef04429b0/cli/SmartPy.sh > SmartPy.sh
17
17
  - chmod +x ./SmartPy.sh
18
- - ./SmartPy.sh local-install $HOME/bin/smartpy
18
+ - ./SmartPy.sh local-install-auto $HOME/bin/smartpy/cli
19
19
  - rm ./SmartPy.sh
20
- - export PATH="$PATH:$HOME/bin/:$HOME/bin/smartpy/SmartPyBasic/"
20
+ - export PATH="$PATH:$HOME/bin/:$HOME/bin/smartpy/cli/"
21
21
  - npm link michelson-to-micheline
22
22
  - gem install bundler -v 1.16.3
23
23
  script:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tezos_client (1.2.3)
4
+ tezos_client (1.3.0)
5
5
  active_interaction (~> 3.7)
6
6
  activesupport (~> 6.0.0)
7
7
  base58 (~> 0.2.3)
@@ -14,24 +14,24 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- actionpack (6.0.3.2)
18
- actionview (= 6.0.3.2)
19
- activesupport (= 6.0.3.2)
17
+ actionpack (6.0.3.3)
18
+ actionview (= 6.0.3.3)
19
+ activesupport (= 6.0.3.3)
20
20
  rack (~> 2.0, >= 2.0.8)
21
21
  rack-test (>= 0.6.3)
22
22
  rails-dom-testing (~> 2.0)
23
23
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
24
- actionview (6.0.3.2)
25
- activesupport (= 6.0.3.2)
24
+ actionview (6.0.3.3)
25
+ activesupport (= 6.0.3.3)
26
26
  builder (~> 3.1)
27
27
  erubi (~> 1.4)
28
28
  rails-dom-testing (~> 2.0)
29
29
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
30
- active_interaction (3.8.2)
30
+ active_interaction (3.8.3)
31
31
  activemodel (>= 4, < 7)
32
- activemodel (6.0.3.2)
33
- activesupport (= 6.0.3.2)
34
- activesupport (6.0.3.2)
32
+ activemodel (6.0.3.3)
33
+ activesupport (= 6.0.3.3)
34
+ activesupport (6.0.3.3)
35
35
  concurrent-ruby (~> 1.0, >= 1.0.2)
36
36
  i18n (>= 0.7, < 2)
37
37
  minitest (~> 5.1)
@@ -44,7 +44,7 @@ GEM
44
44
  bip_mnemonic (0.0.4)
45
45
  builder (3.2.4)
46
46
  coderay (1.1.2)
47
- concurrent-ruby (1.1.6)
47
+ concurrent-ruby (1.1.7)
48
48
  crack (0.4.3)
49
49
  safe_yaml (~> 1.0.0)
50
50
  crass (1.0.6)
@@ -59,10 +59,10 @@ GEM
59
59
  httparty (0.17.3)
60
60
  mime-types (~> 3.0)
61
61
  multi_xml (>= 0.5.2)
62
- i18n (1.8.3)
62
+ i18n (1.8.5)
63
63
  concurrent-ruby (~> 1.0)
64
64
  jaro_winkler (1.5.3)
65
- loofah (2.6.0)
65
+ loofah (2.7.0)
66
66
  crass (~> 1.0.2)
67
67
  nokogiri (>= 1.5.9)
68
68
  method_source (0.9.2)
@@ -70,12 +70,12 @@ GEM
70
70
  mime-types-data (~> 3.2015)
71
71
  mime-types-data (3.2020.0512)
72
72
  mini_portile2 (2.4.0)
73
- minitest (5.14.1)
73
+ minitest (5.14.2)
74
74
  money-tree (0.10.0)
75
75
  ffi
76
76
  multi_xml (0.6.0)
77
77
  netrc (0.11.0)
78
- nokogiri (1.10.9)
78
+ nokogiri (1.10.10)
79
79
  mini_portile2 (~> 2.4.0)
80
80
  parallel (1.18.0)
81
81
  parser (2.6.5.0)
@@ -92,9 +92,9 @@ GEM
92
92
  nokogiri (>= 1.6)
93
93
  rails-html-sanitizer (1.3.0)
94
94
  loofah (~> 2.3)
95
- railties (6.0.3.2)
96
- actionpack (= 6.0.3.2)
97
- activesupport (= 6.0.3.2)
95
+ railties (6.0.3.3)
96
+ actionpack (= 6.0.3.3)
97
+ activesupport (= 6.0.3.3)
98
98
  method_source
99
99
  rake (>= 0.8.7)
100
100
  thor (>= 0.20.3, < 2.0)
@@ -151,7 +151,7 @@ GEM
151
151
  addressable (>= 2.3.6)
152
152
  crack (>= 0.3.2)
153
153
  hashdiff (>= 0.4.0, < 2.0.0)
154
- zeitwerk (2.3.0)
154
+ zeitwerk (2.4.0)
155
155
 
156
156
  PLATFORMS
157
157
  ruby
@@ -25,6 +25,7 @@ class TezosClient
25
25
  :contract_big_maps,
26
26
  :block_operations,
27
27
  :contract_storage_type,
28
- :entrypoint
28
+ :entrypoint,
29
+ :entrypoints
29
30
  end
30
31
  end
@@ -202,40 +202,39 @@ class TezosClient
202
202
  end
203
203
 
204
204
  private
205
+ def ensure_applied!(rpc_responses)
206
+ metadatas = rpc_responses.map { |response| response[:metadata] }
207
+ operation_results = metadatas.map { |metadata| metadata[:operation_result] }
208
+ internal_operations = metadatas.map { |metadata| metadata[:internal_operation_results] }.flatten.compact
209
+ operation_results.concat(internal_operations.map { |internal_operation| internal_operation[:result] })
210
+
211
+ failed = operation_results.detect do |operation_result|
212
+ operation_result != nil && operation_result[:status] != "applied"
213
+ end
205
214
 
206
- def ensure_applied!(rpc_responses)
207
- metadatas = rpc_responses.map { |response| response[:metadata] }
208
- operation_results = metadatas.map { |metadata| metadata[:operation_result] }
209
- internal_operations = metadatas.map { |metadata| metadata[:internal_operation_results] }.flatten.compact
210
- operation_results.concat(internal_operations.map { |internal_operation| internal_operation[:result] })
211
-
212
- failed = operation_results.detect do |operation_result|
213
- operation_result != nil && operation_result[:status] != "applied"
214
- end
215
+ return metadatas if failed.nil?
215
216
 
216
- return metadatas if failed.nil?
217
+ failed_operation_result = operation_results.detect do |operation_result|
218
+ operation_result[:status] == "failed"
219
+ end
217
220
 
218
- failed_operation_result = operation_results.detect do |operation_result|
219
- operation_result[:status] == "failed"
221
+ failed!("failed", failed_operation_result[:errors], operation_results)
220
222
  end
221
223
 
222
- failed!("failed", failed_operation_result[:errors], operation_results)
223
- end
224
-
225
- def exception_klass(errors)
226
- error = errors[0]
227
- case error[:id]
228
- when TezBalanceTooLow::FIRST_ERROR_REGEXP
229
- TezBalanceTooLow
230
- when ScriptRuntimeError::FIRST_ERROR_REGEXP
231
- ScriptRuntimeError
232
- else
233
- OperationFailure
224
+ def exception_klass(errors)
225
+ error = errors[0]
226
+ case error[:id]
227
+ when TezBalanceTooLow::FIRST_ERROR_REGEXP
228
+ TezBalanceTooLow
229
+ when ScriptRuntimeError::FIRST_ERROR_REGEXP
230
+ ScriptRuntimeError
231
+ else
232
+ OperationFailure
233
+ end
234
234
  end
235
- end
236
235
 
237
- def failed!(status, errors, metadata)
238
- raise exception_klass(errors).new(metadata: metadata, errors: errors, status: status)
239
- end
236
+ def failed!(status, errors, metadata)
237
+ raise exception_klass(errors).new(metadata: metadata, errors: errors, status: status)
238
+ end
240
239
  end
241
- end
240
+ end
@@ -37,6 +37,10 @@ class TezosClient
37
37
  get "#{contract_link(contract_id)}/storage"
38
38
  end
39
39
 
40
+ def entrypoints(contract_id)
41
+ get("#{contract_link(contract_id)}/entrypoints")
42
+ end
43
+
40
44
  def entrypoint(contract_id, entrypoint)
41
45
  get("#{contract_link(contract_id)}/entrypoints/#{entrypoint}")
42
46
  end
@@ -30,16 +30,16 @@ class TezosClient
30
30
  end
31
31
 
32
32
  private
33
- def compile_to_michelson(args)
34
- Tools::TemporaryFile.with_file_copy(args[:script]) do |script_copy_path|
35
- script_basename = script_copy_path.split("/").last.sub(/.py$/, "")
36
- script_path = "/tmp/#{script_basename}/"
37
- init_script_filename = "contractStorage.tz"
38
- contract_script_filename = "contractCode.tz.json"
39
- call_smartpy ["local-compile", script_copy_path, args[:init_params], script_path]
40
-
41
- yield(script_path + contract_script_filename, script_path + init_script_filename)
42
- end
33
+ def compile_to_michelson(args)
34
+ Tools::TemporaryFile.with_file_copy(args[:script]) do |script_copy_path|
35
+ script_basename = script_copy_path.split("/").last.sub(/.py$/, "")
36
+ script_path = "/tmp/#{script_basename}/"
37
+ init_script_filename = "#{script_basename}_storage_init.tz"
38
+ contract_script_filename = "#{script_basename}_compiled.json"
39
+ call_smartpy ["compile", script_copy_path, args[:init_params], script_path]
40
+
41
+ yield(script_path + contract_script_filename, script_path + init_script_filename)
43
42
  end
43
+ end
44
44
  end
45
45
  end
@@ -23,20 +23,28 @@ class TezosClient::Tools::AnnotsToType < ActiveInteraction::Base
23
23
  annot_type = typed_annots[annot]
24
24
 
25
25
  unless annots.size == 1
26
- return [{ "prim" => "pair", "args" => generate_type_args(annots) },
27
- { "prim" => annot_type, "annots" => ["%#{annot}"] }]
26
+ return [
27
+ {
28
+ "prim" => annot_type,
29
+ "annots" => ["%#{annot}"]
30
+ },
31
+ {
32
+ "prim" => "pair",
33
+ "args" => generate_type_args(annots)
34
+ }
35
+ ]
28
36
  end
29
37
 
30
38
  generated_args = [{ "prim" => annot_type, "annots" => ["%#{annot}"] }]
31
39
  annot = annots.pop
32
40
  annot_type = typed_annots[annot]
33
- generated_args.unshift({ "prim" => annot_type, "annots" => ["%#{annot}"] })
41
+ generated_args.append({ "prim" => annot_type, "annots" => ["%#{annot}"] })
34
42
 
35
43
  generated_args
36
44
  end
37
45
 
38
46
  def ordered_annots
39
- @ordered_annots ||= typed_annots.keys.sort
47
+ @ordered_annots ||= typed_annots.keys.sort.reverse
40
48
  end
41
49
 
42
50
  def validate_types
@@ -22,7 +22,7 @@ class TezosClient
22
22
  type: type
23
23
  ).decode
24
24
 
25
- rescue NameError => e
25
+ rescue NameError
26
26
  raise NotImplementedError, "type '#{type[:prim]}' not implemented"
27
27
  end
28
28
 
@@ -22,7 +22,7 @@ class TezosClient::Tools::HashToMicheline < ActiveInteraction::Base
22
22
  # }
23
23
  hash :params, strip: false
24
24
  hash :storage_type, strip: false, default: {}
25
- interface :blockchain_client, methods: [:entrypoint], default: -> { TezosClient.new }
25
+ interface :blockchain_client, methods: %i[entrypoint entrypoints], default: -> { TezosClient.new }
26
26
 
27
27
  # if storage_type is not received, it is fetched from the blockchain using
28
28
  # contract_address and entrypoint (that are mandatory in this case)
@@ -40,7 +40,24 @@ class TezosClient::Tools::HashToMicheline < ActiveInteraction::Base
40
40
  next acc << { prim: "Pair", args: generate_micheline(h[:args]) } if h[:prim] == "pair"
41
41
 
42
42
  annot = h[:annots].first.slice(1..-1).to_sym # remove '%'
43
- acc << hash_type_to_hash_data(h[:prim], params.fetch(annot))
43
+
44
+ if h[:prim] == "option"
45
+ value = params.fetch(annot)
46
+ if value
47
+ acc << {
48
+ "prim": "Some",
49
+ "args": [
50
+ hash_type_to_hash_data(h[:args][0][:prim], params.fetch(annot))
51
+ ]
52
+ }
53
+ else
54
+ acc << {
55
+ "prim": "None"
56
+ }
57
+ end
58
+ else
59
+ acc << hash_type_to_hash_data(h[:prim], params.fetch(annot))
60
+ end
44
61
  end
45
62
  end
46
63
 
@@ -65,12 +82,27 @@ class TezosClient::Tools::HashToMicheline < ActiveInteraction::Base
65
82
  { type => converted_value }
66
83
  end
67
84
 
85
+ def _entrypoint
86
+ @_entrypoint ||= select_entrypoint
87
+ end
88
+
89
+ def select_entrypoint
90
+ entrypoints = blockchain_client.entrypoints(contract_address)["entrypoints"].keys
91
+ if entrypoints.count == 0
92
+ "default"
93
+ elsif entrypoints.include?(entrypoint)
94
+ entrypoint
95
+ else
96
+ errors.add(:entrypoint, :not_found)
97
+ end
98
+ end
99
+
68
100
  def _storage_type
69
- (storage_type.presence || blockchain_client.entrypoint(contract_address, entrypoint)).deep_symbolize_keys
101
+ (storage_type.presence || blockchain_client.entrypoint(contract_address, _entrypoint)).deep_symbolize_keys
70
102
  end
71
103
 
72
104
  def storage_type_or_contract_address_presence
73
- return if storage_type.present? ^ (contract_address.present? && entrypoint.present?)
105
+ return if storage_type.present? ^ (contract_address.present?)
74
106
 
75
107
  errors.add(:base,
76
108
  "You should provide the contract_address and the entrypoint only if storage_type is not provided")
@@ -5,10 +5,10 @@ class TezosClient
5
5
  module SystemCall
6
6
  def self.execute(cmd)
7
7
  Open3.popen3(*cmd) do |_stdin, stdout, stderr, wait_thr|
8
- err = stderr.read
9
8
  status = wait_thr.value.exitstatus
10
9
 
11
10
  if status != 0
11
+ err = stdout.read + stderr.read
12
12
  raise ::TezosClient::SysCallError, "command '#{cmd}' existed with status #{status}: #{err}"
13
13
  end
14
14
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TezosClient
4
- VERSION = "1.2.3"
4
+ VERSION = "1.3.0"
5
5
  end
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: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Michard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -316,7 +316,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
316
316
  - !ruby/object:Gem::Version
317
317
  version: '0'
318
318
  requirements: []
319
- rubygems_version: 3.0.4
319
+ rubyforge_project:
320
+ rubygems_version: 2.7.6
320
321
  signing_key:
321
322
  specification_version: 4
322
323
  summary: Wrapper to the tezos client.