tezos_client 1.2.1 → 1.3.2
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -3
- data/Gemfile.lock +25 -25
- data/README.md +2 -1
- data/lib/tezos_client.rb +21 -2
- data/lib/tezos_client/commands.rb +3 -1
- data/lib/tezos_client/crypto.rb +20 -0
- data/lib/tezos_client/exceptions.rb +3 -0
- data/lib/tezos_client/operation_mgr.rb +28 -29
- data/lib/tezos_client/rpc_interface/contracts.rb +4 -0
- data/lib/tezos_client/smartpy_interface.rb +10 -10
- data/lib/tezos_client/tools/annots_to_type.rb +56 -0
- data/lib/tezos_client/tools/convert_to_hash/base.rb +1 -1
- data/lib/tezos_client/tools/convert_to_hash/option.rb +20 -0
- data/lib/tezos_client/tools/hash_to_micheline.rb +102 -0
- data/lib/tezos_client/tools/system_call.rb +1 -1
- data/lib/tezos_client/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4767efa7b67fc781a2bee7f46beefc6a40f649fc4d3639fd279f1a0fcf76ed4
|
|
4
|
+
data.tar.gz: 4fef498bf7d952d82202ee4323efa107f7456b2d2f4aabfaabc5fb20cd451a9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fcdbd1fca67c85791fd3259c29d140417f2712d458cb61d57136fe035a3aacbecfd89a1de8f47db0772481251fc6b670696044c3e424042b80afd59265530ab
|
|
7
|
+
data.tar.gz: 3a6eeff8a54d35eddaf62da354b420718805f110e2996838aab6b6a564f1e44a57bd5572a1b5a3717cec311234820e5ebbd51fb18d908064eaff861862b0f0ad
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.5
|
|
1
|
+
2.6.5
|
data/.travis.yml
CHANGED
|
@@ -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://
|
|
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/
|
|
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:
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
tezos_client (1.2
|
|
4
|
+
tezos_client (1.3.2)
|
|
5
5
|
active_interaction (~> 3.7)
|
|
6
6
|
activesupport (~> 6.0.0)
|
|
7
7
|
base58 (~> 0.2.3)
|
|
@@ -14,29 +14,29 @@ PATH
|
|
|
14
14
|
GEM
|
|
15
15
|
remote: https://rubygems.org/
|
|
16
16
|
specs:
|
|
17
|
-
actionpack (6.0.
|
|
18
|
-
actionview (= 6.0.
|
|
19
|
-
activesupport (= 6.0.
|
|
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.
|
|
25
|
-
activesupport (= 6.0.
|
|
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.
|
|
30
|
+
active_interaction (3.8.3)
|
|
31
31
|
activemodel (>= 4, < 7)
|
|
32
|
-
activemodel (6.0.
|
|
33
|
-
activesupport (= 6.0.
|
|
34
|
-
activesupport (6.0.
|
|
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)
|
|
38
38
|
tzinfo (~> 1.1)
|
|
39
|
-
zeitwerk (~> 2.2)
|
|
39
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
40
40
|
addressable (2.7.0)
|
|
41
41
|
public_suffix (>= 2.0.2, < 5.0)
|
|
42
42
|
ast (2.4.0)
|
|
@@ -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.
|
|
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)
|
|
@@ -52,30 +52,30 @@ GEM
|
|
|
52
52
|
domain_name (0.5.20190701)
|
|
53
53
|
unf (>= 0.0.5, < 1.0.0)
|
|
54
54
|
erubi (1.9.0)
|
|
55
|
-
ffi (1.
|
|
55
|
+
ffi (1.13.1)
|
|
56
56
|
hashdiff (1.0.0)
|
|
57
57
|
http-cookie (1.0.3)
|
|
58
58
|
domain_name (~> 0.5)
|
|
59
59
|
httparty (0.17.3)
|
|
60
60
|
mime-types (~> 3.0)
|
|
61
61
|
multi_xml (>= 0.5.2)
|
|
62
|
-
i18n (1.8.
|
|
62
|
+
i18n (1.8.5)
|
|
63
63
|
concurrent-ruby (~> 1.0)
|
|
64
64
|
jaro_winkler (1.5.3)
|
|
65
|
-
loofah (2.
|
|
65
|
+
loofah (2.7.0)
|
|
66
66
|
crass (~> 1.0.2)
|
|
67
67
|
nokogiri (>= 1.5.9)
|
|
68
68
|
method_source (0.9.2)
|
|
69
69
|
mime-types (3.3.1)
|
|
70
70
|
mime-types-data (~> 3.2015)
|
|
71
|
-
mime-types-data (3.
|
|
71
|
+
mime-types-data (3.2020.0512)
|
|
72
72
|
mini_portile2 (2.4.0)
|
|
73
|
-
minitest (5.14.
|
|
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.
|
|
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)
|
|
@@ -84,7 +84,7 @@ GEM
|
|
|
84
84
|
coderay (~> 1.1.0)
|
|
85
85
|
method_source (~> 0.9.0)
|
|
86
86
|
public_suffix (4.0.1)
|
|
87
|
-
rack (2.2.
|
|
87
|
+
rack (2.2.3)
|
|
88
88
|
rack-test (1.1.0)
|
|
89
89
|
rack (>= 1.0, < 3)
|
|
90
90
|
rails-dom-testing (2.0.3)
|
|
@@ -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.
|
|
96
|
-
actionpack (= 6.0.
|
|
97
|
-
activesupport (= 6.0.
|
|
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)
|
|
@@ -140,18 +140,18 @@ GEM
|
|
|
140
140
|
safe_yaml (1.0.5)
|
|
141
141
|
thor (1.0.1)
|
|
142
142
|
thread_safe (0.3.6)
|
|
143
|
-
tzinfo (1.2.
|
|
143
|
+
tzinfo (1.2.7)
|
|
144
144
|
thread_safe (~> 0.1)
|
|
145
145
|
unf (0.1.4)
|
|
146
146
|
unf_ext
|
|
147
|
-
unf_ext (0.0.7.
|
|
147
|
+
unf_ext (0.0.7.7)
|
|
148
148
|
unicode-display_width (1.6.0)
|
|
149
149
|
vcr (4.0.0)
|
|
150
150
|
webmock (3.7.6)
|
|
151
151
|
addressable (>= 2.3.6)
|
|
152
152
|
crack (>= 0.3.2)
|
|
153
153
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
154
|
-
zeitwerk (2.
|
|
154
|
+
zeitwerk (2.4.0)
|
|
155
155
|
|
|
156
156
|
PLATFORMS
|
|
157
157
|
ruby
|
data/README.md
CHANGED
|
@@ -27,7 +27,8 @@ need the tezos version (not Dune version)
|
|
|
27
27
|
[SmartPy](https://smartpy.io/)
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
sh <(curl -s https://
|
|
30
|
+
sh <(curl -s https://smartpy.io/dev-20200924-23b26494361d96abf034bdbb1ad1af396f95fd61/cli/SmartPy.sh) local-install-auto
|
|
31
|
+
export PATH=$PATH:$HOME/smartpy-cli/
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
### TypeScript (for dev)
|
data/lib/tezos_client.rb
CHANGED
|
@@ -36,6 +36,8 @@ require "tezos_client/smartpy_interface"
|
|
|
36
36
|
|
|
37
37
|
require "tezos_client/tools/convert_to_hash"
|
|
38
38
|
require "tezos_client/tools/find_big_maps_in_storage"
|
|
39
|
+
require "tezos_client/tools/hash_to_micheline"
|
|
40
|
+
require "tezos_client/tools/annots_to_type"
|
|
39
41
|
|
|
40
42
|
class TezosClient
|
|
41
43
|
using CurrencyUtils
|
|
@@ -163,14 +165,19 @@ class TezosClient
|
|
|
163
165
|
end
|
|
164
166
|
|
|
165
167
|
def call_contract(dry_run: false, entrypoint:, params:, params_type:, **args)
|
|
168
|
+
_entrypoint = select_entrypoint(
|
|
169
|
+
contract_address: args[:to],
|
|
170
|
+
entrypoint: entrypoint
|
|
171
|
+
)
|
|
172
|
+
|
|
166
173
|
json_params = micheline_params(
|
|
167
174
|
params: params,
|
|
168
|
-
entrypoint:
|
|
175
|
+
entrypoint: _entrypoint,
|
|
169
176
|
params_type: params_type
|
|
170
177
|
)
|
|
171
178
|
|
|
172
179
|
transfer_args = args.merge(
|
|
173
|
-
entrypoint:
|
|
180
|
+
entrypoint: _entrypoint,
|
|
174
181
|
parameters: json_params,
|
|
175
182
|
dry_run: dry_run
|
|
176
183
|
)
|
|
@@ -178,6 +185,18 @@ class TezosClient
|
|
|
178
185
|
transfer(transfer_args)
|
|
179
186
|
end
|
|
180
187
|
|
|
188
|
+
def select_entrypoint(contract_address:, entrypoint:)
|
|
189
|
+
entrypoints = entrypoints(contract_address)["entrypoints"].keys
|
|
190
|
+
|
|
191
|
+
if entrypoints.count == 0
|
|
192
|
+
"default"
|
|
193
|
+
elsif entrypoints.include?(entrypoint)
|
|
194
|
+
entrypoint
|
|
195
|
+
else
|
|
196
|
+
raise ::ArgumentError, "entrypoint #{entrypoint} not found in #{entrypoints}"
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
181
200
|
def inject_raw_operations(secret_key:, raw_operations:, dry_run: false, **args)
|
|
182
201
|
public_key = secret_key_to_public_key(secret_key)
|
|
183
202
|
from = public_key_to_address(public_key)
|
data/lib/tezos_client/crypto.rb
CHANGED
|
@@ -165,6 +165,22 @@ class TezosClient
|
|
|
165
165
|
end
|
|
166
166
|
end
|
|
167
167
|
|
|
168
|
+
# payload must be bytes
|
|
169
|
+
def check_signature(public_key:, signature:, payload:)
|
|
170
|
+
verify_key = RbNaCl::VerifyKey.new(decode_tz(public_key).to_bin)
|
|
171
|
+
|
|
172
|
+
bin_sig = decode_tz(signature).to_bin
|
|
173
|
+
payload_hash = RbNaCl::Hash::Blake2b.digest(ignore_0x(payload).to_bin, digest_size: 32)
|
|
174
|
+
|
|
175
|
+
verify_key.verify(bin_sig, payload_hash)
|
|
176
|
+
rescue RbNaCl::BadSignatureError
|
|
177
|
+
false
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def check_signature!(public_key:, signature:, payload:)
|
|
181
|
+
check_signature(public_key: public_key, signature: signature, payload: payload) || raise(BadSignatureError)
|
|
182
|
+
end
|
|
183
|
+
|
|
168
184
|
def operation_id(signed_operation_hex)
|
|
169
185
|
hash = RbNaCl::Hash::Blake2b.digest(
|
|
170
186
|
signed_operation_hex.to_bin,
|
|
@@ -220,5 +236,9 @@ class TezosClient
|
|
|
220
236
|
RbNaCl::SigningKey.generate
|
|
221
237
|
end
|
|
222
238
|
end
|
|
239
|
+
|
|
240
|
+
def ignore_0x(payload)
|
|
241
|
+
payload.starts_with?("0x") ? payload[2..-1] : payload
|
|
242
|
+
end
|
|
223
243
|
end
|
|
224
244
|
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
|
-
|
|
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
|
-
|
|
217
|
+
failed_operation_result = operation_results.detect do |operation_result|
|
|
218
|
+
operation_result[:status] == "failed"
|
|
219
|
+
end
|
|
217
220
|
|
|
218
|
-
|
|
219
|
-
operation_result[:status] == "failed"
|
|
221
|
+
failed!("failed", failed_operation_result[:errors], operation_results)
|
|
220
222
|
end
|
|
221
223
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class TezosClient::Tools::AnnotsToType < ActiveInteraction::Base
|
|
4
|
+
# example of typed_annots :
|
|
5
|
+
# {
|
|
6
|
+
# spending_ref: "string",
|
|
7
|
+
# remainder_amount: "nat",
|
|
8
|
+
# expires_at: "timestamp"
|
|
9
|
+
# }
|
|
10
|
+
hash :typed_annots, strip: false
|
|
11
|
+
|
|
12
|
+
validate :validate_types
|
|
13
|
+
|
|
14
|
+
def execute
|
|
15
|
+
return { "prim" => typed_annots.values.first } if typed_annots.size == 1
|
|
16
|
+
|
|
17
|
+
{ "prim" => "pair", "args" => generate_type_args(ordered_annots) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
def generate_type_args(annots)
|
|
22
|
+
annot = annots.pop
|
|
23
|
+
annot_type = typed_annots[annot]
|
|
24
|
+
|
|
25
|
+
unless annots.size == 1
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
"prim" => annot_type,
|
|
29
|
+
"annots" => ["%#{annot}"]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"prim" => "pair",
|
|
33
|
+
"args" => generate_type_args(annots)
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
generated_args = [{ "prim" => annot_type, "annots" => ["%#{annot}"] }]
|
|
39
|
+
annot = annots.pop
|
|
40
|
+
annot_type = typed_annots[annot]
|
|
41
|
+
generated_args.append({ "prim" => annot_type, "annots" => ["%#{annot}"] })
|
|
42
|
+
|
|
43
|
+
generated_args
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def ordered_annots
|
|
47
|
+
@ordered_annots ||= typed_annots.keys.sort.reverse
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def validate_types
|
|
51
|
+
allowed_types = TezosClient::Tools::HashToMicheline::TYPES_MAPPING.keys
|
|
52
|
+
return if typed_annots.values.map(&:to_sym).all? { |type| type.in? allowed_types }
|
|
53
|
+
|
|
54
|
+
errors.add(:base, "The allowed types are: #{allowed_types.join(', ')}")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class TezosClient
|
|
4
|
+
module Tools
|
|
5
|
+
class ConvertToHash < ActiveInteraction::Base
|
|
6
|
+
class Option < Base
|
|
7
|
+
def decode
|
|
8
|
+
if data[:prim] == "None"
|
|
9
|
+
return nil
|
|
10
|
+
elsif data[:prim] == "Some"
|
|
11
|
+
TezosClient::Tools::ConvertToHash::Base.new(
|
|
12
|
+
data: data[:args][0],
|
|
13
|
+
type: type[:args][0]
|
|
14
|
+
).value
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class TezosClient::Tools::HashToMicheline < ActiveInteraction::Base
|
|
4
|
+
# TODO: handle Arrays and Maps
|
|
5
|
+
TYPES_MAPPING = {
|
|
6
|
+
int: :int,
|
|
7
|
+
nat: :int,
|
|
8
|
+
string: :string,
|
|
9
|
+
signature: :string,
|
|
10
|
+
bytes: :bytes,
|
|
11
|
+
timestamp: :int,
|
|
12
|
+
key: :string,
|
|
13
|
+
address: :string
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
string :contract_address, default: nil
|
|
17
|
+
string :entrypoint, default: nil
|
|
18
|
+
# example of params:
|
|
19
|
+
# {
|
|
20
|
+
# spending_ref: "toto",
|
|
21
|
+
# expires_at: Time.now
|
|
22
|
+
# }
|
|
23
|
+
hash :params, strip: false
|
|
24
|
+
hash :storage_type, strip: false, default: {}
|
|
25
|
+
interface :blockchain_client, methods: %i[entrypoint entrypoints select_entrypoint], default: -> { TezosClient.new }
|
|
26
|
+
|
|
27
|
+
# if storage_type is not received, it is fetched from the blockchain using
|
|
28
|
+
# contract_address and entrypoint (that are mandatory in this case)
|
|
29
|
+
validate :storage_type_or_contract_address_presence
|
|
30
|
+
|
|
31
|
+
def execute
|
|
32
|
+
return hash_type_to_hash_data(_storage_type.fetch(:prim), params.values.first) if params.size == 1
|
|
33
|
+
|
|
34
|
+
{ prim: "Pair", args: generate_micheline(_storage_type[:args]) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
def generate_micheline(remaining_storage_type)
|
|
39
|
+
remaining_storage_type.each_with_object([]) do |h, acc|
|
|
40
|
+
next acc << { prim: "Pair", args: generate_micheline(h[:args]) } if h[:prim] == "pair"
|
|
41
|
+
|
|
42
|
+
annot = h[:annots].first.slice(1..-1).to_sym # remove '%'
|
|
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
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def convert_type(michelson_type)
|
|
65
|
+
TYPES_MAPPING.fetch(michelson_type.to_sym)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def hash_type_to_hash_data(michelson_type, value)
|
|
69
|
+
type = convert_type(michelson_type)
|
|
70
|
+
|
|
71
|
+
converted_value = case michelson_type.to_sym
|
|
72
|
+
when :nat, :int
|
|
73
|
+
value.to_s
|
|
74
|
+
when :timestamp
|
|
75
|
+
errors.add(:base, "timestamp input must be an instance of Time") unless value.is_a? Time
|
|
76
|
+
|
|
77
|
+
value.to_i.to_s
|
|
78
|
+
else
|
|
79
|
+
value
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
{ type => converted_value }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def _entrypoint
|
|
86
|
+
@_entrypoint ||= blockchain_client.select_entrypoint(
|
|
87
|
+
contract_address: contract_address,
|
|
88
|
+
entrypoint: entrypoint
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def _storage_type
|
|
93
|
+
(storage_type.presence || blockchain_client.entrypoint(contract_address, _entrypoint)).deep_symbolize_keys
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def storage_type_or_contract_address_presence
|
|
97
|
+
return if storage_type.present? ^ (contract_address.present?)
|
|
98
|
+
|
|
99
|
+
errors.add(:base,
|
|
100
|
+
"You should provide the contract_address and the entrypoint only if storage_type is not provided")
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -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
|
|
data/lib/tezos_client/version.rb
CHANGED
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
|
|
4
|
+
version: 1.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pierre Michard
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-09-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -274,6 +274,7 @@ files:
|
|
|
274
274
|
- lib/tezos_client/smartpy_inteface/smartpy_wrapper.rb
|
|
275
275
|
- lib/tezos_client/smartpy_interface.rb
|
|
276
276
|
- lib/tezos_client/string_utils.rb
|
|
277
|
+
- lib/tezos_client/tools/annots_to_type.rb
|
|
277
278
|
- lib/tezos_client/tools/convert_to_hash.rb
|
|
278
279
|
- lib/tezos_client/tools/convert_to_hash/address.rb
|
|
279
280
|
- lib/tezos_client/tools/convert_to_hash/base.rb
|
|
@@ -284,11 +285,13 @@ files:
|
|
|
284
285
|
- lib/tezos_client/tools/convert_to_hash/list.rb
|
|
285
286
|
- lib/tezos_client/tools/convert_to_hash/map.rb
|
|
286
287
|
- lib/tezos_client/tools/convert_to_hash/nat.rb
|
|
288
|
+
- lib/tezos_client/tools/convert_to_hash/option.rb
|
|
287
289
|
- lib/tezos_client/tools/convert_to_hash/pair.rb
|
|
288
290
|
- lib/tezos_client/tools/convert_to_hash/signature.rb
|
|
289
291
|
- lib/tezos_client/tools/convert_to_hash/string.rb
|
|
290
292
|
- lib/tezos_client/tools/convert_to_hash/timestamp.rb
|
|
291
293
|
- lib/tezos_client/tools/find_big_maps_in_storage.rb
|
|
294
|
+
- lib/tezos_client/tools/hash_to_micheline.rb
|
|
292
295
|
- lib/tezos_client/tools/system_call.rb
|
|
293
296
|
- lib/tezos_client/tools/temporary_file.rb
|
|
294
297
|
- lib/tezos_client/version.rb
|
|
@@ -299,7 +302,7 @@ licenses:
|
|
|
299
302
|
- MIT
|
|
300
303
|
metadata:
|
|
301
304
|
allowed_push_host: https://rubygems.org
|
|
302
|
-
post_install_message:
|
|
305
|
+
post_install_message:
|
|
303
306
|
rdoc_options: []
|
|
304
307
|
require_paths:
|
|
305
308
|
- lib
|
|
@@ -314,8 +317,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
314
317
|
- !ruby/object:Gem::Version
|
|
315
318
|
version: '0'
|
|
316
319
|
requirements: []
|
|
317
|
-
rubygems_version: 3.0.
|
|
318
|
-
signing_key:
|
|
320
|
+
rubygems_version: 3.0.8
|
|
321
|
+
signing_key:
|
|
319
322
|
specification_version: 4
|
|
320
323
|
summary: Wrapper to the tezos client.
|
|
321
324
|
test_files: []
|