From 3f2916b0fad30856329ebdfc8c211e1f4011002a Mon Sep 17 00:00:00 2001 From: Lee *!* Clagett Date: Tue, 28 May 2024 20:00:30 -0400 Subject: [PATCH] Add webhook deletion to admin cli (#105) --- src/admin_main.cpp | 47 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/admin_main.cpp b/src/admin_main.cpp index 8e06b0c..163c026 100644 --- a/src/admin_main.cpp +++ b/src/admin_main.cpp @@ -130,12 +130,8 @@ namespace return out; } - std::vector get_addresses(epee::span arguments) + std::vector get_addresses_(epee::span arguments) { - // first entry is currently always some other option - assert(!arguments.empty()); - arguments.remove_prefix(1); - std::vector addresses{}; addresses.reserve(arguments.size()); for (std::string const& address : arguments) @@ -143,6 +139,14 @@ namespace return addresses; } + std::vector get_addresses(epee::span 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) @@ -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 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; @@ -295,7 +328,9 @@ namespace {"modify_account_status", &modify_account, "<\"active\"|\"inactive\"|\"hidden\"> [base 58 address]..."}, {"reject_requests", &reject_requests, "<\"create\"|\"import\"> [base 58 address]..."}, {"rescan", &rescan, " [base 58 address]..."}, - {"rollback", &rollback, ""} + {"rollback", &rollback, ""}, + {"webhook_delete", &webhook_delete, " [base 58 address]..."}, + {"webhook_delete_uuid", &webhook_delete_uuid, " [event_id]..."} }; void print_help(std::ostream& out)