3
3
4
4
#pragma once
5
5
#include < inttypes.h>
6
+ #include " api/full_node/node_api.hpp"
6
7
#include " cli/node/node.hpp"
7
8
#include " markets/storage/mk_protocol.hpp"
8
9
#include " primitives/chain_epoch/chain_epoch.hpp"
14
15
#include " vm/actor/actor.hpp"
15
16
#include " vm/actor/builtin/states/verified_registry/verified_registry_actor_state.hpp"
16
17
#include " vm/actor/builtin/v0/verified_registry/verified_registry_actor.hpp"
18
+ #include " common/enum.hpp"
17
19
18
20
namespace fc ::cli::_node {
19
21
using api::FileRef;
20
22
using api::FullNodeApi;
21
23
using api::ImportRes;
22
24
using api::RetrievalOrder;
25
+ using api::StartDealParams;
23
26
using boost::lexical_cast;
24
27
using ::fc::storage::car::makeCar;
25
28
using ::fc::storage::unixfs::wrapFile;
@@ -31,12 +34,13 @@ namespace fc::cli::_node {
31
34
using primitives::piece::UnpaddedPieceSize;
32
35
using proofs::padPiece;
33
36
using storage::ipfs::ApiIpfsDatastore;
37
+ using vm::VMExitCode;
34
38
using vm::actor::kVerifiedRegistryAddress ;
35
39
using vm::actor::builtin::states::VerifiedRegistryActorStatePtr;
36
- using vm::VMExitCode;
37
-
38
- const ChainEpoch kLoopback = 100 ; // TODO: lookback
40
+ using markets::storage::StorageDealStatus;
41
+ using common::toString;
39
42
43
+ const ChainEpoch kLoopback = 100 ; // TODO: lookback
40
44
41
45
StoragePower checkNotary (std::shared_ptr<FullNodeApi> api,
42
46
const Address &vaddr) {
@@ -223,16 +227,42 @@ namespace fc::cli::_node {
223
227
auto duration{cliArgv<ChainEpoch>(
224
228
argv, 3 , " is a period of storing the data for, in blocks" )};
225
229
Node::Api api{argm};
226
- if (duration < kMinDealDuration ) throw CliError (" Minimal deal duration is {}" , kMinDealDuration );
227
- if (duration < kMaxDealDuration ) throw CliError (" Max deal duration is {}" , kMaxDealDuration );
228
-
230
+ if (duration < kMinDealDuration )
231
+ throw CliError (" Minimal deal duration is {}" , kMinDealDuration );
232
+ if (duration < kMaxDealDuration )
233
+ throw CliError (" Max deal duration is {}" , kMaxDealDuration );
234
+ DataRef data_ref;
229
235
Address address_from =
230
236
args.from ? *args.from : cliTry (api._ ->WalletDefaultAddress ());
231
- UnpaddedPieceSize piece_size{*args.man_piece_size };
232
- DataRef data_ref = {.transfer_type = " graphsync" ,
233
- .root = data_cid,
234
- .piece_cid = *args.man_piece_cid ,
235
- .piece_size = piece_size};
237
+ if (args.man_piece_cid ) {
238
+ UnpaddedPieceSize piece_size{*args.man_piece_size };
239
+ data_ref = {.transfer_type = " manual" ,
240
+ .root = data_cid,
241
+ .piece_cid = *args.man_piece_cid ,
242
+ .piece_size = piece_size};
243
+ } else {
244
+ data_ref = {.transfer_type = " graphsync" , .root = data_cid};
245
+ }
246
+ auto dcap =
247
+ cliTry (api._ ->StateVerifiedClientStatus (address_from, TipsetKey ()),
248
+ " Failed to get status of {}" ,
249
+ address_from);
250
+ bool isVerified = dcap.has_value ();
251
+ if (args.verified_deal && !isVerified)
252
+ throw CliError (
253
+ " Cannot perform verified deal using unverified address {}" ,
254
+ address_from);
255
+ StartDealParams deal_params = {.data = data_ref,
256
+ .wallet = address_from,
257
+ .miner = miner,
258
+ .epoch_price = price,
259
+ .min_blocks_duration = duration,
260
+ .deal_start_epoch = *args.start_epoch ,
261
+ .fast_retrieval = args.fast_ret ,
262
+ .verified_deal = isVerified,
263
+ .provider_collateral = *args.collateral };
264
+ auto proposal_cid = cliTry (api._ ->ClientStartDeal (deal_params));
265
+ fmt::print (" Deal proposal CID: {}\n " , cliTry (proposal_cid.toString (), " Cannot extract CID" ));
236
266
}
237
267
};
238
268
@@ -363,6 +393,7 @@ namespace fc::cli::_node {
363
393
364
394
<<<<<<< HEAD
365
395
<<<<<<< HEAD
396
+ <<<<<<< HEAD
366
397
367
398
368
399
<<<<<<< HEAD
@@ -377,6 +408,9 @@ namespace fc::cli::_node {
377
408
=======
378
409
struct Node_client_inspectDeal { // TODO: continue
379
410
>>>>>>> 3d9435d6 (FFi+ and client updates)
411
+ =======
412
+ struct Node_client_inspectDeal { // TODO: continue
413
+ >>>>>>> ad42f96d (ClientUpdates, DealStatus enum conversion)
380
414
struct Args {
381
415
CLI_OPTIONAL (" proposal-cid" , " proposal cid of deal to be inspected" , CID)
382
416
proposal_cid;
@@ -393,25 +427,33 @@ namespace fc::cli::_node {
393
427
}
394
428
};
395
429
396
- struct Node_client_dealStats {
430
+ struct Node_client_dealStats {
397
431
struct Args {
398
432
CLI_DEFAULT (" newer-than" ,
399
433
" list all deals stas that was made after given period" ,
400
434
ChainEpoch,
401
- {0 })newer;
402
- CLI_OPTS (){
435
+ {0 })
436
+ newer;
437
+ CLI_OPTS () {
403
438
Opts opts;
404
439
newer (opts);
405
440
return opts;
406
441
}
407
442
};
408
- CLI_RUN (){
443
+ CLI_RUN () {
409
444
Node::Api api{argm};
410
445
auto deals = cliTry (api._ ->ClientListDeals ());
411
- for (const auto deal: deals){
412
-
413
- }// TODO: Continue
414
-
446
+ uint64_t total_size{0 };
447
+ std::map<StorageDealStatus, uint64_t > by_state;
448
+ for (const auto &deal : deals) {
449
+ // TODO(@Elestrias): [FIL-615] Check Creation time and since-epoch flag
450
+ total_size += deal.size ;
451
+ by_state[deal.state ] += deal.size ;
452
+ }
453
+ fmt::print (" Total: {} deals, {}" , deals.size (), total_size);
454
+ for (const auto &[state, size]: by_state){
455
+ fmt::print (" Deal with status {} allocates {} bytes" , toString (state), size);
456
+ }
415
457
}
416
458
};
417
459
@@ -545,10 +587,13 @@ namespace fc::cli::_node {
545
587
encoded_params},
546
588
api::kPushNoSpec ));
547
589
548
- fmt::print (" message sent, now waiting on cid: {}" , signed_message.getCid ());
549
- auto mwait = cliTry (api._ ->StateWaitMsg (signed_message.getCid (), kMessageConfidence , kLoopback , false ));
550
- if (mwait.receipt .exit_code != VMExitCode::kOk ) throw CliError (" failed to add verified client" );
551
- fmt::print (" Client {} was added successfully!" , target);
590
+ fmt::print (" message sent, now waiting on cid: {}" ,
591
+ signed_message.getCid ());
592
+ auto mwait = cliTry (api._ ->StateWaitMsg (
593
+ signed_message.getCid (), kMessageConfidence , kLoopback , false ));
594
+ if (mwait.receipt .exit_code != VMExitCode::kOk )
595
+ throw CliError (" failed to add verified client" );
596
+ fmt::print (" Client {} was added successfully!" , target);
552
597
}
553
598
};
554
599
@@ -562,8 +607,8 @@ namespace fc::cli::_node {
562
607
}
563
608
};
564
609
565
- struct Node_client_listNotaries : Empty{
566
- CLI_RUN (){
610
+ struct Node_client_listNotaries : Empty {
611
+ CLI_RUN () {
567
612
Node::Api api{argm};
568
613
auto actor =
569
614
cliTry (api._ ->StateGetActor (kVerifiedRegistryAddress , TipsetKey ()),
@@ -574,16 +619,16 @@ namespace fc::cli::_node {
574
619
auto state =
575
620
cliTry (getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head ));
576
621
577
- cliTry (state->verifiers .visit ([=](auto &key, auto &value)->outcome ::result<void >{
578
- fmt::print (" {}: {}" , key, value);
579
- return outcome::success ();
580
- }));
622
+ cliTry (state->verifiers .visit (
623
+ [=](auto &key, auto &value) -> outcome::result<void > {
624
+ fmt::print (" {}: {}" , key, value);
625
+ return outcome::success ();
626
+ }));
581
627
}
582
628
};
583
629
584
-
585
- struct Node_client_listClients : Empty{
586
- CLI_RUN (){
630
+ struct Node_client_listClients : Empty {
631
+ CLI_RUN () {
587
632
Node::Api api{argm};
588
633
auto actor =
589
634
cliTry (api._ ->StateGetActor (kVerifiedRegistryAddress , TipsetKey ()),
@@ -594,16 +639,16 @@ namespace fc::cli::_node {
594
639
auto state =
595
640
cliTry (getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head ));
596
641
597
- cliTry (state->verified_clients .visit ([=](auto &key, auto &value)->outcome ::result<void >{
598
- fmt::print (" {}: {}" , key, value);
599
- return outcome::success ();
600
- }));
642
+ cliTry (state->verified_clients .visit (
643
+ [=](auto &key, auto &value) -> outcome::result<void > {
644
+ fmt::print (" {}: {}" , key, value);
645
+ return outcome::success ();
646
+ }));
601
647
}
602
648
};
603
649
604
-
605
- struct Node_client_checkNotaryDataCap : Empty{
606
- CLI_RUN (){
650
+ struct Node_client_checkNotaryDataCap : Empty {
651
+ CLI_RUN () {
607
652
auto address{cliArgv<Address>(argv, 0 , " address" )};
608
653
Node::Api api{argm};
609
654
auto dcap = checkNotary (api._ , address);
0 commit comments