tezos_client 1.1.4 → 1.2.0
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 +1 -1
- data/lib/tezos_client/commands.rb +4 -1
- data/lib/tezos_client/rpc_interface/contracts.rb +11 -3
- data/lib/tezos_client/tools/convert_to_hash.rb +10 -90
- data/lib/tezos_client/tools/convert_to_hash/address.rb +29 -0
- data/lib/tezos_client/tools/convert_to_hash/base.rb +50 -0
- data/lib/tezos_client/tools/convert_to_hash/big_map.rb +20 -0
- data/lib/tezos_client/tools/convert_to_hash/bytes.rb +13 -0
- data/lib/tezos_client/tools/convert_to_hash/int.rb +13 -0
- data/lib/tezos_client/tools/convert_to_hash/key.rb +27 -0
- data/lib/tezos_client/tools/convert_to_hash/list.rb +22 -0
- data/lib/tezos_client/tools/convert_to_hash/nat.rb +13 -0
- data/lib/tezos_client/tools/convert_to_hash/pair.rb +21 -0
- data/lib/tezos_client/tools/convert_to_hash/signature.rb +19 -0
- data/lib/tezos_client/tools/convert_to_hash/string.rb +13 -0
- data/lib/tezos_client/tools/convert_to_hash/timestamp.rb +13 -0
- data/lib/tezos_client/tools/find_big_maps_in_storage.rb +9 -40
- data/lib/tezos_client/version.rb +1 -1
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b34f7593bef70d5be1219dd4beba9e00f6114da81783148585312cd32eeb82e8
|
4
|
+
data.tar.gz: 862385f6e2fbf82ac12ab9ce912939b9a9499a10a856d447da5d9878afc08ce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf5f33ee51bc2a45edaed55c67bfa7d58addbcc5668eb87198765cdfd50e387bda96769ef238f63011c78e66f802efc89ef293cdd2fb57d9f50de8e0ad2fa45
|
7
|
+
data.tar.gz: 83682fe26418295979576a1a88d66d5b1af082ca2e4195b47286ccaf1a1cc3c24470a4b5ded42b0062bf17d97ad9ded3d5e1768f645c2985c9c683f9395b5c80
|
data/Gemfile.lock
CHANGED
@@ -28,20 +28,28 @@ class TezosClient
|
|
28
28
|
get "#{contract_link(contract_id)}/manager_key"
|
29
29
|
end
|
30
30
|
|
31
|
+
def contract_storage_type(contract_id)
|
32
|
+
contract = contract_detail(contract_id)
|
33
|
+
contract[:script][:code].find { |elem| elem[:prim] == "storage" }[:args].first
|
34
|
+
end
|
35
|
+
|
31
36
|
def contract_storage(contract_id)
|
32
37
|
get "#{contract_link(contract_id)}/storage"
|
33
38
|
end
|
34
39
|
|
40
|
+
def entrypoint(contract_id, entrypoint)
|
41
|
+
get("#{contract_link(contract_id)}/entrypoints/#{entrypoint}")
|
42
|
+
end
|
43
|
+
|
35
44
|
def big_map_value(big_map_id:, key:, key_type:)
|
36
45
|
expr_key = encode_script_expr(data: key, type: key_type)
|
37
46
|
|
38
47
|
get "/chains/main/blocks/head/context/big_maps/#{big_map_id}/#{expr_key}"
|
39
48
|
end
|
40
49
|
|
41
|
-
def
|
50
|
+
def contract_big_maps(contract_address)
|
42
51
|
contract_storage = contract_storage(contract_address)
|
43
|
-
|
44
|
-
storage_type = contract[:script][:code].find { |elem| elem[:prim] == "storage" }[:args].first
|
52
|
+
storage_type = contract_storage_type(contract_address)
|
45
53
|
|
46
54
|
TezosClient::Tools::FindBigMapsInStorage.run!(
|
47
55
|
storage: contract_storage,
|
@@ -1,99 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
interface :data
|
5
|
-
interface :type
|
3
|
+
require_relative "convert_to_hash/base"
|
6
4
|
|
7
|
-
|
8
|
-
decorated_value
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
def value
|
13
|
-
case type[:prim]
|
14
|
-
when "pair"
|
15
|
-
pair_type
|
16
|
-
when "list"
|
17
|
-
list_type
|
18
|
-
when "int"
|
19
|
-
int_type
|
20
|
-
when "nat"
|
21
|
-
int_type
|
22
|
-
when "key"
|
23
|
-
key_type
|
24
|
-
when "timestamp"
|
25
|
-
timestamp_type
|
26
|
-
when "string"
|
27
|
-
string_type
|
28
|
-
when "address"
|
29
|
-
address_type
|
30
|
-
else
|
31
|
-
raise "type '#{type[:prim]}' not implemented"
|
32
|
-
end
|
33
|
-
end
|
5
|
+
Dir[File.join(__dir__, "convert_to_hash", "*.rb")].each { |file| require file }
|
34
6
|
|
35
|
-
|
36
|
-
|
37
|
-
|
7
|
+
class TezosClient
|
8
|
+
module Tools
|
9
|
+
class ConvertToHash < ActiveInteraction::Base
|
10
|
+
interface :data
|
11
|
+
interface :type
|
38
12
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
data: data_n,
|
43
|
-
type: type_n
|
44
|
-
)
|
45
|
-
end.reduce({}, &:merge)
|
46
|
-
end
|
47
|
-
|
48
|
-
def list_type
|
49
|
-
convert_list_element(data: data, element_type: type[:args].first)
|
50
|
-
end
|
13
|
+
def execute
|
14
|
+
TezosClient::Tools::ConvertToHash::Base.new(data: data, type: type).value
|
15
|
+
end
|
51
16
|
|
52
|
-
def convert_list_element(data:, element_type:)
|
53
|
-
data.map do |elem|
|
54
|
-
compose(
|
55
|
-
TezosClient::Tools::ConvertToHash,
|
56
|
-
data: elem,
|
57
|
-
type: element_type
|
58
|
-
)
|
59
17
|
end
|
60
18
|
end
|
61
|
-
|
62
|
-
def int_type
|
63
|
-
data[:int].to_i
|
64
|
-
end
|
65
|
-
|
66
|
-
def key_type
|
67
|
-
data[:bytes] || data[:string]
|
68
|
-
end
|
69
|
-
|
70
|
-
def timestamp_type
|
71
|
-
Time.zone.at(data[:int].to_i)
|
72
|
-
end
|
73
|
-
|
74
|
-
def string_type
|
75
|
-
data[:string]
|
76
|
-
end
|
77
|
-
|
78
|
-
def address_type
|
79
|
-
data[:bytes] || data[:string]
|
80
|
-
end
|
81
|
-
|
82
|
-
def decorated_value
|
83
|
-
anonymous? ? value : { var_name => value }
|
84
|
-
end
|
85
|
-
|
86
|
-
def anonymous?
|
87
|
-
!(type.key?(:annots) && type[:annots].any?)
|
88
|
-
end
|
89
|
-
|
90
|
-
def var_name_annot
|
91
|
-
type[:annots].first
|
92
|
-
end
|
93
|
-
|
94
|
-
def var_name
|
95
|
-
return nil if anonymous?
|
96
|
-
|
97
|
-
"#{var_name_annot[1..-1]}".to_sym
|
98
|
-
end
|
99
19
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
module Tools
|
5
|
+
class ConvertToHash < ActiveInteraction::Base
|
6
|
+
class Address < Base
|
7
|
+
include TezosClient::Crypto
|
8
|
+
|
9
|
+
def decode
|
10
|
+
if data.key?(:bytes)
|
11
|
+
if data[:bytes].start_with?("0000")
|
12
|
+
encode_tz(:tz1, data[:bytes][4..-1])
|
13
|
+
elsif data[:bytes].start_with?("0001")
|
14
|
+
encode_tz(:tz2, data[:bytes][4..-1])
|
15
|
+
elsif data[:bytes].start_with?("0002")
|
16
|
+
encode_tz(:tz3, data[:bytes][4..-1])
|
17
|
+
elsif data[:bytes].start_with?("01")
|
18
|
+
encode_tz(:KT, data[:bytes][2..-3])
|
19
|
+
else
|
20
|
+
data[:bytes]
|
21
|
+
end
|
22
|
+
else
|
23
|
+
data[:string]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
module Tools
|
5
|
+
class ConvertToHash < ActiveInteraction::Base
|
6
|
+
|
7
|
+
class Base
|
8
|
+
def initialize(data:, type:)
|
9
|
+
@data = data
|
10
|
+
@type = type
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :data, :type
|
14
|
+
|
15
|
+
def value
|
16
|
+
anonymous? ? decode : { var_name => decode }
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def decode
|
22
|
+
klass.new(data: data, type: type).decode
|
23
|
+
|
24
|
+
rescue NameError
|
25
|
+
raise NotImplementedError, "type '#{type[:prim]}' not implemented"
|
26
|
+
end
|
27
|
+
|
28
|
+
def anonymous?
|
29
|
+
!(type.key?(:annots) && type[:annots].any?)
|
30
|
+
end
|
31
|
+
|
32
|
+
def var_name_annot
|
33
|
+
type[:annots].first
|
34
|
+
end
|
35
|
+
|
36
|
+
def var_name
|
37
|
+
return nil if anonymous?
|
38
|
+
|
39
|
+
"#{var_name_annot[1..-1]}".to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def klass
|
45
|
+
"TezosClient::Tools::ConvertToHash::#{type[:prim].camelize}".constantize
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
class BigMap < Struct.new(:name, :id, :value_type, :key_type); end
|
5
|
+
|
6
|
+
module Tools
|
7
|
+
class ConvertToHash < ActiveInteraction::Base
|
8
|
+
class BigMap < Base
|
9
|
+
def decode
|
10
|
+
::TezosClient::BigMap.new(
|
11
|
+
var_name,
|
12
|
+
data[:int],
|
13
|
+
type[:args].second,
|
14
|
+
type[:args].first
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
module Tools
|
5
|
+
class ConvertToHash < ActiveInteraction::Base
|
6
|
+
class Key < Base
|
7
|
+
include TezosClient::Crypto
|
8
|
+
|
9
|
+
def decode
|
10
|
+
if data.key?(:bytes)
|
11
|
+
if data[:bytes].start_with?("00")
|
12
|
+
encode_tz(:edpk, data[:bytes][2..-1])
|
13
|
+
elsif data[:bytes].start_with?("01")
|
14
|
+
encode_tz(:sppk, data[:bytes][2..-1])
|
15
|
+
elsif data[:bytes].start_with?("02")
|
16
|
+
encode_tz(:p2pk, data[:bytes][2..-1])
|
17
|
+
else
|
18
|
+
data[:bytes]
|
19
|
+
end
|
20
|
+
else
|
21
|
+
data[:string]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
module Tools
|
5
|
+
class ConvertToHash < ActiveInteraction::Base
|
6
|
+
class List < Base
|
7
|
+
def decode
|
8
|
+
data.map do |elem|
|
9
|
+
TezosClient::Tools::ConvertToHash::Base.new(
|
10
|
+
data: elem,
|
11
|
+
type: elem_type
|
12
|
+
).value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def elem_type
|
17
|
+
type[:args].first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
module Tools
|
5
|
+
class ConvertToHash < ActiveInteraction::Base
|
6
|
+
class Pair < Base
|
7
|
+
def decode
|
8
|
+
raise "Not a 'Pair' type" unless data[:prim] == "Pair"
|
9
|
+
raise "Difference detected between data and type \nDATA: #{data} \nTYPE:#{type} " unless data[:args].size == type[:args].size
|
10
|
+
|
11
|
+
(data[:args]).zip(type[:args]).map do |data_n, type_n|
|
12
|
+
TezosClient::Tools::ConvertToHash::Base.new(
|
13
|
+
data: data_n,
|
14
|
+
type: type_n
|
15
|
+
).value
|
16
|
+
end.reduce({}, &:merge)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
module Tools
|
5
|
+
class ConvertToHash < ActiveInteraction::Base
|
6
|
+
class Signature < Base
|
7
|
+
include TezosClient::Crypto
|
8
|
+
|
9
|
+
def decode
|
10
|
+
if data.key?(:bytes)
|
11
|
+
encode_tz(:edsig, data[:bytes])
|
12
|
+
else
|
13
|
+
data[:string]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -7,50 +7,19 @@ class TezosClient::Tools::FindBigMapsInStorage < ActiveInteraction::Base
|
|
7
7
|
strip: false
|
8
8
|
|
9
9
|
def execute
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
when "big_map"
|
16
|
-
big_map_type(data: storage, type: storage_type)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def pair_type(data:, type:)
|
21
|
-
raise "Not a 'Pair' type" unless data[:prim] == "Pair"
|
22
|
-
raise "Difference detected between data and type \nDATA: #{data} \nTYPE:#{type} " unless data[:args].size == type[:args].size
|
23
|
-
|
24
|
-
(0 .. data[:args].size - 1).map do |iter|
|
25
|
-
compose(
|
26
|
-
TezosClient::Tools::FindBigMapsInStorage,
|
27
|
-
storage: data[:args][iter],
|
28
|
-
storage_type: type[:args][iter]
|
29
|
-
)
|
30
|
-
end.compact.flatten
|
10
|
+
hash_storage
|
11
|
+
.map(&:last)
|
12
|
+
.select { |value| value.is_a? TezosClient::BigMap }
|
13
|
+
.map(&:to_h)
|
14
|
+
.map(&:with_indifferent_access)
|
31
15
|
end
|
32
16
|
|
33
|
-
|
34
|
-
|
35
|
-
data.map do |elem|
|
17
|
+
private
|
18
|
+
def hash_storage
|
36
19
|
compose(
|
37
20
|
TezosClient::Tools::ConvertToHash,
|
38
|
-
data:
|
39
|
-
type:
|
21
|
+
data: storage,
|
22
|
+
type: storage_type
|
40
23
|
)
|
41
24
|
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def big_map_type(data:, type:)
|
45
|
-
{
|
46
|
-
name: var_name(type),
|
47
|
-
id: data[:int],
|
48
|
-
value_type: type[:args].second,
|
49
|
-
key_type: type[:args].first
|
50
|
-
}.with_indifferent_access
|
51
|
-
end
|
52
|
-
|
53
|
-
def var_name(type)
|
54
|
-
"#{type[:annots].first[1..-1]}".to_sym
|
55
|
-
end
|
56
25
|
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.
|
4
|
+
version: 1.2.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-03-
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -275,6 +275,18 @@ files:
|
|
275
275
|
- lib/tezos_client/smartpy_interface.rb
|
276
276
|
- lib/tezos_client/string_utils.rb
|
277
277
|
- lib/tezos_client/tools/convert_to_hash.rb
|
278
|
+
- lib/tezos_client/tools/convert_to_hash/address.rb
|
279
|
+
- lib/tezos_client/tools/convert_to_hash/base.rb
|
280
|
+
- lib/tezos_client/tools/convert_to_hash/big_map.rb
|
281
|
+
- lib/tezos_client/tools/convert_to_hash/bytes.rb
|
282
|
+
- lib/tezos_client/tools/convert_to_hash/int.rb
|
283
|
+
- lib/tezos_client/tools/convert_to_hash/key.rb
|
284
|
+
- lib/tezos_client/tools/convert_to_hash/list.rb
|
285
|
+
- lib/tezos_client/tools/convert_to_hash/nat.rb
|
286
|
+
- lib/tezos_client/tools/convert_to_hash/pair.rb
|
287
|
+
- lib/tezos_client/tools/convert_to_hash/signature.rb
|
288
|
+
- lib/tezos_client/tools/convert_to_hash/string.rb
|
289
|
+
- lib/tezos_client/tools/convert_to_hash/timestamp.rb
|
278
290
|
- lib/tezos_client/tools/find_big_maps_in_storage.rb
|
279
291
|
- lib/tezos_client/tools/system_call.rb
|
280
292
|
- lib/tezos_client/tools/temporary_file.rb
|
@@ -301,7 +313,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
301
313
|
- !ruby/object:Gem::Version
|
302
314
|
version: '0'
|
303
315
|
requirements: []
|
304
|
-
|
316
|
+
rubyforge_project:
|
317
|
+
rubygems_version: 2.7.6
|
305
318
|
signing_key:
|
306
319
|
specification_version: 4
|
307
320
|
summary: Wrapper to the tezos client.
|