Skip to content

Commit bec77ae

Browse files
ElestriasMarkuu-s
authored andcommitted
client methods cli updates
Signed-off-by: elestrias <[email protected]>
1 parent e26857d commit bec77ae

File tree

4 files changed

+167
-48
lines changed

4 files changed

+167
-48
lines changed

core/cli/cli.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@
1111
#include <memory>
1212
#include <typeindex>
1313

14+
<<<<<<< HEAD
1415
<<<<<<< HEAD
1516
#define CLI_TRY(valueName, maybeResult) \
17+
=======
18+
#define CLI_TRY(valueName, maybeResult) \
19+
>>>>>>> 172a64dc (client methods cli updates)
1620
auto valueName##OUTCOME_TRY = maybeResult; \
1721
if (valueName##OUTCOME_TRY.has_error()) throw std::invalid_argument(""); \
1822
auto valueName = valueName##OUTCOME_TRY.value();
1923

20-
#define CLI_TRY_TEXT(valueName, maybeResult, textError) \
21-
auto valueName##OUTCOME_TRY = maybeResult; \
22-
if (valueName##OUTCOME_TRY.has_error()) throw std::invalid_argument(textError); \
24+
#define CLI_TRY_TEXT(valueName, maybeResult, textError) \
25+
auto valueName##OUTCOME_TRY = maybeResult; \
26+
if (valueName##OUTCOME_TRY.has_error()) \
27+
throw std::invalid_argument(textError); \
2328
auto valueName = valueName##OUTCOME_TRY.value();
2429
=======
2530
#include "cli/try.hpp"
@@ -53,6 +58,9 @@
5358
void operator()(Opts &opts) { \
5459
opts.add_options()(NAME, po::value(&_), DESCRIPTION); \
5560
} \
61+
void operator=(TYPE &&rhs) { \
62+
_ = std::move(rhs); \
63+
} \
5664
operator bool() const { \
5765
return _.operator bool(); \
5866
} \
@@ -70,10 +78,9 @@
7078
>>>>>>> aa902706 (options)
7179

7280
#define CLI_OPTS() ::fc::cli::Opts opts()
73-
#define CLI_RUN() \
74-
static ::fc::cli::RunResult run(const ::fc::cli::ArgsMap &argm, \
75-
const Args &args, \
76-
const ::fc::cli::Argv &argv)
81+
#define CLI_RUN() \
82+
static ::fc::cli::RunResult run( \
83+
const ::fc::cli::ArgsMap &argm, Args &args, const ::fc::cli::Argv &argv)
7784
#define CLI_NO_RUN() constexpr static nullptr_t run{nullptr};
7885

7986
namespace fc::cli {
@@ -82,7 +89,7 @@ namespace fc::cli {
8289

8390
using RunResult = void;
8491
struct ArgsMap {
85-
std::map<std::type_index, std::shared_ptr<void>> _;
92+
mutable std::map<std::type_index, std::shared_ptr<void>> _;
8693
template <typename Args>
8794
void add(Args &&v) {
8895
_.emplace(typeid(Args), std::make_shared<Args>(std::forward<Args>(v)));

core/cli/example/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ add_executable(cli_example main.cpp)
77
target_link_libraries(cli_example
88
cli
99
rpc
10+
car
11+
file
12+
memory_indexed_car
13+
unixfs
1014
)

core/cli/node/client.hpp

Lines changed: 147 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44

55
#pragma once
66
#include "cli/node/node.hpp"
7+
#include "storage/car/car.hpp"
8+
#include "storage/ipld/memory_indexed_car.hpp"
9+
#include "storage/unixfs/unixfs.hpp"
10+
#include "storage/ipld/memory_indexed_car.hpp"
711

812
namespace fc::cli::_node {
913
using api::FileRef;
1014
using api::ImportRes;
1115
using api::RetrievalOrder;
12-
using primitives::BigInt;
1316
using primitives::address::Address;
14-
using primitives::address::decodeFromString;
17+
using proofs::padPiece;
18+
using ::fc::storage::car::makeCar;
19+
using ::fc::storage::unixfs::wrapFile;
20+
1521

1622
struct clientRetrieve {
1723
struct Args {
@@ -48,51 +54,48 @@ namespace fc::cli::_node {
4854

4955
CLI_RUN() {
5056
Node::Api api{argm};
51-
CLI_TRY_TEXT(root, CID::fromString(args.root), "Invalid root CID: " + args.root);
52-
CLI_TRY_TEXT(cid,
53-
CID::fromString(args.piece_cid),
54-
"Invalid piece CID: " + args.piece_cid)
55-
if (!args.provider.empty()) {
56-
CLI_TRY_TEXT(miner,
57-
decodeFromString(args.provider),
58-
"Invalid Provider Address: " + args.provider)
59-
}
60-
if (!args.from.empty()) {
61-
CLI_TRY_TEXT(client,
62-
decodeFromString(args.from),
63-
"Invalid Client Address: " + args.from)
57+
RetrievalOrder order{};
58+
auto data_cid{cliArgv<CID>(argv, 0, "dataCid")};
59+
auto path{cliArgv<boost::filesystem::path>(argv, 1, "path")};
60+
order.client = (args.from ? *args.from : cliTry(api._->WalletDefaultAddress(), "Getting address of default wallet..."));
61+
order.miner = (args.provider ? *args.provider : Address{});
62+
if (args.max_price) {
63+
fmt::print("max price is {}fil ({}attofil)\n",
64+
args.max_price->fil,
65+
args.max_price->atto());
6466
}
67+
fmt::print("retrieving {} to {} {}\n",
68+
data_cid,
69+
args.car ? "car" : "file",
70+
path);
71+
6572
// TODO: continue function
66-
// TODO: positional args
6773
}
6874
};
6975

7076
struct clientImportData {
7177
struct Args {
72-
bool car{};
73-
std::string path;
78+
CLI_BOOL("car", "import from a car file instead of a regular file")car;
7479

7580
CLI_OPTS() {
76-
Opts opts;
77-
auto option{opts.add_options()};
78-
option("car",
79-
po::bool_switch(&car),
80-
"import from a car file instead of a regular file");
81-
option("path,p", po::value(&path), "path to import");
82-
return opts;
81+
Opts opts;
82+
car(opts);
83+
return opts;
8384
}
8485
};
8586

8687
CLI_RUN() {
8788
Node::Api api{argm};
88-
FileRef file_ref{args.path, args.car};
89-
CLI_TRY_TEXT(result, api._->ClientImport(file_ref), "Fail of data import")
90-
std::cout << "File Root CID: " << result.root.toString().value() << "\n";
91-
std::cout << "Data Import Success\n";
89+
auto path{cliArgv<std::string>(argv, 0, "path to file to import")};
90+
FileRef file_ref{path, args.car};
91+
auto result = cliTry(api._->ClientImport(file_ref), "Processing data import");
92+
fmt::print("File Root CID: " + result.root.toString().value());
93+
fmt::print("Data Import Success");
9294
}
9395
};
9496

9597

98+
<<<<<<< HEAD
9699
struct clientGenerateCar{
97100
struct Args{
98101
std::string in_path;
@@ -103,39 +106,81 @@ namespace fc::cli::_node {
103106
option("input-path, inp", po::value(&in_path), "specifies path to source file");
104107
option("output-path, outp", po::value(&in_path), "specifies path to generated file");
105108
}
106-
107-
CLI_RUN(){
108-
std::cout<<"Does not supported yet\n";
109-
}
110-
};
109+
=======
110+
struct Node_client_generateCar: Empty{
111+
CLI_RUN() {
112+
auto path_to{cliArgv<boost::filesystem::path>(argv, 0, "input-path")};
113+
auto path_out{cliArgv<boost::filesystem::path>(argv, 1, "output-path")};
114+
>>>>>>> 172a64dc (client methods cli updates)
115+
116+
auto tmp_path = path_to.string() + ".unixfs-tmp.car";
117+
auto ipld = cliTry(MemoryIndexedCar::make(tmp_path, true), "Creting IPLD instance of {}", tmp_path);
118+
std::ifstream file{path_to.string()};
119+
auto root = cliTry(wrapFile(*ipld, file));
120+
cliTry(::fc::storage::car::makeSelectiveCar(
121+
*ipld, {{root, {}}}, path_out.string()));
122+
boost::filesystem::remove(tmp_path);
123+
padPiece(path_out);
124+
}
111125
};
112126

113127
struct clientLocal: Empty{
114128
CLI_RUN(){
115129
Node::Api api {argm};
116130
CLI_TRY_TEXT(result, api._->ClientListImports(), "Fail of getting imports list");
117131
for(auto it = result.begin(); it != result.end(); it++){
118-
std::cout<<"Root CID: "<<it->root.toString().value()<<"\n";
119-
std::cout<<"Source: "<<it->source<<"\n";
120-
std::cout<<"Path: "<<it->path<<"\n";
132+
fmt::print("Root CID: {} \n", it->root.toString().value());
133+
fmt::print("Source: {}\n", it->source);
134+
fmt::print("Path: {}\n", it->path);
121135
}
122136
}
123137
};
124138

139+
<<<<<<< HEAD
125140
struct clientFind{
126141
struct Args{
142+
=======
143+
struct Node_client_find{
144+
145+
};
146+
147+
struct Node_client_listRetrieval{
148+
struct Args {
149+
CLI_BOOL("verbose", "print verbose deal details")verbose;
150+
CLI_BOOL("show-failed", "show failed/failing deals")failed_show;
151+
CLI_BOOL("completed", "show completed retrievals")completed_show;
152+
>>>>>>> 172a64dc (client methods cli updates)
127153

128154
CLI_OPTS(){
129155
Opts opts;
130-
auto option{opts.add_options()};
131-
156+
verbose(opts);
157+
failed_show(opts);
158+
completed_show(opts);
159+
return opts;
132160
}
133161
};
134162

163+
CLI_RUN(){
164+
Node::Api api{argm};
165+
bool failed_show = !args.failed_show;
166+
//TODO: continue;
167+
// chan = ()
168+
// if(flag){
169+
// chan->read([](){
170+
// print(api->stateRetrivalsDeals)
171+
//
172+
// })
173+
while(true){
174+
sleep(10000000000);
175+
}
176+
//
177+
}
178+
135179
};
136180

137181

138182

183+
<<<<<<< HEAD
139184

140185

141186

@@ -222,4 +267,67 @@ namespace fc::cli::_node {
222267
}
223268
};
224269
>>>>>>> b414cb63 (example client)
270+
=======
271+
struct Node_client_inspectDeal{
272+
struct Args {
273+
CLI_OPTIONAL("proposal-cid", "proposal cid of deal to be inspected", CID)
274+
proposal_cid;
275+
CLI_OPTIONAL("deal-id", "id of deal to be inspected", int) deal_id;
276+
CLI_OPTS() {
277+
Opts opts;
278+
proposal_cid(opts);
279+
deal_id(opts);
280+
return opts;
281+
}
282+
};
283+
CLI_RUN(){
284+
Node::Api api{argm};
285+
286+
287+
288+
}
289+
290+
};
291+
struct Node_client_list_deals{
292+
struct Args {
293+
CLI_BOOL("show-failed", "show failed/failing deals") failed_show;
294+
CLI_OPTS(){
295+
Opts opts;
296+
failed_show(opts);
297+
return opts;
298+
}
299+
};
300+
301+
CLI_RUN(){
302+
Node::Api api{argm};
303+
fmt::print("Not supported yet\n");
304+
auto local_deals = cliTry(api._->ClientListDeals(), "Getting local client deals...");
305+
// TODO(Markuus): make output;
306+
}
307+
};
308+
309+
struct Node_client_balances{
310+
struct Args{
311+
CLI_OPTIONAL("client", "specifies market client", Address)client;
312+
CLI_OPTS(){
313+
Opts opts;
314+
client(opts);
315+
return opts;
316+
}
317+
};
318+
319+
CLI_RUN(){
320+
Node::Api api{argm};
321+
Address addr = (args.client ? *args.client : cliTry(api._->WalletDefaultAddress(), "Getting address of default wallet..."));
322+
auto balance = cliTry(api._->StateMarketBalance(addr, TipsetKey()));
323+
324+
325+
fmt::print(" Escrowed Funds: {}\n", AttoFil{balance.escrow});
326+
fmt::print(" Locked Funds: {}\n", AttoFil{balance.locked});
327+
//TODO: Reserved and Avaliable
328+
}
329+
};
330+
331+
332+
>>>>>>> 172a64dc (client methods cli updates)
225333
} // namespace fc::cli::_node

core/cli/tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace fc::cli {
2929
if constexpr (run) {
3030
t.run = [](const ArgsMap &argm, const Argv &argv) {
3131
if constexpr (run) {
32-
return Cmd::run(argm, argm.of<Cmd>(), argv);
32+
return Cmd::run(argm, const_cast<typename Cmd::Args &>(argm.of<Cmd>()), argv);
3333
}
3434
};
3535
}

0 commit comments

Comments
 (0)