substrate_client.rb 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +17 -0
- data/Gemfile.lock +1 -1
- data/README.md +47 -1
- data/lib/substrate_client.rb +16 -12
- data/lib/substrate_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af04674d5e75dbafa82eade829b5798fe87e015a51a8edb63d7845cdd38c27b9
|
4
|
+
data.tar.gz: 8afa612ea099169396f4ef3155c5158ba188b09ff602b5d515fcf6deadfe5739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5c5379451ece56ac1a868092446f66929c83eafb36dace7007b2f479616c3bb2c7a9aff2f77fd1ef25b0bdf5ebb0a431b17308d892ecc4ad3cad54a03700a2e
|
7
|
+
data.tar.gz: e179bd7fb5a421f1de150463d09a04ad369a15eb1f1027c5c21d9fdc837dda5ebed1671cac093e2a584b9c356ad3112881b990d0763394d533ddb7d3e22c7f00
|
data/Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
FROM ruby:2.6-alpine3.11
|
2
|
+
|
3
|
+
ENV BUILD_PACKAGES curl-dev build-base
|
4
|
+
|
5
|
+
RUN apk update && \
|
6
|
+
apk upgrade && \
|
7
|
+
apk add git curl $BUILD_PACKAGES
|
8
|
+
|
9
|
+
WORKDIR /usr/src/app
|
10
|
+
|
11
|
+
COPY . .
|
12
|
+
|
13
|
+
RUN gem install bundler:1.17.3 && \
|
14
|
+
bundle install && \
|
15
|
+
rake install:local
|
16
|
+
|
17
|
+
CMD ["sh"]
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -107,7 +107,7 @@ But, in order to show the parameters more clearly, some important or frequently
|
|
107
107
|
Retrieves the newest header via subscription. This will return data continuously until you unsubscribe the subscription.
|
108
108
|
|
109
109
|
```ruby
|
110
|
-
subscription = client.
|
110
|
+
subscription = client.chain_subscribe_all_heads do |data|
|
111
111
|
p data
|
112
112
|
end
|
113
113
|
```
|
@@ -221,7 +221,53 @@ p client.chain_get_header(block_hash = nil)
|
|
221
221
|
...
|
222
222
|
```
|
223
223
|
|
224
|
+
## Docker
|
224
225
|
|
226
|
+
1. update to latest image
|
227
|
+
|
228
|
+
`docker pull itering/substrate_client:latest`
|
229
|
+
|
230
|
+
2. Run image:
|
231
|
+
|
232
|
+
`docker run -it itering/substrate_client:latest`
|
233
|
+
|
234
|
+
This will enter the container with a linux shell opened.
|
235
|
+
|
236
|
+
```shell
|
237
|
+
/usr/src/app #
|
238
|
+
```
|
239
|
+
|
240
|
+
3. Type `rspec` to run all tests
|
241
|
+
|
242
|
+
```shell
|
243
|
+
/usr/src/app # rspec
|
244
|
+
...................
|
245
|
+
|
246
|
+
Finished in 0.00883 seconds (files took 0.09656 seconds to load)
|
247
|
+
5 examples, 0 failures
|
248
|
+
```
|
249
|
+
|
250
|
+
4. Or, type `./bin/console` to enter the ruby interactive environment and run any decode or encode code
|
251
|
+
|
252
|
+
```shell
|
253
|
+
/usr/src/app # ./bin/console
|
254
|
+
[1] pry(main)> client = SubstrateClient.new("wss://kusama-rpc.polkadot.io/")
|
255
|
+
=> #<SubstrateClient:0x000055a78f124f58 ...
|
256
|
+
[2] pry(main)> client.method_list do |methods| p methods end
|
257
|
+
=> ...
|
258
|
+
[3] pry(main)> subscription = client.chain_subscribe_new_heads do |data| p data end
|
259
|
+
...
|
260
|
+
```
|
261
|
+
|
262
|
+
5. Or, SubstrateClientSync:
|
263
|
+
|
264
|
+
```shell
|
265
|
+
/usr/src/app # ./bin/console
|
266
|
+
[1] pry(main)> client = SubstrateClientSync.new("wss://kusama-rpc.polkadot.io/", spec_name: "kusama")
|
267
|
+
=> #<SubstrateClientSync:0x000055a78edfd6e0 @request_id=1, @spec_name="kusama", @url="wss://kusama-rpc.polkadot.io/">
|
268
|
+
[2] pry(main)> client.chain_get_head
|
269
|
+
=> "0xb3c3a220d4639b7c62f179f534b3a66336a115ebc18f13db053f0c57437c45fc"
|
270
|
+
```
|
225
271
|
|
226
272
|
## Development
|
227
273
|
|
data/lib/substrate_client.rb
CHANGED
@@ -46,6 +46,10 @@ class SubstrateClient
|
|
46
46
|
"id" => @request_id
|
47
47
|
}
|
48
48
|
|
49
|
+
while @callbacks.nil?
|
50
|
+
sleep(1)
|
51
|
+
end
|
52
|
+
|
49
53
|
@callbacks[@request_id] = proc do |data|
|
50
54
|
if not subscription_callback.nil? && data["result"]
|
51
55
|
@subscription_callbacks[data["result"]] = subscription_callback
|
@@ -80,7 +84,7 @@ class SubstrateClient
|
|
80
84
|
if data["error"]
|
81
85
|
Thread.main.raise RpcError, data["error"]
|
82
86
|
else
|
83
|
-
callback.call data["result"]
|
87
|
+
callback.call data["result"] unless callback.nil?
|
84
88
|
end
|
85
89
|
}
|
86
90
|
end
|
@@ -109,7 +113,7 @@ class SubstrateClient
|
|
109
113
|
invoke rpc_method(__method__), [], callback
|
110
114
|
end
|
111
115
|
|
112
|
-
def chain_get_finalised_head
|
116
|
+
def chain_get_finalised_head(&callback)
|
113
117
|
invoke rpc_method(__method__), [], callback
|
114
118
|
end
|
115
119
|
|
@@ -149,40 +153,40 @@ class SubstrateClient
|
|
149
153
|
request rpc_method(__method__), [], subscription_callback: callback
|
150
154
|
end
|
151
155
|
|
152
|
-
def chain_unsubscribe_all_heads(subscription
|
153
|
-
invoke rpc_method(__method__), [ subscription ],
|
156
|
+
def chain_unsubscribe_all_heads(subscription)
|
157
|
+
invoke rpc_method(__method__), [ subscription ], nil
|
154
158
|
end
|
155
159
|
|
156
160
|
def chain_subscribe_new_heads(&callback)
|
157
161
|
request rpc_method(__method__), [], subscription_callback: callback
|
158
162
|
end
|
159
163
|
|
160
|
-
def chain_unsubscribe_new_heads(subscription
|
161
|
-
invoke rpc_method(__method__), [ subscription ],
|
164
|
+
def chain_unsubscribe_new_heads(subscription)
|
165
|
+
invoke rpc_method(__method__), [ subscription ], nil
|
162
166
|
end
|
163
167
|
|
164
168
|
def chain_subscribe_finalized_heads(&callback)
|
165
169
|
request rpc_method(__method__), [], subscription_callback: callback
|
166
170
|
end
|
167
171
|
|
168
|
-
def chain_unsubscribe_finalized_heads(subscription
|
169
|
-
invoke rpc_method(__method__), [ subscription ],
|
172
|
+
def chain_unsubscribe_finalized_heads(subscription)
|
173
|
+
invoke rpc_method(__method__), [ subscription ], nil
|
170
174
|
end
|
171
175
|
|
172
176
|
def state_subscribe_runtime_version(&callback)
|
173
177
|
request rpc_method(__method__), [], subscription_callback: callback
|
174
178
|
end
|
175
179
|
|
176
|
-
def state_unsubscribe_runtime_version(subscription
|
177
|
-
invoke rpc_method(__method__), [ subscription ],
|
180
|
+
def state_unsubscribe_runtime_version(subscription)
|
181
|
+
invoke rpc_method(__method__), [ subscription ], nil
|
178
182
|
end
|
179
183
|
|
180
184
|
def state_subscribe_storage(keys, &callback)
|
181
185
|
request rpc_method(__method__), [keys], subscription_callback: callback
|
182
186
|
end
|
183
187
|
|
184
|
-
def state_unsubscribe_storage(subscription
|
185
|
-
invoke rpc_method(__method__), [ subscription ],
|
188
|
+
def state_unsubscribe_storage(subscription)
|
189
|
+
invoke rpc_method(__method__), [ subscription ], nil
|
186
190
|
end
|
187
191
|
|
188
192
|
# ################################################
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: substrate_client.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wu Minzhe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- ".rspec"
|
135
135
|
- ".travis.yml"
|
136
136
|
- CODE_OF_CONDUCT.md
|
137
|
+
- Dockerfile
|
137
138
|
- Gemfile
|
138
139
|
- Gemfile.lock
|
139
140
|
- LICENSE.txt
|