tezos_client 1.2.1 → 1.2.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/Gemfile.lock +22 -22
- data/lib/tezos_client.rb +2 -0
- data/lib/tezos_client/tools/annots_to_type.rb +48 -0
- data/lib/tezos_client/tools/hash_to_micheline.rb +78 -0
- data/lib/tezos_client/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1459f7dd534e408bd13520b14789b9f719a6cec9b004f5ab3ca00c151da1ac4
|
|
4
|
+
data.tar.gz: 2aa7c36fc10c82537de03593e592703274daedcff36edec84130c98cc385098f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa9dc95f337c4bbbda410392c03d6305c93ee8f4dfec1810f629c0143a4beb3ce88789f5c4eaa809ae572bb4871ad44b0e87d35071727f9800cc9167f290492f
|
|
7
|
+
data.tar.gz: e625840ea65befc0adc6ece5e334d8e869daabbaa2e6a9fc51881dda0ba3971dcec2f0d3274968e07a7e9268e1af93469c1f70f1395fa3d773119e871ab55f2a
|
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.2.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.2)
|
|
18
|
+
actionview (= 6.0.3.2)
|
|
19
|
+
activesupport (= 6.0.3.2)
|
|
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.2)
|
|
25
|
+
activesupport (= 6.0.3.2)
|
|
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.2)
|
|
31
31
|
activemodel (>= 4, < 7)
|
|
32
|
-
activemodel (6.0.
|
|
33
|
-
activesupport (= 6.0.
|
|
34
|
-
activesupport (6.0.
|
|
32
|
+
activemodel (6.0.3.2)
|
|
33
|
+
activesupport (= 6.0.3.2)
|
|
34
|
+
activesupport (6.0.3.2)
|
|
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)
|
|
@@ -52,25 +52,25 @@ 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.3)
|
|
63
63
|
concurrent-ruby (~> 1.0)
|
|
64
64
|
jaro_winkler (1.5.3)
|
|
65
|
-
loofah (2.
|
|
65
|
+
loofah (2.6.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.1)
|
|
74
74
|
money-tree (0.10.0)
|
|
75
75
|
ffi
|
|
76
76
|
multi_xml (0.6.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.2)
|
|
96
|
+
actionpack (= 6.0.3.2)
|
|
97
|
+
activesupport (= 6.0.3.2)
|
|
98
98
|
method_source
|
|
99
99
|
rake (>= 0.8.7)
|
|
100
100
|
thor (>= 0.20.3, < 2.0)
|
|
@@ -140,11 +140,11 @@ 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)
|
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
|
|
@@ -0,0 +1,48 @@
|
|
|
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 [{ "prim" => "pair", "args" => generate_type_args(annots) },
|
|
27
|
+
{ "prim" => annot_type, "annots" => ["%#{annot}"] }]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
generated_args = [{ "prim" => annot_type, "annots" => ["%#{annot}"] }]
|
|
31
|
+
annot = annots.pop
|
|
32
|
+
annot_type = typed_annots[annot]
|
|
33
|
+
generated_args.unshift({ "prim" => annot_type, "annots" => ["%#{annot}"] })
|
|
34
|
+
|
|
35
|
+
generated_args
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def ordered_annots
|
|
39
|
+
@ordered_annots ||= typed_annots.keys.sort
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def validate_types
|
|
43
|
+
allowed_types = TezosClient::Tools::HashToMicheline::TYPES_MAPPING.keys
|
|
44
|
+
return if typed_annots.values.map(&:to_sym).all? { |type| type.in? allowed_types }
|
|
45
|
+
|
|
46
|
+
errors.add(:base, "The allowed types are: #{allowed_types.join(', ')}")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
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: [: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
|
+
acc << hash_type_to_hash_data(h[:prim], params.fetch(annot))
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def convert_type(michelson_type)
|
|
48
|
+
TYPES_MAPPING.fetch(michelson_type.to_sym)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def hash_type_to_hash_data(michelson_type, value)
|
|
52
|
+
type = convert_type(michelson_type)
|
|
53
|
+
|
|
54
|
+
converted_value = case michelson_type.to_sym
|
|
55
|
+
when :nat, :int
|
|
56
|
+
value.to_s
|
|
57
|
+
when :timestamp
|
|
58
|
+
errors.add(:base, "timestamp input must be an instance of Time") unless value.is_a? Time
|
|
59
|
+
|
|
60
|
+
value.to_i.to_s
|
|
61
|
+
else
|
|
62
|
+
value
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
{ type => converted_value }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def _storage_type
|
|
69
|
+
(storage_type.presence || blockchain_client.entrypoint(contract_address, entrypoint)).deep_symbolize_keys
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def storage_type_or_contract_address_presence
|
|
73
|
+
return if storage_type.present? ^ (contract_address.present? && entrypoint.present?)
|
|
74
|
+
|
|
75
|
+
errors.add(:base,
|
|
76
|
+
"You should provide the contract_address and the entrypoint only if storage_type is not provided")
|
|
77
|
+
end
|
|
78
|
+
end
|
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.2.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-07-15 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
|
|
@@ -289,6 +290,7 @@ files:
|
|
|
289
290
|
- lib/tezos_client/tools/convert_to_hash/string.rb
|
|
290
291
|
- lib/tezos_client/tools/convert_to_hash/timestamp.rb
|
|
291
292
|
- lib/tezos_client/tools/find_big_maps_in_storage.rb
|
|
293
|
+
- lib/tezos_client/tools/hash_to_micheline.rb
|
|
292
294
|
- lib/tezos_client/tools/system_call.rb
|
|
293
295
|
- lib/tezos_client/tools/temporary_file.rb
|
|
294
296
|
- lib/tezos_client/version.rb
|
|
@@ -299,7 +301,7 @@ licenses:
|
|
|
299
301
|
- MIT
|
|
300
302
|
metadata:
|
|
301
303
|
allowed_push_host: https://rubygems.org
|
|
302
|
-
post_install_message:
|
|
304
|
+
post_install_message:
|
|
303
305
|
rdoc_options: []
|
|
304
306
|
require_paths:
|
|
305
307
|
- lib
|
|
@@ -314,8 +316,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
314
316
|
- !ruby/object:Gem::Version
|
|
315
317
|
version: '0'
|
|
316
318
|
requirements: []
|
|
317
|
-
rubygems_version: 3.0.
|
|
318
|
-
signing_key:
|
|
319
|
+
rubygems_version: 3.0.4
|
|
320
|
+
signing_key:
|
|
319
321
|
specification_version: 4
|
|
320
322
|
summary: Wrapper to the tezos client.
|
|
321
323
|
test_files: []
|