tezos_client 0.3.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -4
- data/Gemfile.lock +1 -1
- data/lib/tezos_client.rb +19 -10
- data/lib/tezos_client/exceptions.rb +92 -0
- data/lib/tezos_client/liquidity_interface.rb +4 -2
- data/lib/tezos_client/logger.rb +22 -0
- data/lib/tezos_client/operation_mgr.rb +178 -0
- data/lib/tezos_client/operations/activate_account_operation.rb +9 -27
- data/lib/tezos_client/operations/operation.rb +33 -0
- data/lib/tezos_client/operations/operation_array.rb +35 -0
- data/lib/tezos_client/operations/origination_operation.rb +13 -44
- data/lib/tezos_client/operations/reveal_operation.rb +3 -22
- data/lib/tezos_client/operations/transaction_operation.rb +21 -24
- data/lib/tezos_client/operations/transactions_operation.rb +24 -22
- data/lib/tezos_client/rpc_interface.rb +2 -0
- data/lib/tezos_client/rpc_interface/helper.rb +29 -85
- data/lib/tezos_client/rpc_interface/operations.rb +44 -0
- data/lib/tezos_client/rpc_interface/request_manager.rb +23 -5
- data/lib/tezos_client/version.rb +1 -1
- data/travis-scripts/install-liquidity.sh +2 -10
- data/travis-scripts/install-opam.sh +11 -3
- data/travis-scripts/prepare-ubuntu.sh +14 -0
- metadata +8 -4
- data/lib/tezos_client/operation.rb +0 -159
- data/travis-scripts/prepare-trusty.sh +0 -16
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TezosClient
|
4
|
+
class RpcInterface
|
5
|
+
module Operations
|
6
|
+
using CurrencyUtils
|
7
|
+
|
8
|
+
def preapply_operations(operations:, **options)
|
9
|
+
content = {
|
10
|
+
protocol: options.fetch(:protocol),
|
11
|
+
branch: options.fetch(:branch),
|
12
|
+
contents: operations,
|
13
|
+
signature: options.fetch(:signature)
|
14
|
+
}
|
15
|
+
|
16
|
+
res = post("chains/main/blocks/head/helpers/preapply/operations",
|
17
|
+
[content])
|
18
|
+
res[0]["contents"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_operations(operations:, **options)
|
22
|
+
content = {
|
23
|
+
branch: options.fetch(:branch),
|
24
|
+
contents: operations,
|
25
|
+
signature: options.fetch(:signature)
|
26
|
+
}
|
27
|
+
res = post("chains/main/blocks/head/helpers/scripts/run_operation", content)
|
28
|
+
res["contents"]
|
29
|
+
end
|
30
|
+
|
31
|
+
def forge_operations(operations:, **options)
|
32
|
+
content = {
|
33
|
+
branch: options.fetch(:branch),
|
34
|
+
contents: operations
|
35
|
+
}
|
36
|
+
post("chains/main/blocks/head/helpers/forge/operations", content)
|
37
|
+
end
|
38
|
+
|
39
|
+
def broadcast_operation(data)
|
40
|
+
post("injection/operation?chain=main", data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -11,10 +11,10 @@ class TezosClient
|
|
11
11
|
|
12
12
|
log("-------")
|
13
13
|
log(">>> GET #{response.request.uri.to_s} \n")
|
14
|
-
log("<<< code: #{response.code} \n #{formatted_response
|
14
|
+
log("<<< code: #{response.code} \n #{tezos_contents_log(formatted_response)}")
|
15
15
|
log("-------")
|
16
16
|
unless response.success?
|
17
|
-
|
17
|
+
failed!(url: url, code: response.code, responses: formatted_response)
|
18
18
|
end
|
19
19
|
|
20
20
|
formatted_response
|
@@ -29,12 +29,12 @@ class TezosClient
|
|
29
29
|
formatted_response = format_response(response.parsed_response)
|
30
30
|
|
31
31
|
log("-------")
|
32
|
-
log(">>> POST #{url} \n #{content
|
33
|
-
log("<<< code: #{response.code} \n #{formatted_response
|
32
|
+
log(">>> POST #{url} \n #{tezos_contents_log(content)}")
|
33
|
+
log("<<< code: #{response.code} \n #{tezos_contents_log(formatted_response)}")
|
34
34
|
log("-------")
|
35
35
|
|
36
36
|
unless response.success?
|
37
|
-
|
37
|
+
failed!(url: url, code: response.code, responses: formatted_response)
|
38
38
|
end
|
39
39
|
|
40
40
|
formatted_response
|
@@ -63,6 +63,24 @@ class TezosClient
|
|
63
63
|
|
64
64
|
private
|
65
65
|
|
66
|
+
def exception_klass(error)
|
67
|
+
case error[:id]
|
68
|
+
when "proto.003-PsddFKi3.operation.invalid_activation"
|
69
|
+
TezosClient::InvalidActivation
|
70
|
+
else
|
71
|
+
TezosClient::RpcRequestFailure
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def failed!(url:, code:, responses:)
|
76
|
+
error = responses[0]
|
77
|
+
raise exception_klass(error).new(
|
78
|
+
error: error,
|
79
|
+
url: url,
|
80
|
+
status_code: code
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
66
84
|
def monitor_event_reader(uuid, event_handler)
|
67
85
|
proc do |event_response|
|
68
86
|
event_response.read_body do |event_json|
|
data/lib/tezos_client/version.rb
CHANGED
@@ -3,24 +3,16 @@
|
|
3
3
|
# This script is used in .travis.yml for continuous integration on travis.
|
4
4
|
# BTW, it also show some needed system packages to build liquidity
|
5
5
|
# Travis CI is done on Ubuntu trusty
|
6
|
+
export OPAMYES=1
|
6
7
|
|
7
8
|
[ -d "liquidity/.git" ] || git clone --depth=50 https://github.com/OCamlPro/liquidity.git liquidity
|
8
9
|
cd liquidity
|
9
10
|
git pull
|
10
11
|
git checkout next
|
11
12
|
|
12
|
-
# currently, we only target OCaml 4.06.1 because we reuse the parser of OCaml
|
13
|
-
opam switch create liquidity 4.06.1 || opam switch set liquidity
|
14
|
-
|
15
|
-
eval `opam config env`
|
16
|
-
opam update
|
17
13
|
eval `opam config env`
|
18
14
|
|
19
|
-
make clone-tezos
|
20
|
-
tezos/scripts/install_build_deps.raw.sh
|
21
|
-
|
22
|
-
cd tezos && make build-deps all install && cd -
|
23
15
|
make build-deps
|
24
|
-
|
16
|
+
make clone-tezos
|
25
17
|
make
|
26
18
|
make install
|
@@ -1,4 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# This script is used in .travis.yml for continuous integration on travis.
|
2
|
+
# Travis CI is done on Ubuntu trusty
|
3
|
+
|
4
|
+
export OPAMYES=1
|
3
5
|
wget https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh
|
4
|
-
yes "" | sh install.sh
|
6
|
+
yes "" | sh install.sh
|
7
|
+
|
8
|
+
opam switch create liquidity 4.06.1 || opam switch set liquidity
|
9
|
+
|
10
|
+
eval $(opam config env)
|
11
|
+
|
12
|
+
opam update
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This script is used in .travis.yml for continuous integration on travis.
|
2
|
+
# This also show some needed system packages to build liquidity.
|
3
|
+
# Travis CI is done on Ubuntu Xenial
|
4
|
+
|
5
|
+
sudo apt-get update -qq
|
6
|
+
sudo apt-get install -y -qq libgmp-dev
|
7
|
+
|
8
|
+
# do this in a second step
|
9
|
+
# for ubuntu, these packages are too old or not available in xenial
|
10
|
+
sudo add-apt-repository "deb http://fr.archive.ubuntu.com/ubuntu artful main universe"
|
11
|
+
sudo apt-get update -qq
|
12
|
+
sudo apt-get install -y -qq \
|
13
|
+
libsecp256k1-dev libsecp256k1-0 libsodium-dev libssl-dev \
|
14
|
+
bubblewrap libev-dev libhidapi-dev
|
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: 0.
|
4
|
+
version: 0.4.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: 2019-
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -223,11 +223,14 @@ files:
|
|
223
223
|
- lib/tezos_client/crypto.rb
|
224
224
|
- lib/tezos_client/currency_utils.rb
|
225
225
|
- lib/tezos_client/encode_utils.rb
|
226
|
+
- lib/tezos_client/exceptions.rb
|
226
227
|
- lib/tezos_client/liquidity_inteface/liquidity_wrapper.rb
|
227
228
|
- lib/tezos_client/liquidity_interface.rb
|
228
229
|
- lib/tezos_client/logger.rb
|
229
|
-
- lib/tezos_client/
|
230
|
+
- lib/tezos_client/operation_mgr.rb
|
230
231
|
- lib/tezos_client/operations/activate_account_operation.rb
|
232
|
+
- lib/tezos_client/operations/operation.rb
|
233
|
+
- lib/tezos_client/operations/operation_array.rb
|
231
234
|
- lib/tezos_client/operations/origination_operation.rb
|
232
235
|
- lib/tezos_client/operations/reveal_operation.rb
|
233
236
|
- lib/tezos_client/operations/transaction_operation.rb
|
@@ -238,13 +241,14 @@ files:
|
|
238
241
|
- lib/tezos_client/rpc_interface/contracts.rb
|
239
242
|
- lib/tezos_client/rpc_interface/helper.rb
|
240
243
|
- lib/tezos_client/rpc_interface/monitor.rb
|
244
|
+
- lib/tezos_client/rpc_interface/operations.rb
|
241
245
|
- lib/tezos_client/rpc_interface/request_manager.rb
|
242
246
|
- lib/tezos_client/string_utils.rb
|
243
247
|
- lib/tezos_client/version.rb
|
244
248
|
- tezos_client.gemspec
|
245
249
|
- travis-scripts/install-liquidity.sh
|
246
250
|
- travis-scripts/install-opam.sh
|
247
|
-
- travis-scripts/prepare-
|
251
|
+
- travis-scripts/prepare-ubuntu.sh
|
248
252
|
homepage: http://moneytrack.io
|
249
253
|
licenses:
|
250
254
|
- MIT
|
@@ -1,159 +0,0 @@
|
|
1
|
-
|
2
|
-
class TezosClient
|
3
|
-
|
4
|
-
class Operation
|
5
|
-
include Crypto
|
6
|
-
using CurrencyUtils
|
7
|
-
|
8
|
-
attr_accessor :liquidity_interface,
|
9
|
-
:rpc_interface,
|
10
|
-
:from,
|
11
|
-
:operation_args,
|
12
|
-
:rpc_args
|
13
|
-
|
14
|
-
def initialize(liquidity_interface:, rpc_interface:, **args)
|
15
|
-
@liquidity_interface = liquidity_interface
|
16
|
-
@rpc_interface = rpc_interface
|
17
|
-
@from = args.fetch(:from) { raise ArgumentError, "Argument :from missing" }
|
18
|
-
@secret_key = args.fetch(:secret_key)
|
19
|
-
@init_args = args
|
20
|
-
@operation_args = {}
|
21
|
-
initialize_operation_args
|
22
|
-
@signed_operation_args_h = nil
|
23
|
-
@rpc_args = rpc_interface.operation(@operation_args)
|
24
|
-
end
|
25
|
-
|
26
|
-
def initialize_operation_args
|
27
|
-
raise NotImplementedError.new("#{self.class.name}##{__method__} is an abstract method.")
|
28
|
-
end
|
29
|
-
|
30
|
-
def operation_kind
|
31
|
-
raise NotImplementedError.new("#{self.class.name}##{__method__} is an abstract method.")
|
32
|
-
end
|
33
|
-
|
34
|
-
def branch
|
35
|
-
rpc_interface.head_hash
|
36
|
-
end
|
37
|
-
|
38
|
-
def remote_counter
|
39
|
-
@remote_counter ||= rpc_interface.contract_counter(from) + 1
|
40
|
-
end
|
41
|
-
|
42
|
-
def counter
|
43
|
-
@counter ||= @init_args.fetch(:counter) { remote_counter }
|
44
|
-
end
|
45
|
-
|
46
|
-
def protocol
|
47
|
-
rpc_interface.protocol
|
48
|
-
end
|
49
|
-
|
50
|
-
def simulate_and_update_limits
|
51
|
-
run_result = run
|
52
|
-
|
53
|
-
@operation_args[:gas_limit] = run_result[:consumed_gas] + 0.01
|
54
|
-
#@operation_args[:storage_limit] = run_result[:consumed_storage]
|
55
|
-
end
|
56
|
-
|
57
|
-
def to_hex
|
58
|
-
rpc_interface.forge_operation(operation_args)
|
59
|
-
end
|
60
|
-
|
61
|
-
def sign
|
62
|
-
sign_operation(
|
63
|
-
secret_key: @secret_key,
|
64
|
-
operation_hex: to_hex
|
65
|
-
) do |base_58_signature, signed_hex, _op_id|
|
66
|
-
@signed_operation_args_h = operation_args.hash
|
67
|
-
@base_58_signature = base_58_signature
|
68
|
-
@signed_hex = signed_hex
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def signed?
|
73
|
-
@signed_operation_args_h == operation_args.hash
|
74
|
-
end
|
75
|
-
|
76
|
-
def base_58_signature
|
77
|
-
sign unless signed?
|
78
|
-
@base_58_signature
|
79
|
-
end
|
80
|
-
|
81
|
-
def signed_hex
|
82
|
-
sign unless signed?
|
83
|
-
@signed_hex
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_and_broadcast
|
87
|
-
# https://gitlab.com/tezos/tezos/issues/376
|
88
|
-
operation_args.merge!(counter: remote_counter)
|
89
|
-
|
90
|
-
# simulate operations and adjust gas limits
|
91
|
-
simulate_and_update_limits
|
92
|
-
operation_result = preapply
|
93
|
-
|
94
|
-
# https://gitlab.com/tezos/tezos/issues/376
|
95
|
-
operation_args.merge!(counter: counter)
|
96
|
-
|
97
|
-
op_id = broadcast
|
98
|
-
{
|
99
|
-
operation_id: op_id,
|
100
|
-
operation_result: operation_result,
|
101
|
-
counter: counter
|
102
|
-
}
|
103
|
-
end
|
104
|
-
|
105
|
-
def run
|
106
|
-
rpc_response = rpc_interface.run_operation(**operation_args, signature: base_58_signature)
|
107
|
-
|
108
|
-
consumed_storage = 0
|
109
|
-
consumed_gas = 0
|
110
|
-
|
111
|
-
operation_result = ensure_applied!(rpc_response) do |result|
|
112
|
-
consumed_storage = (result.dig(:operation_result, :paid_storage_size_diff) || "0").to_i.from_satoshi
|
113
|
-
consumed_gas = (result.dig(:operation_result, :consumed_gas) || "0").to_i.from_satoshi
|
114
|
-
|
115
|
-
unless result[:internal_operation_results].nil?
|
116
|
-
result[:internal_operation_results].each do |internal_operation_result|
|
117
|
-
consumed_gas += (internal_operation_result[:result][:consumed_gas] || "0").to_i.from_satoshi
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
result[:operation_result]
|
122
|
-
end
|
123
|
-
|
124
|
-
{
|
125
|
-
status: :applied,
|
126
|
-
consumed_gas: consumed_gas,
|
127
|
-
consumed_storage: consumed_storage,
|
128
|
-
operation_result: operation_result
|
129
|
-
}
|
130
|
-
end
|
131
|
-
|
132
|
-
def preapply
|
133
|
-
res = rpc_interface.preapply_operation(
|
134
|
-
**operation_args,
|
135
|
-
signature: base_58_signature,
|
136
|
-
protocol: protocol)
|
137
|
-
|
138
|
-
ensure_applied!(res)
|
139
|
-
end
|
140
|
-
|
141
|
-
def broadcast
|
142
|
-
rpc_interface.broadcast_operation(signed_hex)
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
def ensure_applied!(rpc_response)
|
149
|
-
operation_result = rpc_response[:metadata][:operation_result]
|
150
|
-
status = operation_result[:status]
|
151
|
-
raise "Operation status != 'applied': #{status}\n #{rpc_response.pretty_inspect}" if status != "applied"
|
152
|
-
if block_given?
|
153
|
-
yield rpc_response[:metadata]
|
154
|
-
else
|
155
|
-
operation_result
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
# This script is used in .travis.yml for continuous integration on travis.
|
3
|
-
# BTW, it also show some needed system packages to build liquidity.
|
4
|
-
# Travis CI is done on Ubuntu trusty
|
5
|
-
|
6
|
-
sudo apt-get update -qq
|
7
|
-
sudo apt-get install -y -qq libgmp-dev pandoc make m4 gcc aspcud curl # ocaml ocaml-native-compilers
|
8
|
-
|
9
|
-
# do this in a second step to only install libsecp256k1-dev libsecp256k1-0
|
10
|
-
# for ubuntu, these packages are not available in trusty
|
11
|
-
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu artful main universe"
|
12
|
-
sudo apt-get update -qq
|
13
|
-
sudo apt-get install -y -qq \
|
14
|
-
libsecp256k1-dev libsecp256k1-0 libsodium-dev libssl-dev \
|
15
|
-
bubblewrap libev-dev libhidapi-dev pkg-config
|
16
|
-
|