Skip to content

Commit

Permalink
Add webhook deletion to admin cli (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtnerd authored May 29, 2024
1 parent a644b66 commit 68916b7
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/admin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,23 @@ namespace
return out;
}

std::vector<lws::db::account_address> get_addresses(epee::span<const std::string> arguments)
std::vector<lws::db::account_address> get_addresses_(epee::span<const std::string> arguments)
{
// first entry is currently always some other option
assert(!arguments.empty());
arguments.remove_prefix(1);

std::vector<lws::db::account_address> addresses{};
addresses.reserve(arguments.size());
for (std::string const& address : arguments)
addresses.push_back(lws::db::address_string(address).value());
return addresses;
}

std::vector<lws::db::account_address> get_addresses(epee::span<const std::string> arguments)
{
// first entry is currently always some other option
assert(!arguments.empty());
arguments.remove_prefix(1);
return get_addresses_(arguments);
}

void accept_requests(program prog, std::ostream& out)
{
if (prog.arguments.size() < 2)
Expand Down Expand Up @@ -276,6 +280,35 @@ namespace
json.finish();
}

void webhook_delete(program prog, std::ostream& out)
{
if (prog.arguments.size() < 1)
throw std::runtime_error{"webhook_delete requires 1 or more arguments"};

lws::rpc::webhook_delete_req req{
get_addresses_(epee::to_span(prog.arguments))
};
run_command(lws::rpc::webhook_delete, out, std::move(prog.disk), std::move(req));
}

void webhook_delete_uuid(program prog, std::ostream& out)
{
if (prog.arguments.size() < 1)
throw std::runtime_error{"webhook_delete_uuid requires 1 or more arguments"};

std::vector<boost::uuids::uuid> ids{};
ids.reserve(prog.arguments.size());
for (const auto id : prog.arguments)
{
ids.emplace_back();
if (!epee::from_hex::to_buffer(epee::as_mut_byte_span(ids.back()), id))
throw std::runtime_error{"webhook_delete_uuid given invalid event_id/uuid"};
}

lws::rpc::webhook_delete_uuid_req req{std::move(ids)};
run_command(lws::rpc::webhook_delete_uuid, out, std::move(prog.disk), std::move(req));
}

struct command
{
char const* const name;
Expand All @@ -295,7 +328,9 @@ namespace
{"modify_account_status", &modify_account, "<\"active\"|\"inactive\"|\"hidden\"> <base58 address> [base 58 address]..."},
{"reject_requests", &reject_requests, "<\"create\"|\"import\"> <base58 address> [base 58 address]..."},
{"rescan", &rescan, "<height> <base58 address> [base 58 address]..."},
{"rollback", &rollback, "<height>"}
{"rollback", &rollback, "<height>"},
{"webhook_delete", &webhook_delete, "<base58 address> [base 58 address]..."},
{"webhook_delete_uuid", &webhook_delete_uuid, "<event_id> [event_id]..."}
};

void print_help(std::ostream& out)
Expand Down

0 comments on commit 68916b7

Please sign in to comment.