4
4
5
5
#pragma once
6
6
#include < inttypes.h>
7
+ #include " api/full_node/node_api.hpp"
7
8
#include " cli/node/node.hpp"
8
9
#include " markets/storage/mk_protocol.hpp"
9
10
#include " primitives/chain_epoch/chain_epoch.hpp"
15
16
#include " vm/actor/actor.hpp"
16
17
#include " vm/actor/builtin/states/verified_registry/verified_registry_actor_state.hpp"
17
18
#include " vm/actor/builtin/v0/verified_registry/verified_registry_actor.hpp"
19
+ #include " common/enum.hpp"
18
20
19
21
namespace fc ::cli::_node {
20
22
using api::FileRef;
21
23
using api::FullNodeApi;
22
24
using api::ImportRes;
23
25
using api::RetrievalOrder;
26
+ using api::StartDealParams;
24
27
using boost::lexical_cast;
25
28
using ::fc::storage::car::makeCar;
26
29
using ::fc::storage::unixfs::wrapFile;
@@ -32,12 +35,13 @@ namespace fc::cli::_node {
32
35
using primitives::piece::UnpaddedPieceSize;
33
36
using proofs::padPiece;
34
37
using storage::ipfs::ApiIpfsDatastore;
38
+ using vm::VMExitCode;
35
39
using vm::actor::kVerifiedRegistryAddress ;
36
40
using vm::actor::builtin::states::VerifiedRegistryActorStatePtr;
37
- using vm::VMExitCode;
38
-
39
- const ChainEpoch kLoopback = 100 ; // TODO: lookback
41
+ using markets::storage::StorageDealStatus;
42
+ using common::toString;
40
43
44
+ const ChainEpoch kLoopback = 100 ; // TODO: lookback
41
45
42
46
StoragePower checkNotary (std::shared_ptr<FullNodeApi> api,
43
47
const Address &vaddr) {
@@ -224,16 +228,42 @@ namespace fc::cli::_node {
224
228
auto duration{cliArgv<ChainEpoch>(
225
229
argv, 3 , " is a period of storing the data for, in blocks" )};
226
230
Node::Api api{argm};
227
- if (duration < kMinDealDuration ) throw CliError (" Minimal deal duration is {}" , kMinDealDuration );
228
- if (duration < kMaxDealDuration ) throw CliError (" Max deal duration is {}" , kMaxDealDuration );
229
-
231
+ if (duration < kMinDealDuration )
232
+ throw CliError (" Minimal deal duration is {}" , kMinDealDuration );
233
+ if (duration < kMaxDealDuration )
234
+ throw CliError (" Max deal duration is {}" , kMaxDealDuration );
235
+ DataRef data_ref;
230
236
Address address_from =
231
237
args.from ? *args.from : cliTry (api._ ->WalletDefaultAddress ());
232
- UnpaddedPieceSize piece_size{*args.man_piece_size };
233
- DataRef data_ref = {.transfer_type = " graphsync" ,
234
- .root = data_cid,
235
- .piece_cid = *args.man_piece_cid ,
236
- .piece_size = piece_size};
238
+ if (args.man_piece_cid ) {
239
+ UnpaddedPieceSize piece_size{*args.man_piece_size };
240
+ data_ref = {.transfer_type = " manual" ,
241
+ .root = data_cid,
242
+ .piece_cid = *args.man_piece_cid ,
243
+ .piece_size = piece_size};
244
+ } else {
245
+ data_ref = {.transfer_type = " graphsync" , .root = data_cid};
246
+ }
247
+ auto dcap =
248
+ cliTry (api._ ->StateVerifiedClientStatus (address_from, TipsetKey ()),
249
+ " Failed to get status of {}" ,
250
+ address_from);
251
+ bool isVerified = dcap.has_value ();
252
+ if (args.verified_deal && !isVerified)
253
+ throw CliError (
254
+ " Cannot perform verified deal using unverified address {}" ,
255
+ address_from);
256
+ StartDealParams deal_params = {.data = data_ref,
257
+ .wallet = address_from,
258
+ .miner = miner,
259
+ .epoch_price = price,
260
+ .min_blocks_duration = duration,
261
+ .deal_start_epoch = *args.start_epoch ,
262
+ .fast_retrieval = args.fast_ret ,
263
+ .verified_deal = isVerified,
264
+ .provider_collateral = *args.collateral };
265
+ auto proposal_cid = cliTry (api._ ->ClientStartDeal (deal_params));
266
+ fmt::print (" Deal proposal CID: {}\n " , cliTry (proposal_cid.toString (), " Cannot extract CID" ));
237
267
}
238
268
};
239
269
@@ -364,6 +394,7 @@ namespace fc::cli::_node {
364
394
365
395
<<<<<<< HEAD
366
396
<<<<<<< HEAD
397
+ <<<<<<< HEAD
367
398
368
399
369
400
<<<<<<< HEAD
@@ -461,6 +492,9 @@ namespace fc::cli::_node {
461
492
=======
462
493
struct Node_client_inspectDeal { // TODO: continue
463
494
>>>>>>> 3d9435d6 (FFi+ and client updates)
495
+ =======
496
+ struct Node_client_inspectDeal { // TODO: continue
497
+ >>>>>>> ad42f96d (ClientUpdates, DealStatus enum conversion)
464
498
struct Args {
465
499
CLI_OPTIONAL (" proposal-cid" , " proposal cid of deal to be inspected" , CID)
466
500
proposal_cid;
@@ -477,25 +511,33 @@ namespace fc::cli::_node {
477
511
}
478
512
};
479
513
480
- struct Node_client_dealStats {
514
+ struct Node_client_dealStats {
481
515
struct Args {
482
516
CLI_DEFAULT (" newer-than" ,
483
517
" list all deals stas that was made after given period" ,
484
518
ChainEpoch,
485
- {0 })newer;
486
- CLI_OPTS (){
519
+ {0 })
520
+ newer;
521
+ CLI_OPTS () {
487
522
Opts opts;
488
523
newer (opts);
489
524
return opts;
490
525
}
491
526
};
492
- CLI_RUN (){
527
+ CLI_RUN () {
493
528
Node::Api api{argm};
494
529
auto deals = cliTry (api._ ->ClientListDeals ());
495
- for (const auto deal: deals){
496
-
497
- }// TODO: Continue
498
-
530
+ uint64_t total_size{0 };
531
+ std::map<StorageDealStatus, uint64_t > by_state;
532
+ for (const auto &deal : deals) {
533
+ // TODO(@Elestrias): [FIL-615] Check Creation time and since-epoch flag
534
+ total_size += deal.size ;
535
+ by_state[deal.state ] += deal.size ;
536
+ }
537
+ fmt::print (" Total: {} deals, {}" , deals.size (), total_size);
538
+ for (const auto &[state, size]: by_state){
539
+ fmt::print (" Deal with status {} allocates {} bytes" , toString (state), size);
540
+ }
499
541
}
500
542
};
501
543
@@ -631,10 +673,13 @@ namespace fc::cli::_node {
631
673
encoded_params},
632
674
api::kPushNoSpec ));
633
675
634
- fmt::print (" message sent, now waiting on cid: {}" , signed_message.getCid ());
635
- auto mwait = cliTry (api._ ->StateWaitMsg (signed_message.getCid (), kMessageConfidence , kLoopback , false ));
636
- if (mwait.receipt .exit_code != VMExitCode::kOk ) throw CliError (" failed to add verified client" );
637
- fmt::print (" Client {} was added successfully!" , target);
676
+ fmt::print (" message sent, now waiting on cid: {}" ,
677
+ signed_message.getCid ());
678
+ auto mwait = cliTry (api._ ->StateWaitMsg (
679
+ signed_message.getCid (), kMessageConfidence , kLoopback , false ));
680
+ if (mwait.receipt .exit_code != VMExitCode::kOk )
681
+ throw CliError (" failed to add verified client" );
682
+ fmt::print (" Client {} was added successfully!" , target);
638
683
}
639
684
};
640
685
@@ -648,8 +693,8 @@ namespace fc::cli::_node {
648
693
}
649
694
};
650
695
651
- struct Node_client_listNotaries : Empty{
652
- CLI_RUN (){
696
+ struct Node_client_listNotaries : Empty {
697
+ CLI_RUN () {
653
698
Node::Api api{argm};
654
699
auto actor =
655
700
cliTry (api._ ->StateGetActor (kVerifiedRegistryAddress , TipsetKey ()),
@@ -660,16 +705,16 @@ namespace fc::cli::_node {
660
705
auto state =
661
706
cliTry (getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head ));
662
707
663
- cliTry (state->verifiers .visit ([=](auto &key, auto &value)->outcome ::result<void >{
664
- fmt::print (" {}: {}" , key, value);
665
- return outcome::success ();
666
- }));
708
+ cliTry (state->verifiers .visit (
709
+ [=](auto &key, auto &value) -> outcome::result<void > {
710
+ fmt::print (" {}: {}" , key, value);
711
+ return outcome::success ();
712
+ }));
667
713
}
668
714
};
669
715
670
-
671
- struct Node_client_listClients : Empty{
672
- CLI_RUN (){
716
+ struct Node_client_listClients : Empty {
717
+ CLI_RUN () {
673
718
Node::Api api{argm};
674
719
auto actor =
675
720
cliTry (api._ ->StateGetActor (kVerifiedRegistryAddress , TipsetKey ()),
@@ -680,16 +725,16 @@ namespace fc::cli::_node {
680
725
auto state =
681
726
cliTry (getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head ));
682
727
683
- cliTry (state->verified_clients .visit ([=](auto &key, auto &value)->outcome ::result<void >{
684
- fmt::print (" {}: {}" , key, value);
685
- return outcome::success ();
686
- }));
728
+ cliTry (state->verified_clients .visit (
729
+ [=](auto &key, auto &value) -> outcome::result<void > {
730
+ fmt::print (" {}: {}" , key, value);
731
+ return outcome::success ();
732
+ }));
687
733
}
688
734
};
689
735
690
-
691
- struct Node_client_checkNotaryDataCap : Empty{
692
- CLI_RUN (){
736
+ struct Node_client_checkNotaryDataCap : Empty {
737
+ CLI_RUN () {
693
738
auto address{cliArgv<Address>(argv, 0 , " address" )};
694
739
Node::Api api{argm};
695
740
auto dcap = checkNotary (api._ , address);
0 commit comments