tezos_client 1.0.0 → 1.0.1

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: 579469179cc4a5bb283d1bcf72b47ef45526cfa043b8e726c0f0fd28ce898660
4
- data.tar.gz: 96812ca579b2385498b1d6d77ec0402b971e0cd5404a14358d82afef38d9a155
3
+ metadata.gz: 014c9a05ae3cd9274cb1c05389dc09ba2b392d4696f473e2f46cc9f4937a28ee
4
+ data.tar.gz: a9b296c7d4e3eda79f7a4aabbea8754aa598a668b257a06ee883295c0697effb
5
5
  SHA512:
6
- metadata.gz: 2430302849c553bb54824fdb7f9f42f2370e382996217560895a4423fb7639d4ce3ed35bbeab04726385b156759ffff938912cb1d9d9c10f0a59fbc682e9e573
7
- data.tar.gz: 9e998064917d3163aa589ba96bf7dbbb06cee177192d9487d17d5d181141634b951fb2c3c0c39358abe911efc21b7c44e9bbefc670171f0b613c8417a71abeed
6
+ metadata.gz: 983b7ab275287b10d6f049e8ef70590c6379ff487da32a7edea2f7f7e775fac922028fba84b76174d393e976a13d56cd15be7521e6fd8bac7096b4408aac8f6f
7
+ data.tar.gz: 494b2b66f0f4e99ea176d01d526365841f17a27b156e03b98c5d76b441c4461cdc657db9843cb3fa84b605812d253ea3f3d166c06eb350a709e06de10ce77c7a
data/.travis.yml CHANGED
@@ -12,18 +12,18 @@ rvm:
12
12
  - 2.5.1
13
13
  before_install:
14
14
  - sh travis-scripts/prepare-ubuntu.sh
15
- - mkdir $HOME/bin
15
+ - mkdir -p $HOME/bin
16
16
  - docker pull moneytrack/liquidity:babylonnet
17
17
  - id=$(docker create moneytrack/liquidity:babylonnet)
18
18
  - docker cp $id:/home/opam/.opam/4.07/bin/liquidity - > $HOME/bin/liquidity
19
- - chmod +x liquidity
20
- - curl -s https://SmartPy.io/SmartPyBasicTest2/SmartPy.sh > SmartPy.sh
19
+ - chmod +x $HOME/bin/liquidity
20
+ - curl -s https://SmartPy.io/SmartPyBasic/SmartPy.sh > SmartPy.sh
21
21
  - chmod +x ./SmartPy.sh
22
- - ./SmartPy.sh local-install-custom SmartPyBasicTest2 $HOME/bin/smartpy
22
+ - ./SmartPy.sh local-install $HOME/bin/smartpy
23
23
  - rm ./SmartPy.sh
24
24
  - export PATH="$PATH:$HOME/bin/:$HOME/bin/smartpy/SmartPyBasic/"
25
25
  - npm link michelson-to-micheline
26
26
  - gem install bundler -v 1.16.3
27
27
  script:
28
28
  - bundle install
29
- - bundle exec rake
29
+ - bundle exec rspec --tag '~require_node'
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tezos_client (1.0.0)
4
+ tezos_client (1.0.1)
5
+ active_interaction (~> 3.7)
5
6
  activesupport (~> 6.0.0)
6
7
  base58 (~> 0.2.3)
7
8
  bip_mnemonic (~> 0.0.2)
@@ -26,6 +27,10 @@ GEM
26
27
  erubi (~> 1.4)
27
28
  rails-dom-testing (~> 2.0)
28
29
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
30
+ active_interaction (3.7.1)
31
+ activemodel (>= 4, < 7)
32
+ activemodel (6.0.0)
33
+ activesupport (= 6.0.0)
29
34
  activesupport (6.0.0)
30
35
  concurrent-ruby (~> 1.0, >= 1.0.2)
31
36
  i18n (>= 0.7, < 2)
@@ -47,7 +52,7 @@ GEM
47
52
  domain_name (0.5.20190701)
48
53
  unf (>= 0.0.5, < 1.0.0)
49
54
  erubi (1.9.0)
50
- ffi (1.12.1)
55
+ ffi (1.12.2)
51
56
  hashdiff (1.0.0)
52
57
  http-cookie (1.0.3)
53
58
  domain_name (~> 0.5)
data/lib/tezos_client.rb CHANGED
@@ -7,6 +7,8 @@ require "active_support/core_ext/module/delegation"
7
7
  require "timeout"
8
8
  require "benchmark"
9
9
  require "open3"
10
+ require "active_interaction"
11
+ require "time"
10
12
 
11
13
  require "tezos_client/version"
12
14
  require "tezos_client/string_utils"
@@ -33,6 +35,9 @@ require "tezos_client/rpc_interface"
33
35
  require "tezos_client/liquidity_interface"
34
36
  require "tezos_client/smartpy_interface"
35
37
 
38
+ require "tezos_client/tools/convert_to_hash"
39
+ require "tezos_client/tools/find_big_maps_in_storage"
40
+
36
41
  class TezosClient
37
42
  using CurrencyUtils
38
43
  using StringUtils
@@ -18,9 +18,11 @@ class TezosClient
18
18
  :balance,
19
19
  :contract_manager_key,
20
20
  :contract_storage,
21
+ :contract_detail,
21
22
  :pending_operations,
22
23
  :pack_data,
23
- :big_map_value
24
+ :big_map_value,
25
+ :list_big_map_by_contract
24
26
 
25
27
  def_delegators :liquidity_interface,
26
28
  :get_storage,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TezosClient
4
- class RpcRequestFailure < Exception
4
+ class RpcRequestFailure < StandardError
5
5
 
6
6
  attr_reader :status_code
7
7
  attr_reader :error
@@ -49,7 +49,7 @@ class TezosClient
49
49
  end
50
50
  end
51
51
 
52
- class OperationFailure < Exception
52
+ class OperationFailure < StandardError
53
53
  include Logger
54
54
 
55
55
  attr_reader :metadata
@@ -10,6 +10,10 @@ class TezosClient
10
10
  "/chains/main/blocks/head/context/contracts/#{contract_id}"
11
11
  end
12
12
 
13
+ def contract_detail(contract_id)
14
+ get contract_link(contract_id)
15
+ end
16
+
13
17
  def balance(contract_id)
14
18
  res = get("#{contract_link(contract_id)}/balance")
15
19
  res.to_i.from_satoshi
@@ -33,6 +37,17 @@ class TezosClient
33
37
 
34
38
  get "/chains/main/blocks/head/context/big_maps/#{big_map_id}/#{expr_key}"
35
39
  end
40
+
41
+ def list_big_map_by_contract(contract_address:)
42
+ contract_storage = contract_storage(contract_address)
43
+ contract = contract_detail(contract_address)
44
+ storage_type = contract[:script][:code].find { |elem| elem[:prim] == "storage" }[:args].first
45
+
46
+ TezosClient::Tools::FindBigMapsInStorage.run!(
47
+ storage: contract_storage,
48
+ storage_type: storage_type
49
+ )
50
+ end
36
51
  end
37
52
  end
38
53
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TezosClient::Tools::ConvertToHash < ActiveInteraction::Base
4
+ interface :data
5
+ interface :type
6
+
7
+ def execute
8
+
9
+ case type[:prim]
10
+ when "pair"
11
+ pair_type(data: data, type: type)
12
+ when "list"
13
+ list_type(data: data, type: type)
14
+ when "int"
15
+ int_type(data: data, type: type)
16
+ when "nat"
17
+ int_type(data: data, type: type)
18
+ when "key"
19
+ key_type(data: data, type: type)
20
+ when "timestamp"
21
+ timestamp_type(data: data, type: type)
22
+ when "string"
23
+ string_type(data: data, type: type)
24
+ when "address"
25
+ address_type(data: data, type: type)
26
+ else
27
+ raise "type '#{type[:prim]}' not implemented"
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def pair_type(data:, type:)
34
+ raise "Not a 'Pair' type" unless data[:prim] == "Pair"
35
+ raise "Difference detected between data and type \nDATA: #{data} \nTYPE:#{type} " unless data[:args].size == type[:args].size
36
+
37
+ result = {}
38
+ data[:args].size.times do |iter|
39
+ result.merge!(
40
+ compose(
41
+ TezosClient::Tools::ConvertToHash,
42
+ data: data[:args][iter],
43
+ type: type[:args][iter]
44
+ )
45
+ )
46
+ end
47
+ result
48
+ end
49
+
50
+ def list_type(data:, type:)
51
+ {
52
+ var_name(type) => convert_list_element(data: data, element_type: type[:args].first)
53
+ }
54
+ end
55
+
56
+ def convert_list_element(data:, element_type:)
57
+ data.map do |elem|
58
+ compose(
59
+ TezosClient::Tools::ConvertToHash,
60
+ data: elem,
61
+ type: element_type
62
+ )
63
+ end
64
+ end
65
+
66
+ def int_type(data:, type:)
67
+ { var_name(type) => data[:int].to_i }
68
+ end
69
+
70
+ def key_type(data:, type:)
71
+ { var_name(type) => data[:bytes] || data[:string] }
72
+ end
73
+
74
+ def timestamp_type(data:, type:)
75
+ { var_name(type) => Time.zone.at(data[:int].to_i) }
76
+ end
77
+
78
+ def string_type(data:, type:)
79
+ { var_name(type) => data[:string] }
80
+ end
81
+
82
+ def address_type(data:, type:)
83
+ { var_name(type) => data[:bytes] || data[:string] }
84
+ end
85
+
86
+ def var_name(type)
87
+ "#{type[:annots].first[1..-1]}".to_sym
88
+ end
89
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TezosClient::Tools::FindBigMapsInStorage < ActiveInteraction::Base
4
+ hash :storage,
5
+ strip: false
6
+ hash :storage_type,
7
+ strip: false
8
+
9
+ def execute
10
+ case storage_type[:prim]
11
+ when "pair"
12
+ pair_type(data: storage, type: storage_type)
13
+ when "list"
14
+ list_type(data: storage, type: storage_type)
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
31
+ end
32
+
33
+ def list_type(data:, type:)
34
+ element_type = type[:args].first
35
+ data.map do |elem|
36
+ compose(
37
+ TezosClient::Tools::ConvertToHash,
38
+ data: elem,
39
+ type: element_type
40
+ )
41
+ end
42
+ end
43
+
44
+ def big_map_type(data:, type:)
45
+ {
46
+ name: var_name(type),
47
+ id: data[:int],
48
+ type_value: type[:args].second,
49
+ type_key: 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
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TezosClient
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
data/tezos_client.gemspec CHANGED
@@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency "vcr", "~> 4.0.0"
42
42
  spec.add_development_dependency "pry"
43
43
 
44
+ spec.add_dependency "active_interaction", "~> 3.7"
44
45
  spec.add_dependency "base58", "~> 0.2.3"
45
46
  spec.add_dependency "httparty", "~> 0.17.0"
46
47
  spec.add_dependency "rbnacl", "~> 5.0.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: 1.0.0
4
+ version: 1.0.1
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-02-04 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: active_interaction
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.7'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.7'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: base58
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -262,6 +276,8 @@ files:
262
276
  - lib/tezos_client/smartpy_inteface/smartpy_wrapper.rb
263
277
  - lib/tezos_client/smartpy_interface.rb
264
278
  - lib/tezos_client/string_utils.rb
279
+ - lib/tezos_client/tools/convert_to_hash.rb
280
+ - lib/tezos_client/tools/find_big_maps_in_storage.rb
265
281
  - lib/tezos_client/tools/system_call.rb
266
282
  - lib/tezos_client/tools/temporary_file.rb
267
283
  - lib/tezos_client/version.rb
@@ -287,8 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
303
  - !ruby/object:Gem::Version
288
304
  version: '0'
289
305
  requirements: []
290
- rubyforge_project:
291
- rubygems_version: 2.7.6
306
+ rubygems_version: 3.0.6
292
307
  signing_key:
293
308
  specification_version: 4
294
309
  summary: Wrapper to the tezos client.