tezos_client 0.2.0 → 0.2.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: 996f52ab508d2c26e7fc291462f8758b0dd30db32415f657cc050b89cacc272e
4
- data.tar.gz: 20138f2fd23c49133d839fa0963c1c0920f4525eee31d8d39a62d1afebeec1ac
3
+ metadata.gz: a192811cdc281656ad008df4408d830283c77f7ccf66150c0282005a68505f7c
4
+ data.tar.gz: d1c9561af9631e8db8c54b867983efc0e0c54c0628a8f88354fc0a0d55e861dd
5
5
  SHA512:
6
- metadata.gz: 287af23b98733a8b8411e8ec85eccdd5b797f74189fd2e88aabc34fb98d997c74f52e163a7eee54611c5de7b67ea124f297b2697fd4e90f3b6c62728ab869428
7
- data.tar.gz: 0d73408994a10d1d8906308faf8f5d19995e7d2cd759abe1c520c7aa1577812a55b8490a6a727afe426d7c47837fa77fd47b760b2b53b5f2f5be40bd643185f8
6
+ metadata.gz: 334a46f80c4e6873dbd587413589d343eaba149881f6b99dcc44c658f5c904fded810ed938748aa3085bcd70db198f74564ae1e2e5a2099a6d55b40e2c425569
7
+ data.tar.gz: bc6a850b461d0608f82d1929745a5c34493f4c34365e4018e3bcc1ee6f3ab7e8b26613d540e05556932166a7e6af3c4fea3db60e663898bef25518ba6593810d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tezos_client (0.2.0)
4
+ tezos_client (0.2.1)
5
5
  activesupport (~> 5.2.0)
6
6
  base58 (~> 0.2.3)
7
7
  httparty (~> 0.16.2)
@@ -7,8 +7,6 @@ class TezosClient
7
7
 
8
8
  attr_accessor :liquidity_interface,
9
9
  :rpc_interface,
10
- :base_58_signature,
11
- :signed_hex,
12
10
  :from,
13
11
  :operation_args,
14
12
  :rpc_args
@@ -19,9 +17,9 @@ class TezosClient
19
17
  @from = args.fetch(:from) { raise ArgumentError, "Argument :from missing" }
20
18
  @secret_key = args.fetch(:secret_key)
21
19
  @init_args = args
22
- @signed = false
23
20
  @operation_args = {}
24
21
  initialize_operation_args
22
+ @signed_operation_args_h = nil
25
23
  @rpc_args = rpc_interface.operation(@operation_args)
26
24
  end
27
25
 
@@ -37,12 +35,16 @@ class TezosClient
37
35
  rpc_interface.head_hash
38
36
  end
39
37
 
38
+ def remote_counter
39
+ @remote_counter ||= rpc_interface.contract_counter(from) + 1
40
+ end
41
+
40
42
  def counter
41
- @init_args.fetch(:counter) { rpc_interface.contract_counter(from) + 1 }
43
+ @counter ||= @init_args.fetch(:counter) { remote_counter }
42
44
  end
43
45
 
44
46
  def protocol
45
- rpc_interface.protocols[0]
47
+ rpc_interface.protocol
46
48
  end
47
49
 
48
50
  def simulate_and_update_limits
@@ -61,27 +63,47 @@ class TezosClient
61
63
  secret_key: @secret_key,
62
64
  operation_hex: to_hex
63
65
  ) do |base_58_signature, signed_hex, _op_id|
66
+ @signed_operation_args_h = operation_args.hash
64
67
  @base_58_signature = base_58_signature
65
68
  @signed_hex = signed_hex
66
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
67
80
 
68
- @signed = true
81
+ def signed_hex
82
+ sign unless signed?
83
+ @signed_hex
69
84
  end
70
85
 
71
86
  def test_and_broadcast
87
+ # https://gitlab.com/tezos/tezos/issues/376
88
+ operation_args.merge!(counter: remote_counter)
89
+
72
90
  # simulate operations and adjust gas limits
73
91
  simulate_and_update_limits
74
- sign
75
92
  operation_result = preapply
93
+
94
+ # https://gitlab.com/tezos/tezos/issues/376
95
+ operation_args.merge!(counter: counter)
96
+
76
97
  op_id = broadcast
77
98
  {
78
99
  operation_id: op_id,
79
- operation_result: operation_result
100
+ operation_result: operation_result,
101
+ counter: counter
80
102
  }
81
103
  end
82
104
 
83
105
  def run
84
- rpc_response = rpc_interface.run_operation(**operation_args, signature: RANDOM_SIGNATURE)
106
+ rpc_response = rpc_interface.run_operation(**operation_args, signature: base_58_signature)
85
107
 
86
108
  operation_result = ensure_applied!(rpc_response)
87
109
 
@@ -97,8 +119,6 @@ class TezosClient
97
119
  end
98
120
 
99
121
  def preapply
100
- raise "can not preapply unsigned operations" unless @signed
101
-
102
122
  res = rpc_interface.preapply_operation(
103
123
  **operation_args,
104
124
  signature: base_58_signature,
@@ -108,7 +128,6 @@ class TezosClient
108
128
  end
109
129
 
110
130
  def broadcast
111
- raise "can not preapply unsigned operations" unless @signed
112
131
  rpc_interface.broadcast_operation(signed_hex)
113
132
  end
114
133
 
@@ -20,7 +20,8 @@ class TezosClient
20
20
  end
21
21
 
22
22
  def protocol
23
- get "/protocols/main"
23
+ metadata = get "/chains/main/blocks/head/metadata"
24
+ metadata[:protocol]
24
25
  end
25
26
  end
26
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class TezosClient
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tezos_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Michard