filecoin 0.3.0 → 0.4.0

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: 51d924d8ec129371f94374405e003a802de0b7952fdeb9ae8eec0df93ed4f2f1
4
- data.tar.gz: d3f27b9ee0a0a5b252d6523740be7d3fb2302a89ea528503e9081f7cbcb7d328
3
+ metadata.gz: 7159b291af21ca88add75488b10ac6700be6abbbde528b04aa880efa208ba480
4
+ data.tar.gz: 21f88799b03a576802cb03bd00b1680615c86b5fb2557b68bbe1fb729c0f8fc2
5
5
  SHA512:
6
- metadata.gz: a6021bf20aa984240b5839418aa29913007e40889f9dbbae25ec9a1a84a74577ba771fe6b9ad548f9312b7088cf957f3f6ec5d8643168a364e876ef64e6ecad3
7
- data.tar.gz: d893ffd092e50be52cd458eb0e277897df5305ce670d0134da287a62cf658afd39e8f6dec200e66920dde56b86e53ec29117ce223b916d26488f8b35957610ad
6
+ metadata.gz: 5d719cd23a5178285a70ffc2589fa14fe56c39aefed45cef6398faa5a7d7b6271ea7e2d6bac21ed89b1234f48bcdabe293dbce1b7d540f3863e221ccaeefb102
7
+ data.tar.gz: 5d6d6a5e5c81ce3fab7373edf35c9d2a2e69784f7f512043a8508ea1e3c501fafb5fdff5e8565dc63f43689c8524bb52936af98f85c18c2816c4d71e0599b66f
@@ -10,6 +10,19 @@ 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.4.0 - 2020-09-18
17
+ -------------------
18
+
19
+ - Add support `Filecoin.StateMinerPower` without any miner information, to
20
+ obtain the network's aggregate mining power.
21
+
22
+
23
+ v0.3.0 - 2020-07-07
24
+ -------------------
25
+
13
26
  - Add optional argument to extract the deal CID automatically from the response
14
27
  when submitting a proposal;
15
28
  - Make wallet for deal proposals optional, falling back on the configured
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- filecoin (0.3.0)
4
+ filecoin (0.4.0)
5
5
  dry-struct (~> 1.0)
6
6
 
7
7
  GEM
@@ -25,7 +25,7 @@ GEM
25
25
  concurrent-ruby (~> 1.0)
26
26
  dry-equalizer (0.3.0)
27
27
  dry-inflector (0.2.0)
28
- dry-logic (1.0.6)
28
+ dry-logic (1.0.7)
29
29
  concurrent-ruby (~> 1.0)
30
30
  dry-core (~> 0.2)
31
31
  dry-equalizer (~> 0.2)
data/README.md CHANGED
@@ -12,7 +12,7 @@ Installation
12
12
  Add this line to your application's Gemfile:
13
13
 
14
14
  ```ruby
15
- gem "filecoin", "~> 0.2.0"
15
+ gem "filecoin", "~> 0.3.0"
16
16
  ```
17
17
 
18
18
  And then execute:
@@ -86,313 +86,8 @@ All methods return the server's JSON parsed response as a plain `Hash`.
86
86
  - [x] `Filecoin.ClientStartDeal`
87
87
  - [x] `Filecoin.NetPeers`
88
88
 
89
-
90
- ### Filecoin.ChainHead
91
-
92
- Returns the current head of the chain.
93
-
94
- ```ruby
95
- Filecoin.chain_head
96
- ```
97
-
98
- ```json
99
- {
100
- "jsonrpc": "2.0",
101
- "result": {
102
- "Cids": [
103
- {
104
- "/": "bafy2bzaceabs2fnv5xehoibdik3bp3flze3v3mbxdprsu2yt5urpz3sd4sysk"
105
- }
106
- ],
107
- "Blocks": [
108
- {
109
- "Miner": "t01100",
110
- "Ticket": {
111
- "VRFProof": "koRyPdBso5iROYfkkLLS8BbkYkziPmao/DJsVTGWRC7gHz/RPSKG/LCjvcOylI+IEzCghQAHantaG96rUAwc5m08FBhYp9/zx/eZSce42ktfIGfO6lF1ymya3Tlzn2Xd"
112
- },
113
- "ElectionProof": {
114
- "VRFProof": "qMwlLzao8BJn38wJ5/kxcorBNr1IGMpOedLYHV7y7g71vK5suKHIZsC66jtxvCLdFlqWKGsgBifbJkAo38NIPCD4cTiDBz5J3PzDLVAy8f0x3JV7BoaQVmmUr57BCiG+"
115
- },
116
- "BeaconEntries": [
117
- {
118
- "Round": 125398,
119
- "Data": "hRPhxVhoujTf7wZoZ4zk/bucunZeEpF5Oi7O1Es1gnnYNBzHlesNhZ8GHfjsULTHFvOVngrawT5Y3P5u7sx2f7ysVfuh16jo1CFJu3KSFfilBXCmjRCKG6rC6KRhQVMO"
120
- }
121
- ],
122
- "WinPoStProof": [
123
- {
124
- "RegisteredProof": 15,
125
- "ProofBytes": "srmO6BOqe4lEh4RbVybhkEtH3wDV4QFl/h599QG3K5DZN2yZF77gy0Apaybjr/UgqUVoPPELOkW7HcZLLgSRXwbQ6dmKPnb5rC58ucK4tcab5tKbz6xk3jjoYkHC8tbjEETOmRYlOyvYFSmkkRbdT0aixosSRiecQv94SyiSTWwZ2hNrnDW6tsbqNd8WGTqCjbhvMvHFxFATXv2xu8ndQ+YjYrpuaY/HRz3NfLq0Gj1niqXawkAw2UgKh4aod79A"
126
- }
127
- ],
128
- "Parents": [
129
- {
130
- "/": "bafy2bzacec6osar3i62fr3u4dlw4bxns3sc4ycipjbo4u6u4tbgh6f7hwhypi"
131
- },
132
- {
133
- "/": "bafy2bzaceblqc4nzzneqg5sd5ik23jnt77fhizm7mqj5ulcyxwlu6p7cftoam"
134
- }
135
- ],
136
- "ParentWeight": "1584010805",
137
- "Height": 99565,
138
- "ParentStateRoot": {
139
- "/": "bafy2bzacecolsvk4s2pn7eeso7eobseqxs2x6vkkcenjyd6ikbk4hanmmr6oe"
140
- },
141
- "ParentMessageReceipts": {
142
- "/": "bafy2bzaced3qvpgmcwl4qyxq2rwgmeduqhtnhdunwdisvyejup7vcqxi5cor2"
143
- },
144
- "Messages": {
145
- "/": "bafy2bzaceavnr75wltzlp5eqi4er7u2f5c4halukuetqk2vmbqd7ltcms5cjs"
146
- },
147
- "BLSAggregate": {
148
- "Type": 2,
149
- "Data": "sXWOH7SeDDQeMTKIBewRGdNYlRGPchtj2iJlXNwZrRV/ukmlcl2yLA24fQhNy1lDDlKNZ+juGq6TyhYGimRMLCaAjCc50jfxOGEk1+uTpxb3QzxknpopWoDHEhCpPz59"
150
- },
151
- "Timestamp": 1591983325,
152
- "BlockSig": {
153
- "Type": 2,
154
- "Data": "krAlrTcpd3QFNETCn2sTsXuqlIHCsmwss+iUziCE/F6mVs6UxZ/f43uyHjKRBojwFZRJKsdZV3JWfg+HrWcj51x5qBAwNwReCCOpJUBwEbLcdrUDyrGIzJ203g6r6YS7"
155
- },
156
- "ForkSignaling": 0
157
- }
158
- ],
159
- "Height": 99565
160
- },
161
- "id": 3
162
- }
163
- ```
164
-
165
-
166
- ### Filecoin.ClientGetDealInfo
167
-
168
- Get the information on a specific deal.
169
-
170
- ```ruby
171
- Filecoin.client_get_deal_info("bafyreigc4b4fqsval4pjmfncaqdezhe5y3anwavjyzpj4mar73e6n7mvj4")
172
- ```
173
-
174
- ```json
175
- {
176
- "jsonrpc": "2.0",
177
- "result": {
178
- "ProposalCid": {
179
- "/": "bafyreigc4b4fqsval4pjmfncaqdezhe5y3anwavjyzpj4mar73e6n7mvj4"
180
- },
181
- "State": 5,
182
- "Message": "",
183
- "Provider": "t0239463",
184
- "PieceCID": {
185
- "/": "bafk4chzaw4zjxdl3d6vd7shbr23ps4nygl77ywogasvzskvn7jszur3tpetq"
186
- },
187
- "Size": 2080768,
188
- "PricePerEpoch": "500000000",
189
- "Duration": 1492,
190
- "DealID": 2725
191
- },
192
- "id": 3
193
- }
194
- ```
195
-
196
-
197
- #### Understanding Deal State
198
-
199
- The state of a deal has a numerical value which links it to a constant in the
200
- Filecoin Lotus client. At the time of writing, these states are
201
- ([source][states]):
202
-
203
- | Value | State | Description |
204
- | :---: | :--- | :--- |
205
- | 0 | Unknown | Status of the deal is undefined. |
206
- | 1 | Not found | Deal can not be located. |
207
- | 2 | Proposal rejected | Storage miner chose not to accept this deal proposal. |
208
- | 3 | Proposal accepted | Storage miner chose to accept this deal proposal. |
209
- | 4 | Staged | Deal has been published and data is ready to be put into a sector. |
210
- | 5 | Sealing | Deal is in sector that's being sealed. |
211
- | 6 | Active | Deal is in a sealed sector and the miner is providing proofs for this deal. |
212
- | 7 | Expired | Deal has passed its final epoch and is expired. |
213
- | 8 | Slashed | Deal was in a sector that got slashed from failing to produce proofs. |
214
- | 9 | Failing | Something has gone wrong in the deal. Data is being cleaned. |
215
- | 10 | Funds ensured | The funds necessary to create the deal have been deposited. |
216
- | 11 | Waiting for data request | Client is waiting for provider to request the deal data. |
217
- | 12 | Validating | Storage provider is validating whether the deal parameters are good for a proposal. |
218
- | 13 | Waiting for acceptance | Storage provider is running some custom decision logic to decide whether to accept the deal. |
219
- | 14 | Transferring | Data is being sent from the client to the storage provider. |
220
- | 15 | Waiting for data | Deal is for a manual data transfer, or the storage provider has not yet received a request to transfer data from the client. |
221
- | 16 | Verifying data | Data has been transferred and the storage provider is verifying it against the provided piece CID. |
222
- | 17 | Ensure provider funds | Storage provider is making sure it has adequate funds for the deal. |
223
- | 18 | Ensure client funds | Client is making sure it has adequate funds for the deal. |
224
- | 19 | Provider is funding | Storage provider has deposited funds and is waiting for funds to show up in balance. |
225
- | 20 | Client is funding | Client has deposited funds and is waiting for funds to show up in balance. |
226
- | 21 | Publish | Deal is ready to be published on chain. |
227
- | 22 | Publishing | Deal has been published, currently waiting for it to appear on chain. |
228
- | 23 | Error | Deal has failed due to an error, no further updates will occur. |
229
- | 24 | Completed | Deal is active and information for retrieval is recorded. |
230
-
231
- The lifecycle of a deal is slightly different from the point-of-view of the
232
- client (the node proposing a deal) and the miner. Please refer to [the
233
- storage market technical documentation] for up-to-date diagrams.
234
-
235
- This gem provides an abstraction in `Filecoin::Deals::State` of the **client
236
- deal lifecycle** reducing them to 4 general states for general deal
237
- health-checks and tracking.
238
-
239
- <table>
240
- <thead>
241
- <tr>
242
- <th>Abstract State</th>
243
- <th>Description</th>
244
- <th>Positive States</th>
245
- </tr>
246
- </thead>
247
- <tbody>
248
- <tr>
249
- <td>Pending</td>
250
- <td>Deal has been proposed and is pending acceptance or rejection.</td>
251
- <td>
252
- <ul>
253
- <li>Ensure client funds</li>
254
- <li>Client is funding</li>
255
- <li>Funds ensured</li>
256
- <li>Waiting for data</li>
257
- <li>Transferring</li>
258
- <li>Validating</li>
259
- </ul>
260
- </td>
261
- </tr>
262
- <tr>
263
- <td>Good</td>
264
- <td>Deal has been accepted and is active or on its way to become active.</td>
265
- <td>
266
- <ul>
267
- <li>Proposal accepted</li>
268
- <li>Sealing</li>
269
- <li>Active</li>
270
- </ul>
271
- </td>
272
- </tr>
273
- <tr>
274
- <td>Bad</td>
275
- <td>Something has gone wrong with the deal and it is now invalid.</td>
276
- <td>
277
- <ul>
278
- <li>Failing</li>
279
- <li>Error</li>
280
- </ul>
281
- </td>
282
- </tr>
283
- <tr>
284
- <td>Finished</td>
285
- <td>The deal has followed its natural course and is no longer active.</td>
286
- <td>
287
- <ul>
288
- <li>Slashed</li>
289
- <li>Expired</li>
290
- </ul>
291
- </td>
292
- </tr>
293
- </tbody>
294
- </table>
295
-
296
- To make use of this abstraction, initialize `Filecoin::Deal` with the result
297
- of `Filecoin.ClientGetDealInfo`.
298
-
299
- ```ruby
300
- response = Filecoin.client_get_deal_info("bafyreigc4b4fqsval4pjmfncaqdezhe5y3anwavjyzpj4mar73e6n7mvj4")
301
- deal = Filecoin::Deal.new(response["result"])
302
- ```
303
-
304
-
305
- ### Filecoin.ClientQueryAsk
306
-
307
- ```ruby
308
- Filecoin.client_query_ask(
309
- # ID of the peer to query
310
- "0003KooWBhDJkzmK1QKQqp7hRDAA9cLBNsneaYn2TBGdUSKXzoc8",
311
- # ID of the miner to query about
312
- "t1234567",
313
- )
314
- ```
315
-
316
-
317
- ### Filecoin.ClientStartDeal
318
-
319
- This method requires the aid of some type classes due to the complex structure
320
- of the payload. Make use of `Filecoin::Types::DataRef` to represent the data to
321
- transfer for this deal, and then pass it on to
322
- `Filecoin::Types::StartDealParams` to describe the deal to propose.
323
-
324
- If successful, the response contains the CID of the proposed deal. Use
325
- `Filecoin.ClientGetDealInfo` to query the network about its evolution.
326
-
327
- ```ruby
328
- data_ref = Filecoin::Types::DataRef.new(
329
- # (Optional) Define how the data will be transferred. Must be "graphsync" or
330
- # "manual". Defaults to "graphsync".
331
- transfer_type: "manual",
332
- # CID of the file to transfer
333
- root: "bafkreicomazccnbsql4nvtp6jfrk5qwys63ktakp4hkdt3ncl2hvhemwde",
334
- # (Optional) Piece CID. Required for "manual" transfer deals.
335
- piece_cid: "bafk4chzak7ieup5a3aup2vzavfzlnmbxxx4bpi3kpykhbkn4cdemdmk3aeaa",
336
- # (Optional) Piece size. Required for "manual" transfer deals.
337
- piece_size: 532_676_608,ClientGetDealInfo
338
- )
339
-
340
- start_deal_params = Filecoin::Types::StartDealParams.new(
341
- # Description of the data the deal refers to
342
- data: data_ref,
343
- # Address of the wallet in the node to use to pay for the deal
344
- # (optional if `Filecoin.config.default_wallet` is set)
345
- wallet: "t13nqjc55m3h327646cwcu4lchdx4lkw7ccxnx4ca",
346
- # Address ot the miner to whom this deal is to be proposed
347
- miner: "t1234567",
348
- # Price per block in attoFIL to propose for this deal
349
- epoch_price: 500_000_000,
350
- # (Optional) Duration of the deal in blocks
351
- min_blocks_duration: 1572,
352
- # (Optional) Unix timestamp stating the moment the deal starts
353
- deal_start_epoch: 1591979600,
354
- )
355
-
356
- Filecoin.client_start_deal(start_deal_params, extract_response: false)
357
- ```
358
-
359
- ```json
360
- {
361
- "jsonrpc": "2.0",
362
- "result": {
363
- "/": "bafyreihdss5rlzmft3lzez2n5jyxqo5znhewdvpbcnhbnairkc2yl6zk6e"
364
- },
365
- "id": 3
366
- }
367
- ```
368
-
369
- This method accepts an optional keyword argument `extract_response`. If truthy,
370
- the method returns the deal CID directly, or `nil`, instead of the JSON RPC
371
- full response. Defaults to `false`.
372
-
373
-
374
- ### Filecoin.NetPeers
375
-
376
- Get the peers the node is connected to.
377
-
378
- ```ruby
379
- Filecoin.net_peers
380
- ```
381
-
382
- ```json
383
- {
384
- "jsonrpc": "2.0",
385
- "result": [
386
- {
387
- "Addrs": [
388
- "/ip4/54.212.151.167/tcp/40817"
389
- ],
390
- "ID": "12D3KooWGBxkba5Havy4wiGvLVmqPBCPjs7xPQPtqNr1HRq6RaVM"
391
- }
392
- ],
393
- "id": 3
394
- }
395
- ```
89
+ For more information on each supported method, check
90
+ [the wiki](https://github.com/subvisual/filecoin-ruby/wiki/Supported-Methods).
396
91
 
397
92
 
398
93
  Development
@@ -444,8 +139,6 @@ filecoin-ruby was created and is maintained with :heart: by
444
139
 
445
140
  [Filecoin Node API]: https://github.com/filecoin-project/lotus/blob/master/api/api_full.go
446
141
  [permissions]: https://lotu.sh/en+api#what-authorization-level-should-i-use-21853
447
- [states]: https://github.com/filecoin-project/go-fil-markets/blob/master/storagemarket/dealstatus.go
448
- [the storage market technical documentation]: https://github.com/filecoin-project/go-fil-markets/tree/master/storagemarket#technical-documentation
449
142
  [license]: ./LICENSE.txt
450
143
  [rubygems.org]: https://rubygems.org
451
144
  [subvisual]: http://subvisual.com
@@ -1,4 +1,5 @@
1
1
  require "filecoin/types/cid"
2
+ require "filecoin/types/power_claim"
2
3
 
3
4
  module Filecoin
4
5
  class Client
@@ -32,6 +33,16 @@ module Filecoin
32
33
  def net_peers
33
34
  json_rpc_call "Filecoin.NetPeers"
34
35
  end
36
+
37
+ def state_power(extract_response: false)
38
+ response = json_rpc_call "Filecoin.StateMinerPower", nil, nil
39
+
40
+ if extract_response
41
+ Types::PowerClaim.from_as_json(response.dig("result", "TotalPower"))
42
+ else
43
+ response
44
+ end
45
+ end
35
46
  end
36
47
  end
37
48
  end
@@ -0,0 +1,23 @@
1
+ module Filecoin
2
+ module Types
3
+ class PowerClaim
4
+ module ClassMethods
5
+ def from_as_json(as_json)
6
+ new(
7
+ quality_adjusted_power: Integer(as_json["QualityAdjPower"]),
8
+ raw_byte_power: Integer(as_json["RawBytePower"]),
9
+ )
10
+ end
11
+ end
12
+
13
+ extend ClassMethods
14
+
15
+ # raw_byte_power: Sum of raw byte power for a miner's (or of all miners') sectors
16
+ # quality_adjusted_power: Sum of quality adjusted power for a miner's (or of all miners') sectors.
17
+ def initialize(quality_adjusted_power:, raw_byte_power:)
18
+ @quality_adjusted_power = quality_adjusted_power
19
+ @raw_byte_power = raw_byte_power
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Filecoin
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Costa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -68,6 +68,7 @@ files:
68
68
  - lib/filecoin/types.rb
69
69
  - lib/filecoin/types/cid.rb
70
70
  - lib/filecoin/types/data_ref.rb
71
+ - lib/filecoin/types/power_claim.rb
71
72
  - lib/filecoin/types/start_deal_params.rb
72
73
  - lib/filecoin/version.rb
73
74
  homepage: https://github.com/subvisual/filecoin-ruby