diff --git a/include/ircd/m/state.h b/include/ircd/m/state.h index 0cd502356..f6e3b38a9 100644 --- a/include/ircd/m/state.h +++ b/include/ircd/m/state.h @@ -55,6 +55,7 @@ namespace ircd::m::state json::array make_key(const mutable_buffer &out, const string_view &type); id set_node(db::txn &txn, const mutable_buffer &id, const json::object &node); + bool get_node(const std::nothrow_t, const string_view &id, const node_closure &); void get_node(const string_view &id, const node_closure &); id remove(db::txn &, const mutable_buffer &rootout, const id &rootin, const json::array &key); diff --git a/ircd/m/state.cc b/ircd/m/state.cc index 4c559fca0..ac51f67f3 100644 --- a/ircd/m/state.cc +++ b/ircd/m/state.cc @@ -783,10 +783,24 @@ ircd::m::state::_getbuffer(const uint8_t &height) void ircd::m::state::get_node(const string_view &node_id, const node_closure &closure) +{ + if(!get_node(std::nothrow, node_id, closure)) + throw m::NOT_FOUND + { + "node_id %s not found", + string_view{node_id} + }; +} + +/// View a node by ID. This makes a DB query and may yield ircd::ctx. +bool +ircd::m::state::get_node(const std::nothrow_t, + const string_view &node_id, + const node_closure &closure) { assert(bool(dbs::state_node)); auto &column{dbs::state_node}; - column(node_id, closure); + return column(node_id, std::nothrow, closure); } /// Writes a node to the db::txn and returns the id of this node (a hash) into