tezos_client 1.0.1 → 1.1.1
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/.travis.yml +0 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -25
- data/lib/tezos_client/commands.rb +0 -4
- data/lib/tezos_client/exceptions.rb +0 -4
- data/lib/tezos_client/logger.rb +1 -0
- data/lib/tezos_client/operation_mgr.rb +26 -25
- data/lib/tezos_client/operations/activate_account_operation.rb +3 -2
- data/lib/tezos_client/operations/operation.rb +17 -16
- data/lib/tezos_client/operations/operation_array.rb +6 -7
- data/lib/tezos_client/operations/origination_operation.rb +3 -1
- data/lib/tezos_client/operations/raw_operation_array.rb +4 -3
- data/lib/tezos_client/operations/reveal_operation.rb +3 -1
- data/lib/tezos_client/operations/transaction_operation.rb +29 -28
- data/lib/tezos_client/operations/transactions_operation.rb +4 -3
- data/lib/tezos_client/rpc_interface/contracts.rb +2 -2
- data/lib/tezos_client/rpc_interface/request_manager.rb +40 -41
- data/lib/tezos_client/smartpy_inteface/micheline_serializer_wrapper.rb +1 -1
- data/lib/tezos_client/smartpy_interface.rb +10 -11
- data/lib/tezos_client/tools/convert_to_hash.rb +43 -45
- data/lib/tezos_client/tools/find_big_maps_in_storage.rb +3 -3
- data/lib/tezos_client/tools/system_call.rb +3 -1
- data/lib/tezos_client/tools/temporary_file.rb +4 -2
- data/lib/tezos_client/version.rb +1 -1
- data/lib/tezos_client.rb +34 -63
- metadata +4 -5
- data/lib/tezos_client/liquidity_inteface/liquidity_wrapper.rb +0 -24
- data/lib/tezos_client/liquidity_interface.rb +0 -120
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6de17ecf9250b846d61ac7c09163ae7d724bbf2cef921accfb363c17642d09bd
|
4
|
+
data.tar.gz: eceb944bc3de48585b37adb47d9004193b3b96b6803071ccb543c969d8d11888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af341ffed833a6f8683653b96f8a3cbc0b9397e7b5d56e734a6a528f96904c2ec45d252bd05be6ea8f009a54b55cc7d758784006c99c393ac3d4871913aeede9
|
7
|
+
data.tar.gz: 4a0ae7f0d075caace39047dcc9a012811484a0569a86223a508e8bb8fbbad578456bea5852c3243ff1b99ec4fdbc847abefd8dddaa24d3dd5e6490fb1e44323a
|
data/.travis.yml
CHANGED
@@ -13,10 +13,6 @@ rvm:
|
|
13
13
|
before_install:
|
14
14
|
- sh travis-scripts/prepare-ubuntu.sh
|
15
15
|
- mkdir -p $HOME/bin
|
16
|
-
- docker pull moneytrack/liquidity:babylonnet
|
17
|
-
- id=$(docker create moneytrack/liquidity:babylonnet)
|
18
|
-
- docker cp $id:/home/opam/.opam/4.07/bin/liquidity - > $HOME/bin/liquidity
|
19
|
-
- chmod +x $HOME/bin/liquidity
|
20
16
|
- curl -s https://SmartPy.io/SmartPyBasic/SmartPy.sh > SmartPy.sh
|
21
17
|
- chmod +x ./SmartPy.sh
|
22
18
|
- ./SmartPy.sh local-install $HOME/bin/smartpy
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tezos_client (1.
|
4
|
+
tezos_client (1.1.1)
|
5
5
|
active_interaction (~> 3.7)
|
6
6
|
activesupport (~> 6.0.0)
|
7
7
|
base58 (~> 0.2.3)
|
@@ -75,7 +75,7 @@ GEM
|
|
75
75
|
ffi
|
76
76
|
multi_xml (0.6.0)
|
77
77
|
netrc (0.11.0)
|
78
|
-
nokogiri (1.10.
|
78
|
+
nokogiri (1.10.8)
|
79
79
|
mini_portile2 (~> 2.4.0)
|
80
80
|
parallel (1.18.0)
|
81
81
|
parser (2.6.5.0)
|
data/README.md
CHANGED
@@ -120,11 +120,11 @@ client.transfer(
|
|
120
120
|
### Originate a contract written in liquidity
|
121
121
|
|
122
122
|
```ruby
|
123
|
-
script = File.expand_path("./spec/fixtures/demo.
|
123
|
+
script = File.expand_path("./spec/fixtures/demo.py")
|
124
124
|
source = "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq"
|
125
125
|
secret_key = "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN"
|
126
126
|
amount = 0
|
127
|
-
init_params
|
127
|
+
init_params= "MyContract()"
|
128
128
|
client = TezosClient.new
|
129
129
|
|
130
130
|
res = client.originate_contract(
|
@@ -139,20 +139,6 @@ puts "Origination operation: #{res[:operation_id]}"
|
|
139
139
|
puts "Contract address: #{res[:originated_contract]}"
|
140
140
|
```
|
141
141
|
|
142
|
-
### Call a contract written in liquidity
|
143
|
-
```ruby
|
144
|
-
TezosClient.new.call_contract(
|
145
|
-
from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
|
146
|
-
amount: 0,
|
147
|
-
script: File.expand_path("./spec/fixtures/demo.liq"),
|
148
|
-
secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN",
|
149
|
-
to: "KT1STzq9p2tfW3K4RdoM9iYd1htJ4QcJ8Njs",
|
150
|
-
entrypoint: "manage",
|
151
|
-
params: "(Some { destination = tz1YLtLqD1fWHthSVHPD116oYvsd4PTAHUoc; amount = 1tz })" ,
|
152
|
-
params_type: :caml
|
153
|
-
)
|
154
|
-
```
|
155
|
-
|
156
142
|
### Originate a contract written in SmartPy
|
157
143
|
|
158
144
|
```ruby
|
@@ -191,15 +177,6 @@ TezosClient.new.call_contract(
|
|
191
177
|
|
192
178
|
## Options
|
193
179
|
|
194
|
-
### Liquidity options
|
195
|
-
|
196
|
-
`TezosClient.new(..., liquidity_options: { options... })`
|
197
|
-
|
198
|
-
Available options :
|
199
|
-
|
200
|
-
* verbose (boolean) : enable verbose mode of Liquidity commands.
|
201
|
-
|
202
|
-
|
203
180
|
## Development
|
204
181
|
|
205
182
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
class TezosClient
|
4
4
|
class RpcRequestFailure < StandardError
|
5
|
-
|
6
5
|
attr_reader :status_code
|
7
6
|
attr_reader :error
|
8
7
|
|
@@ -21,9 +20,6 @@ class TezosClient
|
|
21
20
|
class SysCallError < RuntimeError
|
22
21
|
end
|
23
22
|
|
24
|
-
class LiquidityError < SysCallError
|
25
|
-
end
|
26
|
-
|
27
23
|
class SmartPyError < SysCallError
|
28
24
|
end
|
29
25
|
|
data/lib/tezos_client/logger.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "tezos_client/compute_operation_args_counters"
|
2
4
|
|
3
5
|
class TezosClient
|
@@ -199,38 +201,37 @@ class TezosClient
|
|
199
201
|
end
|
200
202
|
|
201
203
|
private
|
204
|
+
def ensure_applied!(rpc_responses)
|
205
|
+
metadatas = rpc_responses.map { |response| response[:metadata] }
|
206
|
+
operation_results = metadatas.map { |metadata| metadata[:operation_result] }
|
202
207
|
|
203
|
-
|
204
|
-
|
205
|
-
|
208
|
+
failed = operation_results.detect do |operation_result|
|
209
|
+
operation_result != nil && operation_result[:status] != "applied"
|
210
|
+
end
|
206
211
|
|
207
|
-
|
208
|
-
operation_result != nil && operation_result[:status] != "applied"
|
209
|
-
end
|
212
|
+
return metadatas if failed.nil?
|
210
213
|
|
211
|
-
|
214
|
+
failed_operation_result = operation_results.detect do |operation_result|
|
215
|
+
operation_result[:status] == "failed"
|
216
|
+
end
|
212
217
|
|
213
|
-
|
214
|
-
operation_result[:status] == "failed"
|
218
|
+
failed!("failed", failed_operation_result[:errors], operation_results)
|
215
219
|
end
|
216
220
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
else
|
228
|
-
OperationFailure
|
221
|
+
def exception_klass(errors)
|
222
|
+
error = errors[0]
|
223
|
+
case error[:id]
|
224
|
+
when TezBalanceTooLow::FIRST_ERROR_REGEXP
|
225
|
+
TezBalanceTooLow
|
226
|
+
when ScriptRuntimeError::FIRST_ERROR_REGEXP
|
227
|
+
ScriptRuntimeError
|
228
|
+
else
|
229
|
+
OperationFailure
|
230
|
+
end
|
229
231
|
end
|
230
|
-
end
|
231
232
|
|
232
|
-
|
233
|
-
|
234
|
-
|
233
|
+
def failed!(status, errors, metadata)
|
234
|
+
raise exception_klass(errors).new(metadata: metadata, errors: errors, status: status)
|
235
|
+
end
|
235
236
|
end
|
236
237
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TezosClient
|
2
4
|
class ActivateAccountOperation < Operation
|
3
|
-
|
4
5
|
def rpc_operation_args
|
5
6
|
@rpc_operation_args ||= rpc_interface.activate_account_operation(
|
6
7
|
operation_args
|
@@ -14,4 +15,4 @@ class TezosClient
|
|
14
15
|
}
|
15
16
|
end
|
16
17
|
end
|
17
|
-
end
|
18
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TezosClient
|
2
4
|
class Operation
|
3
5
|
delegate :run, :preapply, :test_and_broadcast, :broadcast, :simulate, :signed_hex, to: :operation_mgr
|
@@ -9,25 +11,24 @@ class TezosClient
|
|
9
11
|
end
|
10
12
|
|
11
13
|
protected
|
14
|
+
attr_reader :rpc_interface
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
raise NotImplementedError, "#{__method__} is a virtual method"
|
17
|
-
end
|
16
|
+
def rpc_operation_args
|
17
|
+
raise NotImplementedError, "#{__method__} is a virtual method"
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
def post_initialize(*_args)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def operation_mgr
|
24
|
+
@operation_mgr ||= OperationMgr.new(
|
25
|
+
rpc_interface: rpc_interface,
|
26
|
+
rpc_operation_args: rpc_operation_args,
|
27
|
+
**operation_options)
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def operation_options
|
31
|
+
@args.slice(:secret_key, :protocol, :branch, :ignore_counter_error)
|
32
|
+
end
|
32
33
|
end
|
33
34
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TezosClient
|
2
4
|
class OperationArray < RawOperationArray
|
3
|
-
|
4
5
|
def post_initialize(operations:, **args)
|
5
6
|
@raw_operations = operations.map do |operation|
|
6
7
|
operation_kind = operation.delete(:kind)
|
@@ -15,10 +16,8 @@ class TezosClient
|
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
"tezos_client/#{operation_name}_operation".camelize.constantize
|
22
|
-
end
|
19
|
+
def operation_klass(operation_name)
|
20
|
+
"tezos_client/#{operation_name}_operation".camelize.constantize
|
21
|
+
end
|
23
22
|
end
|
24
|
-
end
|
23
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TezosClient
|
2
4
|
class RawOperationArray < Operation
|
3
|
-
|
4
5
|
def post_initialize(raw_operations:, **args)
|
5
6
|
@raw_operations = raw_operations.clone
|
6
7
|
end
|
@@ -19,6 +20,6 @@ class TezosClient
|
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
22
|
-
|
23
|
+
attr_reader :raw_operations
|
23
24
|
end
|
24
|
-
end
|
25
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TezosClient
|
2
4
|
class TransactionOperation < Operation
|
3
5
|
include EncodeUtils
|
@@ -11,36 +13,35 @@ class TezosClient
|
|
11
13
|
end
|
12
14
|
|
13
15
|
private
|
16
|
+
def operation_args
|
17
|
+
operation_args = @args.slice(
|
18
|
+
:amount,
|
19
|
+
:from,
|
20
|
+
:to,
|
21
|
+
:gas_limit,
|
22
|
+
:storage_limit,
|
23
|
+
:fee,
|
24
|
+
:counter
|
25
|
+
)
|
26
|
+
operation_args[:parameters] = parameters if has_parameters?
|
14
27
|
|
15
|
-
|
16
|
-
|
17
|
-
:amount,
|
18
|
-
:from,
|
19
|
-
:to,
|
20
|
-
:gas_limit,
|
21
|
-
:storage_limit,
|
22
|
-
:fee,
|
23
|
-
:counter
|
24
|
-
)
|
25
|
-
operation_args[:parameters] = parameters if has_parameters?
|
26
|
-
|
27
|
-
operation_args
|
28
|
-
end
|
28
|
+
operation_args
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def has_parameters?
|
32
|
+
@args.key? :parameters
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
def parameters
|
36
|
+
parameters = @args[:parameters].clone
|
37
|
+
if parameters.is_a? String
|
38
|
+
{
|
39
|
+
entrypoint: "default",
|
40
|
+
value: encode_args(@args[:parameters])
|
41
|
+
}
|
42
|
+
else
|
43
|
+
parameters
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
end
|
46
|
-
end
|
47
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TezosClient
|
2
4
|
class TransactionsOperation < Operation
|
3
5
|
def rpc_operation_args
|
@@ -6,8 +8,7 @@ class TezosClient
|
|
6
8
|
operations: operations,
|
7
9
|
secret_key: @args.fetch(:secret_key),
|
8
10
|
from: @args.fetch(:from),
|
9
|
-
rpc_interface: rpc_interface
|
10
|
-
liquidity_interface: liquidity_interface
|
11
|
+
rpc_interface: rpc_interface
|
11
12
|
).rpc_operation_args
|
12
13
|
end
|
13
14
|
end
|
@@ -28,4 +29,4 @@ class TezosClient
|
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
31
|
-
end
|
32
|
+
end
|
@@ -32,8 +32,8 @@ class TezosClient
|
|
32
32
|
get "#{contract_link(contract_id)}/storage"
|
33
33
|
end
|
34
34
|
|
35
|
-
def big_map_value(big_map_id:, key:,
|
36
|
-
expr_key = encode_script_expr(data: key, type:
|
35
|
+
def big_map_value(big_map_id:, key:, key_type:)
|
36
|
+
expr_key = encode_script_expr(data: key, type: key_type)
|
37
37
|
|
38
38
|
get "/chains/main/blocks/head/context/big_maps/#{big_map_id}/#{expr_key}"
|
39
39
|
end
|
@@ -12,7 +12,7 @@ class TezosClient
|
|
12
12
|
formatted_response = format_response(response.parsed_response)
|
13
13
|
|
14
14
|
log("-------")
|
15
|
-
log(">>> GET #{response.request.uri
|
15
|
+
log(">>> GET #{response.request.uri} \n")
|
16
16
|
log("<<< code: #{response.code} \n exec time: #{exec_time}\n #{tezos_contents_log(formatted_response)}")
|
17
17
|
log("-------")
|
18
18
|
unless response.success?
|
@@ -68,54 +68,53 @@ class TezosClient
|
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
71
|
+
def get_error_id(error)
|
72
|
+
error[:id]
|
73
|
+
rescue TypeError, NoMethodError
|
74
|
+
nil
|
75
|
+
end
|
71
76
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
TezosClient::InvalidActivation
|
82
|
-
when /proto\.[^.]*\.contract\.previously_revealed_key/
|
83
|
-
TezosClient::PreviouslyRevealedKey
|
84
|
-
else
|
85
|
-
TezosClient::RpcRequestFailure
|
77
|
+
def exception_klass(error)
|
78
|
+
case get_error_id(error)
|
79
|
+
when /proto\.[^.]*\.operation\.invalid_activation/
|
80
|
+
TezosClient::InvalidActivation
|
81
|
+
when /proto\.[^.]*\.contract\.previously_revealed_key/
|
82
|
+
TezosClient::PreviouslyRevealedKey
|
83
|
+
else
|
84
|
+
TezosClient::RpcRequestFailure
|
85
|
+
end
|
86
86
|
end
|
87
|
-
end
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
88
|
+
def failed!(url:, code:, responses:)
|
89
|
+
error = responses.is_a?(Array) ? responses[0] : responses
|
90
|
+
raise exception_klass(error).new(
|
91
|
+
error: error,
|
92
|
+
url: url,
|
93
|
+
status_code: code
|
94
|
+
)
|
95
|
+
end
|
97
96
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
def monitor_event_reader(uuid, event_handler)
|
98
|
+
proc do |event_response|
|
99
|
+
event_response.read_body do |event_json|
|
100
|
+
event = format_response(JSON.parse(event_json))
|
101
|
+
log("Monitor #{uuid}: received chunk #{event.pretty_inspect}")
|
102
|
+
event_handler.call(event)
|
103
|
+
end
|
104
104
|
end
|
105
105
|
end
|
106
|
-
end
|
107
106
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
def format_response(response)
|
108
|
+
if response.is_a? Array
|
109
|
+
response.map do |el|
|
110
|
+
(el.is_a? Hash) ? el.with_indifferent_access : el
|
111
|
+
end
|
112
|
+
elsif response.is_a? Hash
|
113
|
+
response.with_indifferent_access
|
114
|
+
else
|
115
|
+
response
|
112
116
|
end
|
113
|
-
elsif response.is_a? Hash
|
114
|
-
response.with_indifferent_access
|
115
|
-
else
|
116
|
-
response
|
117
117
|
end
|
118
|
-
end
|
119
118
|
end
|
120
119
|
end
|
121
|
-
end
|
120
|
+
end
|
@@ -30,17 +30,16 @@ class TezosClient
|
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
43
|
end
|
44
|
-
end
|
45
44
|
end
|
46
45
|
end
|
@@ -5,7 +5,6 @@ class TezosClient::Tools::ConvertToHash < ActiveInteraction::Base
|
|
5
5
|
interface :type
|
6
6
|
|
7
7
|
def execute
|
8
|
-
|
9
8
|
case type[:prim]
|
10
9
|
when "pair"
|
11
10
|
pair_type(data: data, type: type)
|
@@ -29,61 +28,60 @@ class TezosClient::Tools::ConvertToHash < ActiveInteraction::Base
|
|
29
28
|
end
|
30
29
|
|
31
30
|
private
|
31
|
+
def pair_type(data:, type:)
|
32
|
+
raise "Not a 'Pair' type" unless data[:prim] == "Pair"
|
33
|
+
raise "Difference detected between data and type \nDATA: #{data} \nTYPE:#{type} " unless data[:args].size == type[:args].size
|
34
|
+
|
35
|
+
result = {}
|
36
|
+
data[:args].size.times do |iter|
|
37
|
+
result.merge!(
|
38
|
+
compose(
|
39
|
+
TezosClient::Tools::ConvertToHash,
|
40
|
+
data: data[:args][iter],
|
41
|
+
type: type[:args][iter]
|
42
|
+
)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
result
|
46
|
+
end
|
32
47
|
|
33
|
-
|
34
|
-
|
35
|
-
|
48
|
+
def list_type(data:, type:)
|
49
|
+
{
|
50
|
+
var_name(type) => convert_list_element(data: data, element_type: type[:args].first)
|
51
|
+
}
|
52
|
+
end
|
36
53
|
|
37
|
-
|
38
|
-
|
39
|
-
result.merge!(
|
54
|
+
def convert_list_element(data:, element_type:)
|
55
|
+
data.map do |elem|
|
40
56
|
compose(
|
41
57
|
TezosClient::Tools::ConvertToHash,
|
42
|
-
data:
|
43
|
-
type:
|
58
|
+
data: elem,
|
59
|
+
type: element_type
|
44
60
|
)
|
45
|
-
|
61
|
+
end
|
46
62
|
end
|
47
|
-
result
|
48
|
-
end
|
49
63
|
|
50
|
-
|
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
|
-
)
|
64
|
+
def int_type(data:, type:)
|
65
|
+
{ var_name(type) => data[:int].to_i }
|
63
66
|
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def int_type(data:, type:)
|
67
|
-
{ var_name(type) => data[:int].to_i }
|
68
|
-
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
def key_type(data:, type:)
|
69
|
+
{ var_name(type) => data[:bytes] || data[:string] }
|
70
|
+
end
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
def timestamp_type(data:, type:)
|
73
|
+
{ var_name(type) => Time.zone.at(data[:int].to_i) }
|
74
|
+
end
|
77
75
|
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
def string_type(data:, type:)
|
77
|
+
{ var_name(type) => data[:string] }
|
78
|
+
end
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
def address_type(data:, type:)
|
81
|
+
{ var_name(type) => data[:bytes] || data[:string] }
|
82
|
+
end
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
def var_name(type)
|
85
|
+
"#{type[:annots].first[1..-1]}".to_sym
|
86
|
+
end
|
89
87
|
end
|
@@ -45,12 +45,12 @@ class TezosClient::Tools::FindBigMapsInStorage < ActiveInteraction::Base
|
|
45
45
|
{
|
46
46
|
name: var_name(type),
|
47
47
|
id: data[:int],
|
48
|
-
|
49
|
-
|
48
|
+
value_type: type[:args].second,
|
49
|
+
key_type: type[:args].first
|
50
50
|
}.with_indifferent_access
|
51
51
|
end
|
52
52
|
|
53
53
|
def var_name(type)
|
54
54
|
"#{type[:annots].first[1..-1]}".to_sym
|
55
55
|
end
|
56
|
-
end
|
56
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class TezosClient
|
2
4
|
module Tools
|
3
5
|
module TemporaryFile
|
@@ -16,7 +18,7 @@ class TezosClient
|
|
16
18
|
|
17
19
|
res
|
18
20
|
ensure
|
19
|
-
File.delete(file_copy_path) if File.
|
21
|
+
File.delete(file_copy_path) if File.exist? file_copy_path
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.with_tempfile(extension)
|
@@ -27,4 +29,4 @@ class TezosClient
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
32
|
+
end
|
data/lib/tezos_client/version.rb
CHANGED
data/lib/tezos_client.rb
CHANGED
@@ -32,7 +32,6 @@ require "tezos_client/tools/system_call"
|
|
32
32
|
require "tezos_client/tools/temporary_file"
|
33
33
|
|
34
34
|
require "tezos_client/rpc_interface"
|
35
|
-
require "tezos_client/liquidity_interface"
|
36
35
|
require "tezos_client/smartpy_interface"
|
37
36
|
|
38
37
|
require "tezos_client/tools/convert_to_hash"
|
@@ -48,7 +47,6 @@ class TezosClient
|
|
48
47
|
include Crypto
|
49
48
|
|
50
49
|
attr_accessor :rpc_interface
|
51
|
-
attr_accessor :liquidity_interface
|
52
50
|
attr_accessor :smartpy_interface
|
53
51
|
|
54
52
|
RANDOM_SIGNATURE = "edsigu165B7VFf3Dpw2QABVzEtCxJY2gsNBNcE3Ti7rRxtDUjqTFRpg67EdAQmY6YWPE5tKJDMnSTJDFu65gic8uLjbW2YwGvAZ"
|
@@ -56,7 +54,6 @@ class TezosClient
|
|
56
54
|
def initialize(rpc_node_address: "127.0.0.1", rpc_node_port: 8732, liquidity_options: {})
|
57
55
|
@rpc_node_address = rpc_node_address
|
58
56
|
@rpc_node_port = rpc_node_port
|
59
|
-
@liquidity_options = liquidity_options
|
60
57
|
|
61
58
|
@client_config_file = ENV["TEZOS_CLIENT_CONFIG_FILE"]
|
62
59
|
|
@@ -66,12 +63,6 @@ class TezosClient
|
|
66
63
|
)
|
67
64
|
|
68
65
|
@smartpy_interface = SmartpyInterface.new
|
69
|
-
|
70
|
-
@liquidity_interface = LiquidityInterface.new(
|
71
|
-
rpc_node_address: @rpc_node_address,
|
72
|
-
rpc_node_port: @rpc_node_port,
|
73
|
-
options: @liquidity_options
|
74
|
-
)
|
75
66
|
end
|
76
67
|
|
77
68
|
# Originates a contract on the tezos blockchain
|
@@ -161,7 +152,6 @@ class TezosClient
|
|
161
152
|
from = public_key_to_address(public_key)
|
162
153
|
|
163
154
|
operation = RevealOperation.new(
|
164
|
-
liquidity_interface: liquidity_interface,
|
165
155
|
rpc_interface: rpc_interface,
|
166
156
|
public_key: public_key,
|
167
157
|
from: from,
|
@@ -172,11 +162,10 @@ class TezosClient
|
|
172
162
|
broadcast_operation(operation: operation, dry_run: dry_run)
|
173
163
|
end
|
174
164
|
|
175
|
-
def call_contract(dry_run: false, entrypoint:, params:,
|
165
|
+
def call_contract(dry_run: false, entrypoint:, params:, params_type:, **args)
|
176
166
|
json_params = micheline_params(
|
177
167
|
params: params,
|
178
168
|
entrypoint: entrypoint,
|
179
|
-
script: script,
|
180
169
|
params_type: params_type
|
181
170
|
)
|
182
171
|
|
@@ -194,7 +183,6 @@ class TezosClient
|
|
194
183
|
from = public_key_to_address(public_key)
|
195
184
|
|
196
185
|
operation = RawOperationArray.new(
|
197
|
-
liquidity_interface: liquidity_interface,
|
198
186
|
rpc_interface: rpc_interface,
|
199
187
|
public_key: public_key,
|
200
188
|
from: from,
|
@@ -257,63 +245,46 @@ class TezosClient
|
|
257
245
|
end
|
258
246
|
|
259
247
|
private
|
248
|
+
def broadcast_operation(operation:, dry_run:)
|
249
|
+
res = if dry_run
|
250
|
+
operation.simulate
|
251
|
+
else
|
252
|
+
operation.test_and_broadcast
|
253
|
+
end
|
260
254
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
else
|
265
|
-
operation.test_and_broadcast
|
255
|
+
res.merge(
|
256
|
+
rpc_operation_args: operation.rpc_operation_args
|
257
|
+
)
|
266
258
|
end
|
267
259
|
|
268
|
-
|
269
|
-
|
270
|
-
)
|
271
|
-
end
|
272
|
-
|
273
|
-
def liquidity_contract? filename
|
274
|
-
filename&.to_s&.end_with?(".liq")
|
275
|
-
end
|
276
|
-
|
277
|
-
def micheline_params(params:, entrypoint:, script: nil, params_type:)
|
278
|
-
{
|
279
|
-
entrypoint: entrypoint,
|
280
|
-
value: convert_params(
|
281
|
-
params: params,
|
260
|
+
def micheline_params(params:, entrypoint:, params_type:)
|
261
|
+
{
|
282
262
|
entrypoint: entrypoint,
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
def convert_params(params:, entrypoint:, script: nil, params_type:)
|
290
|
-
case params_type.to_sym
|
291
|
-
when :micheline
|
292
|
-
params
|
293
|
-
when :caml
|
294
|
-
raise ::ArgumentError, "need liquidity script path with camel type" if script.nil?
|
263
|
+
value: convert_params(
|
264
|
+
params: params,
|
265
|
+
params_type: params_type
|
266
|
+
)
|
267
|
+
}
|
268
|
+
end
|
295
269
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
270
|
+
def convert_params(params:, params_type:)
|
271
|
+
case params_type.to_sym
|
272
|
+
when :micheline
|
273
|
+
params
|
274
|
+
else
|
275
|
+
raise ::ArgumentError, "params type must be equal to [ :micheline ]"
|
276
|
+
end
|
303
277
|
end
|
304
|
-
end
|
305
278
|
|
306
279
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
raise "unknown contract type"
|
280
|
+
def contract_interface(script)
|
281
|
+
case script.to_s
|
282
|
+
when /[A-Za-z_\/\-]*.py/
|
283
|
+
smartpy_interface
|
284
|
+
when nil
|
285
|
+
raise "script var unset"
|
286
|
+
else
|
287
|
+
raise "unknown contract type"
|
288
|
+
end
|
317
289
|
end
|
318
|
-
end
|
319
290
|
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.
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2020-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -252,8 +252,6 @@ files:
|
|
252
252
|
- lib/tezos_client/currency_utils.rb
|
253
253
|
- lib/tezos_client/encode_utils.rb
|
254
254
|
- lib/tezos_client/exceptions.rb
|
255
|
-
- lib/tezos_client/liquidity_inteface/liquidity_wrapper.rb
|
256
|
-
- lib/tezos_client/liquidity_interface.rb
|
257
255
|
- lib/tezos_client/logger.rb
|
258
256
|
- lib/tezos_client/operation_mgr.rb
|
259
257
|
- lib/tezos_client/operations/activate_account_operation.rb
|
@@ -303,7 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
301
|
- !ruby/object:Gem::Version
|
304
302
|
version: '0'
|
305
303
|
requirements: []
|
306
|
-
|
304
|
+
rubyforge_project:
|
305
|
+
rubygems_version: 2.7.6
|
307
306
|
signing_key:
|
308
307
|
specification_version: 4
|
309
308
|
summary: Wrapper to the tezos client.
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class TezosClient
|
4
|
-
class LiquidityInterface
|
5
|
-
# Wrapper used to call the tezos-client binary
|
6
|
-
module LiquidityWrapper
|
7
|
-
def call_liquidity(command, verbose: false)
|
8
|
-
cmd = liquidity_cmd(verbose: verbose).concat command
|
9
|
-
|
10
|
-
Tools::SystemCall.execute(cmd)
|
11
|
-
rescue SysCallError => e
|
12
|
-
raise LiquidityError, e.message
|
13
|
-
end
|
14
|
-
|
15
|
-
def liquidity_cmd(verbose:)
|
16
|
-
liquidity_request = ["liquidity"]
|
17
|
-
liquidity_request << "--verbose" if verbose
|
18
|
-
liquidity_request << "--tezos-node"
|
19
|
-
liquidity_request << tezos_node.to_s
|
20
|
-
liquidity_request
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "liquidity_inteface/liquidity_wrapper"
|
4
|
-
|
5
|
-
class TezosClient
|
6
|
-
class LiquidityInterface
|
7
|
-
include Logger
|
8
|
-
include LiquidityWrapper
|
9
|
-
|
10
|
-
attr_reader :options
|
11
|
-
|
12
|
-
def initialize(rpc_node_address: "127.0.0.1", rpc_node_port: 8732, options: {})
|
13
|
-
@rpc_node_address = rpc_node_address
|
14
|
-
@rpc_node_port = rpc_node_port
|
15
|
-
@options = options
|
16
|
-
end
|
17
|
-
|
18
|
-
def format_params(params)
|
19
|
-
return [] if params.nil?
|
20
|
-
return [params] if params.is_a? String
|
21
|
-
|
22
|
-
params.map(&:to_s)
|
23
|
-
end
|
24
|
-
|
25
|
-
def initial_storage(args)
|
26
|
-
from = args.fetch :from
|
27
|
-
script = args.fetch :script
|
28
|
-
init_params = args.fetch :init_params
|
29
|
-
init_params = format_params(init_params)
|
30
|
-
|
31
|
-
Tools::TemporaryFile.with_tempfile(".json") do |json_file|
|
32
|
-
cmd_opt = ["--source", from.to_s,"--json", script.to_s, "-o", json_file.path.to_s, "--init-storage"] + init_params
|
33
|
-
|
34
|
-
call_liquidity cmd_opt, verbose: options[:verbose]
|
35
|
-
JSON.parse json_file.read.strip
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def json_scripts(script:)
|
40
|
-
Tools::TemporaryFile.with_file_copy(script) do |script_copy_path|
|
41
|
-
script_basename = script_copy_path.sub(/.liq$/, "")
|
42
|
-
|
43
|
-
json_init_script_path = "#{script_basename}.initializer.tz.json"
|
44
|
-
json_contract_script_path = "#{script_basename}.tz.json"
|
45
|
-
|
46
|
-
call_liquidity ["--json", "#{script_copy_path}"]
|
47
|
-
|
48
|
-
json_contract_script_file = File.open(json_contract_script_path)
|
49
|
-
json_contract_script = JSON.parse(json_contract_script_file.read)
|
50
|
-
json_contract_script_file.close
|
51
|
-
|
52
|
-
if File.exists? json_init_script_path
|
53
|
-
json_init_script_file = File.open(json_init_script_path)
|
54
|
-
json_init_script = JSON.parse(json_init_script_file.read)
|
55
|
-
json_init_script_file.close
|
56
|
-
end
|
57
|
-
|
58
|
-
if block_given?
|
59
|
-
yield(json_init_script, json_contract_script)
|
60
|
-
else
|
61
|
-
return json_init_script, json_contract_script
|
62
|
-
end
|
63
|
-
|
64
|
-
ensure
|
65
|
-
[json_init_script_path, json_contract_script_path].each do |file_path|
|
66
|
-
File.delete file_path if File.exists? file_path
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def origination_script(args)
|
72
|
-
storage = initial_storage(args)
|
73
|
-
_json_init_script, json_contract_script = json_scripts(script: args[:script])
|
74
|
-
|
75
|
-
{
|
76
|
-
code: json_contract_script,
|
77
|
-
storage: storage
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
def forge_deploy(args)
|
82
|
-
amount = args.fetch(:amount, 0)
|
83
|
-
spendable = args.fetch(:spendable, false)
|
84
|
-
delegatable = args.fetch(:delegatable, false)
|
85
|
-
source = args.fetch :from
|
86
|
-
script = args.fetch :script
|
87
|
-
init_params = args.fetch :init_params
|
88
|
-
|
89
|
-
cmd_opt = ["--source", "#{source}"]
|
90
|
-
cmd_opt << "--spendable" if spendable
|
91
|
-
cmd_opt << "--delegatable" if delegatable
|
92
|
-
cmd_opt += ["--amount", "#{amount}tz", "#{script}", "--forge-deploy", init_params]
|
93
|
-
res = call_liquidity cmd_opt
|
94
|
-
res.strip
|
95
|
-
end
|
96
|
-
|
97
|
-
def tezos_node
|
98
|
-
"#{@rpc_node_address}:#{@rpc_node_port}"
|
99
|
-
end
|
100
|
-
|
101
|
-
def get_storage(script:, contract_address:)
|
102
|
-
res = call_liquidity ["#{script}", "--get-storage", "#{contract_address}"]
|
103
|
-
res.strip
|
104
|
-
end
|
105
|
-
|
106
|
-
def call_parameters(script:, entrypoint:, parameters:)
|
107
|
-
params = format_params parameters
|
108
|
-
Tools::TemporaryFile.with_tempfile(".json") do |json_file|
|
109
|
-
params = [ entrypoint ] + params
|
110
|
-
res = call_liquidity ["--json", "-o", "#{json_file.path}", "#{script}", "--data"] + params
|
111
|
-
JSON.parse res
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def liquidity_pack_data(data:, type:)
|
116
|
-
res = call_liquidity ["--pack", "#{data}", "#{type}"]
|
117
|
-
res.strip
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|