Add (non-standard) 'daemon_status' endpoint to REST API (#124)

This commit is contained in:
Lee *!* Clagett
2024-08-06 19:04:55 -04:00
committed by Lee *!* Clagett
parent 79564f714f
commit 8fad87a0fe
3 changed files with 122 additions and 2 deletions

View File

@@ -40,6 +40,7 @@
#include "ringct/rctOps.h" // monero/src
#include "span.h" // monero/contrib/epee/include
#include "util/random_outputs.h"
#include "wire.h"
#include "wire/adapted/crypto.h"
#include "wire/error.h"
#include "wire/json.h"
@@ -195,6 +196,29 @@ namespace lws
convert_address(address, self.address);
}
namespace rpc
{
namespace
{
constexpr const char* map_daemon_state[] = {"ok", "no_connections", "synchronizing", "unavailable"};
constexpr const char* map_network_type[] = {"main", "test", "stage", "fake"};
}
WIRE_DEFINE_ENUM(daemon_state, map_daemon_state);
WIRE_DEFINE_ENUM(network_type, map_network_type);
}
void rpc::write_bytes(wire::json_writer& dest, const daemon_status_response& self)
{
wire::object(dest,
WIRE_FIELD(outgoing_connections_count),
WIRE_FIELD(incoming_connections_count),
WIRE_FIELD(height),
WIRE_FIELD(target_height),
WIRE_FIELD(network),
WIRE_FIELD(state)
);
}
void rpc::write_bytes(wire::json_writer& dest, const new_subaddrs_response& self)
{
wire::object(dest, WIRE_FIELD(new_subaddrs), WIRE_FIELD(all_subaddrs));

View File

@@ -33,8 +33,10 @@
#include <utility>
#include <vector>
#include "common/expect.h" // monero/src
#include "crypto/crypto.h" // monero/src
#include "common/expect.h" // monero/src
#include "cryptonote_config.h" // monero/src
#include "cryptonote_basic/difficulty.h" // monero/src
#include "crypto/crypto.h" // monero/src
#include "db/data.h"
#include "rpc/rates.h"
#include "util/fwd.h"
@@ -65,6 +67,44 @@ namespace rpc
void read_bytes(wire::json_reader&, account_credentials&);
enum class daemon_state : std::uint8_t
{
ok = 0,
no_connections,
synchronizing,
unavailable
};
WIRE_DECLARE_ENUM(daemon_state);
enum class network_type : std::uint8_t
{
main = 0,
test,
stage,
fake
};
WIRE_DECLARE_ENUM(network_type);
struct daemon_status_request
{
daemon_status_request() = delete;
};
inline void read_bytes(const wire::reader&, const daemon_status_request&)
{}
struct daemon_status_response
{
daemon_status_response() = delete;
std::uint64_t outgoing_connections_count;
std::uint64_t incoming_connections_count;
std::uint64_t height;
std::uint64_t target_height;
network_type network;
daemon_state state;
};
void write_bytes(wire::json_writer&, const daemon_status_response&);
struct new_subaddrs_response
{
new_subaddrs_response() = delete;