filecoin 0.1.0 → 0.2.0
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/.rubocop.yml +3 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile.lock +1 -1
- data/README.md +281 -6
- data/lib/filecoin.rb +12 -0
- data/lib/filecoin/client.rb +8 -3
- data/lib/filecoin/client/node.rb +26 -0
- data/lib/filecoin/http.rb +2 -1
- data/lib/filecoin/types.rb +3 -0
- data/lib/filecoin/types/cid.rb +28 -0
- data/lib/filecoin/types/data_ref.rb +28 -0
- data/lib/filecoin/types/start_deal_params.rb +30 -0
- data/lib/filecoin/version.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ef27efff91c40a5b52704f6a8aa63f2ede88e1d88e495444e8660e7746483538
|
|
4
|
+
data.tar.gz: 2ee28c49341b368e2cbab1dc872f72fb156da4217335a6a8e680ed0797a25992
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e603609b41f74c9cfa5fd06072ef859036f3d6fb8644283dd4b824098c05db1dc0cfec23e6b140f661629ee84ee04fc4203449e00757172cc48d8725eee4ca10
|
|
7
|
+
data.tar.gz: d50ba2023ebb16ebc76c03cc064eca582fb1cd40318d594d5d0e567bb535940f0a2a893dc80c3390274b1930f1b04766c324e0a5ffc583c7670147a38989a39d
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,28 @@ The format is based on [Keep a Changelog], and this project adheres to
|
|
|
10
10
|
Unreleased
|
|
11
11
|
----------
|
|
12
12
|
|
|
13
|
+
_Coming soon_
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
v0.2.0 - 2020-06-12
|
|
17
|
+
-------------------
|
|
18
|
+
|
|
19
|
+
- Expose the methods of `Filecoin::Client::Node` in `Filecoin` using its
|
|
20
|
+
default constructor (loads from environment variables);
|
|
21
|
+
- Add support for `Filecoin.ClientGetDealInfo` through
|
|
22
|
+
`Filecoin::Client#client_get_deal_info`;
|
|
23
|
+
- Add support for token authenticated API interaction;
|
|
24
|
+
- Add support for `Filecoin.ClientStartDeal` through
|
|
25
|
+
`Filecoin::Client#client_start_deal`;
|
|
26
|
+
- Add types for storage deal creation;
|
|
27
|
+
- Add support for `Filecoin.ClientQueryAsk` through
|
|
28
|
+
`Filecoin::Client#client_query_ask`;
|
|
29
|
+
- Add support for `Filecoin.NetPeers` through `Filecoin::Client#net_peers`.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
v0.1.0 - 2020-06-04
|
|
33
|
+
-------------------
|
|
34
|
+
|
|
13
35
|
- Add `Filecoin::Client` with `#chain_head` matching the `Filecoin.ChainHead`
|
|
14
36
|
method in the Filecoin Lotus Node API.
|
|
15
37
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Installation
|
|
|
10
10
|
Add this line to your application's Gemfile:
|
|
11
11
|
|
|
12
12
|
```ruby
|
|
13
|
-
gem "filecoin", "~> 0.
|
|
13
|
+
gem "filecoin", "~> 0.2.0"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
And then execute:
|
|
@@ -25,6 +25,19 @@ Or install it yourself as:
|
|
|
25
25
|
Usage
|
|
26
26
|
-----
|
|
27
27
|
|
|
28
|
+
```ruby
|
|
29
|
+
# FILECOIN_URL="https://filecoin.example.com:1234"
|
|
30
|
+
# FILECOIN_TOKEN="asdfghjkl"
|
|
31
|
+
Filecoin.chain_head
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`Filecoin` exposes all the API methods for applications that prefer to load
|
|
35
|
+
configuration from environment variables. These methods are implemented by
|
|
36
|
+
`Filecoin::Client` which is abstracted away in this case.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Client
|
|
40
|
+
|
|
28
41
|
Clients are initialized with the URI to the target API server. This URI can be
|
|
29
42
|
provided as a `URI` object, or as a `String`. If omitted, `Filecoin::Client`
|
|
30
43
|
defaults to the value of the `FILECOIN_URL` environment variable.
|
|
@@ -40,18 +53,268 @@ Filecoin::Client.new(uri: "https://filecoin.example.com:1234")
|
|
|
40
53
|
Filecoin::Client.new
|
|
41
54
|
```
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
`
|
|
56
|
+
Some methods in the [Filecoin Node API] require special [permissions]. To use
|
|
57
|
+
any such method, you'll have to provide your authentication token to the
|
|
58
|
+
client, either on initialization or through the `FILECOIN_TOKEN` environment
|
|
59
|
+
variable.
|
|
46
60
|
|
|
47
61
|
```ruby
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
# with a token String
|
|
63
|
+
Filecoin::Client.new(token: "asdfghjkl")
|
|
64
|
+
|
|
65
|
+
# from the FILECOIN_TOKEN environment variable
|
|
66
|
+
Filecoin::Client.new
|
|
50
67
|
```
|
|
51
68
|
|
|
69
|
+
For each supported method of the [Filecoin Node API] there is a respective
|
|
70
|
+
method in `Filecoin::Client`. For instance, to call `Filecoin.ChainHead` use
|
|
71
|
+
`Filecoin::Client#chain_head`.
|
|
72
|
+
|
|
73
|
+
Some methods require their parameters to follow a hard-to-describe structure.
|
|
74
|
+
In such cases, use the respective type class to make things simpler.
|
|
75
|
+
|
|
52
76
|
All methods return the server's JSON parsed response as a plain `Hash`.
|
|
53
77
|
|
|
54
78
|
|
|
79
|
+
### Supported Filecoin Node API methods
|
|
80
|
+
|
|
81
|
+
- [x] `Filecoin.ChainHead`
|
|
82
|
+
- [x] `Filecoin.ClientGetDealInfo`
|
|
83
|
+
- [x] `Filecoin.ClientQueryAsk`
|
|
84
|
+
- [x] `Filecoin.ClientStartDeal`
|
|
85
|
+
- [x] `Filecoin.NetPeers`
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
### Filecoin.ChainHead
|
|
89
|
+
|
|
90
|
+
Returns the current head of the chain.
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
Filecoin.chain_head
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"jsonrpc": "2.0",
|
|
99
|
+
"result": {
|
|
100
|
+
"Cids": [
|
|
101
|
+
{
|
|
102
|
+
"/": "bafy2bzaceabs2fnv5xehoibdik3bp3flze3v3mbxdprsu2yt5urpz3sd4sysk"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"Blocks": [
|
|
106
|
+
{
|
|
107
|
+
"Miner": "t01100",
|
|
108
|
+
"Ticket": {
|
|
109
|
+
"VRFProof": "koRyPdBso5iROYfkkLLS8BbkYkziPmao/DJsVTGWRC7gHz/RPSKG/LCjvcOylI+IEzCghQAHantaG96rUAwc5m08FBhYp9/zx/eZSce42ktfIGfO6lF1ymya3Tlzn2Xd"
|
|
110
|
+
},
|
|
111
|
+
"ElectionProof": {
|
|
112
|
+
"VRFProof": "qMwlLzao8BJn38wJ5/kxcorBNr1IGMpOedLYHV7y7g71vK5suKHIZsC66jtxvCLdFlqWKGsgBifbJkAo38NIPCD4cTiDBz5J3PzDLVAy8f0x3JV7BoaQVmmUr57BCiG+"
|
|
113
|
+
},
|
|
114
|
+
"BeaconEntries": [
|
|
115
|
+
{
|
|
116
|
+
"Round": 125398,
|
|
117
|
+
"Data": "hRPhxVhoujTf7wZoZ4zk/bucunZeEpF5Oi7O1Es1gnnYNBzHlesNhZ8GHfjsULTHFvOVngrawT5Y3P5u7sx2f7ysVfuh16jo1CFJu3KSFfilBXCmjRCKG6rC6KRhQVMO"
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"WinPoStProof": [
|
|
121
|
+
{
|
|
122
|
+
"RegisteredProof": 15,
|
|
123
|
+
"ProofBytes": "srmO6BOqe4lEh4RbVybhkEtH3wDV4QFl/h599QG3K5DZN2yZF77gy0Apaybjr/UgqUVoPPELOkW7HcZLLgSRXwbQ6dmKPnb5rC58ucK4tcab5tKbz6xk3jjoYkHC8tbjEETOmRYlOyvYFSmkkRbdT0aixosSRiecQv94SyiSTWwZ2hNrnDW6tsbqNd8WGTqCjbhvMvHFxFATXv2xu8ndQ+YjYrpuaY/HRz3NfLq0Gj1niqXawkAw2UgKh4aod79A"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"Parents": [
|
|
127
|
+
{
|
|
128
|
+
"/": "bafy2bzacec6osar3i62fr3u4dlw4bxns3sc4ycipjbo4u6u4tbgh6f7hwhypi"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"/": "bafy2bzaceblqc4nzzneqg5sd5ik23jnt77fhizm7mqj5ulcyxwlu6p7cftoam"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"ParentWeight": "1584010805",
|
|
135
|
+
"Height": 99565,
|
|
136
|
+
"ParentStateRoot": {
|
|
137
|
+
"/": "bafy2bzacecolsvk4s2pn7eeso7eobseqxs2x6vkkcenjyd6ikbk4hanmmr6oe"
|
|
138
|
+
},
|
|
139
|
+
"ParentMessageReceipts": {
|
|
140
|
+
"/": "bafy2bzaced3qvpgmcwl4qyxq2rwgmeduqhtnhdunwdisvyejup7vcqxi5cor2"
|
|
141
|
+
},
|
|
142
|
+
"Messages": {
|
|
143
|
+
"/": "bafy2bzaceavnr75wltzlp5eqi4er7u2f5c4halukuetqk2vmbqd7ltcms5cjs"
|
|
144
|
+
},
|
|
145
|
+
"BLSAggregate": {
|
|
146
|
+
"Type": 2,
|
|
147
|
+
"Data": "sXWOH7SeDDQeMTKIBewRGdNYlRGPchtj2iJlXNwZrRV/ukmlcl2yLA24fQhNy1lDDlKNZ+juGq6TyhYGimRMLCaAjCc50jfxOGEk1+uTpxb3QzxknpopWoDHEhCpPz59"
|
|
148
|
+
},
|
|
149
|
+
"Timestamp": 1591983325,
|
|
150
|
+
"BlockSig": {
|
|
151
|
+
"Type": 2,
|
|
152
|
+
"Data": "krAlrTcpd3QFNETCn2sTsXuqlIHCsmwss+iUziCE/F6mVs6UxZ/f43uyHjKRBojwFZRJKsdZV3JWfg+HrWcj51x5qBAwNwReCCOpJUBwEbLcdrUDyrGIzJ203g6r6YS7"
|
|
153
|
+
},
|
|
154
|
+
"ForkSignaling": 0
|
|
155
|
+
}
|
|
156
|
+
],
|
|
157
|
+
"Height": 99565
|
|
158
|
+
},
|
|
159
|
+
"id": 3
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
### Filecoin.ClientGetDealInfo
|
|
165
|
+
|
|
166
|
+
Get the information on a specific deal.
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
Filecoin.client_get_deal_info("bafyreigc4b4fqsval4pjmfncaqdezhe5y3anwavjyzpj4mar73e6n7mvj4")
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"jsonrpc": "2.0",
|
|
175
|
+
"result": {
|
|
176
|
+
"ProposalCid": {
|
|
177
|
+
"/": "bafyreigc4b4fqsval4pjmfncaqdezhe5y3anwavjyzpj4mar73e6n7mvj4"
|
|
178
|
+
},
|
|
179
|
+
"State": 5,
|
|
180
|
+
"Message": "",
|
|
181
|
+
"Provider": "t0239463",
|
|
182
|
+
"PieceCID": {
|
|
183
|
+
"/": "bafk4chzaw4zjxdl3d6vd7shbr23ps4nygl77ywogasvzskvn7jszur3tpetq"
|
|
184
|
+
},
|
|
185
|
+
"Size": 2080768,
|
|
186
|
+
"PricePerEpoch": "500000000",
|
|
187
|
+
"Duration": 1492,
|
|
188
|
+
"DealID": 2725
|
|
189
|
+
},
|
|
190
|
+
"id": 3
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
#### Understanding Deal State
|
|
196
|
+
|
|
197
|
+
The state of a deal has a numerical value which links it to a constant in the
|
|
198
|
+
Filecoin Lotus client. At the time of writing, these states are
|
|
199
|
+
([source][states]):
|
|
200
|
+
|
|
201
|
+
1. Unknown;
|
|
202
|
+
2. Proposal not found;
|
|
203
|
+
3. Proposal rejected;
|
|
204
|
+
4. Proposal accepted;
|
|
205
|
+
5. Deal staged;
|
|
206
|
+
6. Deal sealing;
|
|
207
|
+
7. Deal is active;
|
|
208
|
+
8. Deal is failing;
|
|
209
|
+
9. Deal not found;
|
|
210
|
+
10. Deal funds ensured — deposited funds as necessary to create a deal,
|
|
211
|
+
ready to move forward;
|
|
212
|
+
11. Waiting for data request — client is waiting for a request for the
|
|
213
|
+
deal data;
|
|
214
|
+
12. Deal validating — verifying that deal parameters are good;
|
|
215
|
+
13. Waiting for deal acceptance — deciding whether or not to accept the
|
|
216
|
+
deal;
|
|
217
|
+
14. Deal transferring — transferring data to the miner;
|
|
218
|
+
15. Waiting for data — for manual transfers;
|
|
219
|
+
16. Verifying transferred data — generate CAR / piece data;
|
|
220
|
+
17. Ensuring provider funds — checking collateral is sufficient;
|
|
221
|
+
18. Ensuring client funds — checking client funds are sufficient;
|
|
222
|
+
19. Waiting for funds to appear in provider balance;
|
|
223
|
+
20. Waiting for funds to appear in client balance;
|
|
224
|
+
21. Publishing deal to chain;
|
|
225
|
+
22. Waiting for deal to appear on chain;
|
|
226
|
+
23. Deal failed with an unexpected error;
|
|
227
|
+
24. Deal completed — the deal has reached the end of its duration.
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
### Filecoin.ClientQueryAsk
|
|
231
|
+
|
|
232
|
+
```ruby
|
|
233
|
+
Filecoin.client_query_ask(
|
|
234
|
+
# ID of the peer to query
|
|
235
|
+
"0003KooWBhDJkzmK1QKQqp7hRDAA9cLBNsneaYn2TBGdUSKXzoc8",
|
|
236
|
+
# ID of the miner to query about
|
|
237
|
+
"t1234567",
|
|
238
|
+
)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
### Filecoin.ClientStartDeal
|
|
243
|
+
|
|
244
|
+
This method requires the aid of some type classes due to the complex structure
|
|
245
|
+
of the payload. Make use of `Filecoin::Types::DataRef` to represent the data to
|
|
246
|
+
transfer for this deal, and then pass it on to
|
|
247
|
+
`Filecoin::Types::StartDealParams` to describe the deal to propose.
|
|
248
|
+
|
|
249
|
+
If successful, the response contains the CID of the proposed deal. Use
|
|
250
|
+
`Filecoin.ClientGetDealInfo` to query the network about its evolution.
|
|
251
|
+
|
|
252
|
+
```ruby
|
|
253
|
+
data_ref = Filecoin::Types::DataRef.new(
|
|
254
|
+
# (Optional) Define how the data will be transferred. Must be "graphsync" or
|
|
255
|
+
# "manual". Defaults to "graphsync".
|
|
256
|
+
transfer_type: "manual",
|
|
257
|
+
# CID of the file to transfer
|
|
258
|
+
root: "bafkreicomazccnbsql4nvtp6jfrk5qwys63ktakp4hkdt3ncl2hvhemwde",
|
|
259
|
+
# (Optional) Piece CID. Required for "manual" transfer deals.
|
|
260
|
+
piece_cid: "bafk4chzak7ieup5a3aup2vzavfzlnmbxxx4bpi3kpykhbkn4cdemdmk3aeaa",
|
|
261
|
+
# (Optional) Piece size. Required for "manual" transfer deals.
|
|
262
|
+
piece_size: 532_676_608,ClientGetDealInfo
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
start_deal_params = Filecoin::Types::StartDealParams.new(
|
|
266
|
+
# Description of the data the deal refers to
|
|
267
|
+
data: data_ref,
|
|
268
|
+
# Address of the wallet in the node to use to pay for the deal
|
|
269
|
+
wallet: "t13nqjc55m3h327646cwcu4lchdx4lkw7ccxnx4ca",
|
|
270
|
+
# Address ot the miner to whom this deal is to be proposed
|
|
271
|
+
miner: "t1234567",
|
|
272
|
+
# Price per block in attoFIL to propose for this deal
|
|
273
|
+
epoch_price: 500_000_000,
|
|
274
|
+
# (Optional) Duration of the deal in blocks
|
|
275
|
+
min_blocks_duration: 1572,
|
|
276
|
+
# (Optional) Unix timestamp stating the moment the deal starts
|
|
277
|
+
deal_start_epoch: 1591979600,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
Filecoin.client_start_deal(start_deal_params)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
```json
|
|
284
|
+
{
|
|
285
|
+
"jsonrpc": "2.0",
|
|
286
|
+
"result": {
|
|
287
|
+
"/": "bafyreihdss5rlzmft3lzez2n5jyxqo5znhewdvpbcnhbnairkc2yl6zk6e"
|
|
288
|
+
},
|
|
289
|
+
"id": 3
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
### Filecoin.NetPeers
|
|
295
|
+
|
|
296
|
+
Get the peers the node is connected to.
|
|
297
|
+
|
|
298
|
+
```ruby
|
|
299
|
+
Filecoin.net_peers
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
```json
|
|
303
|
+
{
|
|
304
|
+
"jsonrpc": "2.0",
|
|
305
|
+
"result": [
|
|
306
|
+
{
|
|
307
|
+
"Addrs": [
|
|
308
|
+
"/ip4/54.212.151.167/tcp/40817"
|
|
309
|
+
],
|
|
310
|
+
"ID": "12D3KooWGBxkba5Havy4wiGvLVmqPBCPjs7xPQPtqNr1HRq6RaVM"
|
|
311
|
+
}
|
|
312
|
+
],
|
|
313
|
+
"id": 3
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
|
|
55
318
|
Development
|
|
56
319
|
-----------
|
|
57
320
|
|
|
@@ -71,6 +334,15 @@ Contributing
|
|
|
71
334
|
Bug reports and pull requests are welcome on GitHub at
|
|
72
335
|
https://github.com/subvisual/filecoin-ruby.
|
|
73
336
|
|
|
337
|
+
This project was created to provide a Ruby interface for projects we at
|
|
338
|
+
Subvisual are actively working on. We are not aiming to provide an exaustive
|
|
339
|
+
interface for the time being, and will focus our development efforts as needed.
|
|
340
|
+
|
|
341
|
+
We welcome anyone interested in helping the development of this project to
|
|
342
|
+
contribute directly with a pull request. Otherwise, please feel free to request
|
|
343
|
+
any features you feel are missing in an issue. We will do our best to comply,
|
|
344
|
+
within reason and the limits of our own availability.
|
|
345
|
+
|
|
74
346
|
|
|
75
347
|
License
|
|
76
348
|
-----
|
|
@@ -90,6 +362,9 @@ filecoin-ruby was created and is maintained with :heart: by
|
|
|
90
362
|
[![Subvisual][subvisual-logo]][subvisual]
|
|
91
363
|
|
|
92
364
|
|
|
365
|
+
[Filecoin Node API]: https://github.com/filecoin-project/lotus/blob/master/api/api_full.go
|
|
366
|
+
[permissions]: https://lotu.sh/en+api#what-authorization-level-should-i-use-21853
|
|
367
|
+
[states]: https://github.com/filecoin-project/go-fil-markets/blob/095b388f830be66ceedc0965e5c7afcb1b96ad60/storagemarket/types.go#L30-L60
|
|
93
368
|
[license]: ./LICENSE.txt
|
|
94
369
|
[rubygems.org]: https://rubygems.org
|
|
95
370
|
[subvisual]: http://subvisual.com
|
data/lib/filecoin.rb
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
require "filecoin/client"
|
|
2
|
+
require "filecoin/types"
|
|
1
3
|
require "filecoin/version"
|
|
4
|
+
require "forwardable"
|
|
2
5
|
|
|
3
6
|
module Filecoin
|
|
7
|
+
class << self
|
|
8
|
+
extend Forwardable
|
|
9
|
+
|
|
10
|
+
def_delegators :client, *Client::Node.public_instance_methods
|
|
11
|
+
|
|
12
|
+
def client
|
|
13
|
+
Client.new
|
|
14
|
+
end
|
|
15
|
+
end
|
|
4
16
|
end
|
data/lib/filecoin/client.rb
CHANGED
|
@@ -5,10 +5,11 @@ module Filecoin
|
|
|
5
5
|
class Client
|
|
6
6
|
include Filecoin::Client::Node
|
|
7
7
|
|
|
8
|
-
attr_reader :uri
|
|
8
|
+
attr_reader :uri, :token
|
|
9
9
|
|
|
10
|
-
def initialize(uri: nil)
|
|
10
|
+
def initialize(uri: nil, token: nil)
|
|
11
11
|
@uri = initialize_uri(uri)
|
|
12
|
+
@token = initialize_token(token)
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
private
|
|
@@ -21,6 +22,10 @@ module Filecoin
|
|
|
21
22
|
URI(uri)
|
|
22
23
|
end
|
|
23
24
|
|
|
25
|
+
def initialize_token(token)
|
|
26
|
+
token || ENV["FILECOIN_TOKEN"]
|
|
27
|
+
end
|
|
28
|
+
|
|
24
29
|
def json_rpc_call(method, *params)
|
|
25
30
|
@json_rpc_call_id ||= 0
|
|
26
31
|
@json_rpc_call_id += 1
|
|
@@ -32,7 +37,7 @@ module Filecoin
|
|
|
32
37
|
id: @json_rpc_call_id,
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
Http.post(uri, body)
|
|
40
|
+
Http.post(uri, token, body)
|
|
36
41
|
end
|
|
37
42
|
end
|
|
38
43
|
end
|
data/lib/filecoin/client/node.rb
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
|
+
require "filecoin/types/cid"
|
|
2
|
+
|
|
1
3
|
module Filecoin
|
|
2
4
|
class Client
|
|
3
5
|
module Node
|
|
4
6
|
def chain_head
|
|
5
7
|
json_rpc_call "Filecoin.ChainHead"
|
|
6
8
|
end
|
|
9
|
+
|
|
10
|
+
def client_get_deal_info(deal_id)
|
|
11
|
+
params = Types::Cid.new(deal_id).as_json
|
|
12
|
+
|
|
13
|
+
json_rpc_call "Filecoin.ClientGetDealInfo", params
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def client_query_ask(peer_id, miner_id)
|
|
17
|
+
json_rpc_call "Filecoin.ClientQueryAsk", peer_id, miner_id
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def client_start_deal(start_deal_params)
|
|
21
|
+
params = if start_deal_params.is_a?(Hash)
|
|
22
|
+
start_deal_params
|
|
23
|
+
else
|
|
24
|
+
start_deal_params.as_json
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
json_rpc_call("Filecoin.ClientStartDeal", params)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def net_peers
|
|
31
|
+
json_rpc_call "Filecoin.NetPeers"
|
|
32
|
+
end
|
|
7
33
|
end
|
|
8
34
|
end
|
|
9
35
|
end
|
data/lib/filecoin/http.rb
CHANGED
|
@@ -4,11 +4,12 @@ require "net/http"
|
|
|
4
4
|
module Filecoin
|
|
5
5
|
module Http
|
|
6
6
|
module ClassMethods
|
|
7
|
-
def post(uri, data)
|
|
7
|
+
def post(uri, token, data)
|
|
8
8
|
return if uri.nil?
|
|
9
9
|
|
|
10
10
|
req = Net::HTTP::Post.new(uri)
|
|
11
11
|
req["Content-Type"] = "application/json"
|
|
12
|
+
req["Authorization"] = "Bearer #{token}" unless token.nil?
|
|
12
13
|
req.body = data.to_json
|
|
13
14
|
|
|
14
15
|
response = request(req)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Filecoin
|
|
2
|
+
module Types
|
|
3
|
+
class Cid
|
|
4
|
+
attr_reader :target
|
|
5
|
+
|
|
6
|
+
def self.new(target)
|
|
7
|
+
return nil if target.nil?
|
|
8
|
+
return target if target.is_a?(Cid)
|
|
9
|
+
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize(target)
|
|
14
|
+
@target = target
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def valid?
|
|
18
|
+
!target.nil? && !target.empty?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def as_json
|
|
22
|
+
{
|
|
23
|
+
"/" => target,
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "filecoin/types/cid"
|
|
2
|
+
|
|
3
|
+
module Filecoin
|
|
4
|
+
module Types
|
|
5
|
+
class DataRef
|
|
6
|
+
attr_reader :transfer_type, :root, :piece_cid, :piece_size
|
|
7
|
+
|
|
8
|
+
def initialize(transfer_type: nil, root:, piece_cid: nil, piece_size: nil)
|
|
9
|
+
@transfer_type = transfer_type
|
|
10
|
+
@root = Cid.new(root)
|
|
11
|
+
@piece_cid = Cid.new(piece_cid)
|
|
12
|
+
@piece_size = piece_size
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def as_json
|
|
16
|
+
hash = {
|
|
17
|
+
"Root" => root.as_json,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
hash["TransferType"] = transfer_type unless transfer_type.nil?
|
|
21
|
+
hash["PieceCID"] = piece_cid.as_json unless piece_cid.nil?
|
|
22
|
+
hash["PieceSize"] = piece_size unless piece_size.nil?
|
|
23
|
+
|
|
24
|
+
hash
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Filecoin
|
|
2
|
+
module Types
|
|
3
|
+
class StartDealParams
|
|
4
|
+
attr_reader :data, :wallet, :miner, :epoch_price, :min_blocks_duration, :deal_start_epoch
|
|
5
|
+
|
|
6
|
+
def initialize(data:, wallet:, miner:, epoch_price:, min_blocks_duration: nil, deal_start_epoch: nil)
|
|
7
|
+
@data = data
|
|
8
|
+
@wallet = wallet
|
|
9
|
+
@miner = miner
|
|
10
|
+
@epoch_price = epoch_price
|
|
11
|
+
@min_blocks_duration = min_blocks_duration
|
|
12
|
+
@deal_start_epoch = deal_start_epoch
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def as_json
|
|
16
|
+
hash = {
|
|
17
|
+
"Data" => data.as_json,
|
|
18
|
+
"Wallet" => wallet,
|
|
19
|
+
"Miner" => miner,
|
|
20
|
+
"EpochPrice" => epoch_price.to_s,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
hash["MinBlocksDuration"] = min_blocks_duration unless min_blocks_duration.nil?
|
|
24
|
+
hash["DealStartEpoch"] = deal_start_epoch unless deal_start_epoch.nil?
|
|
25
|
+
|
|
26
|
+
hash
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/filecoin/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: filecoin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pedro Costa
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-06-
|
|
11
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
Filecoin (https://filecoin.io/) is a distributed storage network based on a
|
|
@@ -47,6 +47,10 @@ files:
|
|
|
47
47
|
- lib/filecoin/client.rb
|
|
48
48
|
- lib/filecoin/client/node.rb
|
|
49
49
|
- lib/filecoin/http.rb
|
|
50
|
+
- lib/filecoin/types.rb
|
|
51
|
+
- lib/filecoin/types/cid.rb
|
|
52
|
+
- lib/filecoin/types/data_ref.rb
|
|
53
|
+
- lib/filecoin/types/start_deal_params.rb
|
|
50
54
|
- lib/filecoin/version.rb
|
|
51
55
|
homepage: https://github.com/subvisual/filecoin-ruby
|
|
52
56
|
licenses: []
|
|
@@ -54,7 +58,7 @@ metadata:
|
|
|
54
58
|
homepage_uri: https://github.com/subvisual/filecoin-ruby
|
|
55
59
|
source_code_uri: https://github.com/subvisual/filecoin-ruby
|
|
56
60
|
changelog_uri: https://github.com/subvisual/filecoin-ruby/blob/master/CHANGELOG.md
|
|
57
|
-
post_install_message:
|
|
61
|
+
post_install_message:
|
|
58
62
|
rdoc_options: []
|
|
59
63
|
require_paths:
|
|
60
64
|
- lib
|
|
@@ -70,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
70
74
|
version: '0'
|
|
71
75
|
requirements: []
|
|
72
76
|
rubygems_version: 3.1.2
|
|
73
|
-
signing_key:
|
|
77
|
+
signing_key:
|
|
74
78
|
specification_version: 4
|
|
75
79
|
summary: Interact with the Filecoin network
|
|
76
80
|
test_files: []
|