Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cli.cpp
Go to the documentation of this file.
7
9#include <iostream>
10#include <string>
11
12namespace bb::avm {
13
14namespace {
15
16struct AvmApi {
19 SERIALIZATION_FIELDS(commands, responses);
20};
21
22std::string get_avm_schema_as_json()
23{
24 return msgpack_schema_to_string(AvmApi{});
25}
26
27} // namespace
28
29int parse_and_run_avm(int argc, char* argv[])
30{
31 CLI::App app{ "aztec-avm: Standalone AVM simulator server" };
32 app.require_subcommand(1);
33
34 // -----------------------------------------------------------------------
35 // Subcommand: msgpack
36 // -----------------------------------------------------------------------
37 CLI::App* msgpack_command = app.add_subcommand("msgpack", "Msgpack API interface.");
38
39 // msgpack schema
40 CLI::App* msgpack_schema_command =
41 msgpack_command->add_subcommand("schema", "Output a msgpack schema encoded as JSON to stdout.");
42
43 // msgpack run
44 CLI::App* msgpack_run_command = msgpack_command->add_subcommand("run", "Start the AVM simulator IPC server.");
45
46 std::string input_path;
47 msgpack_run_command->add_option("-i,--input", input_path, "IPC socket path (.sock)")->required();
48
49 std::string wsdb_path;
50 msgpack_run_command->add_option("--wsdb", wsdb_path, "WSDB server socket path")->required();
51
52 std::string cdb_path;
53 msgpack_run_command->add_option("--cdb", cdb_path, "CDB server socket path")->required();
54
55 // Parse CLI
56 try {
57 app.parse(argc, argv);
58 } catch (const CLI::ParseError& e) {
59 return app.exit(e);
60 }
61
62 try {
63 if (msgpack_schema_command->parsed()) {
64 std::cout << get_avm_schema_as_json() << std::endl;
65 return 0;
66 }
67
68 if (msgpack_run_command->parsed()) {
69 return execute_avm_server(input_path, wsdb_path, cdb_path);
70 }
71 } catch (const std::exception& e) {
72 std::cerr << "Error: " << e.what() << '\n';
73 return 1;
74 }
75
76 return 0;
77}
78
79} // namespace bb::avm
AvmCommandResponse responses
Definition cli.cpp:18
AvmCommand commands
Definition cli.cpp:17
AvmCommand NamedUnion, AvmRequest context, and dispatch function.
#define SERIALIZATION_FIELDS(...)
Definition msgpack.hpp:121
NamedUnion< AvmErrorResponse, AvmSimulate::Response, AvmSimulateWithHints::Response, AvmShutdown::Response > AvmCommandResponse
Union of all AVM response types.
int execute_avm_server(const std::string &input_path, const std::string &wsdb_path, const std::string &cdb_path)
Start the aztec-avm IPC server.
int parse_and_run_avm(int argc, char *argv[])
Definition cli.cpp:29
NamedUnion< AvmSimulate, AvmSimulateWithHints, AvmShutdown > AvmCommand
Union of all AVM commands (request types).
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string msgpack_schema_to_string(const auto &obj)
Print's an object's derived msgpack schema as a string.