lokinet/pybind/llarp/router_id.cpp

24 lines
747 B
C++
Raw Permalink Normal View History

#include <common.hpp>
2020-03-01 00:34:48 +00:00
#include <llarp/router_id.hpp>
2020-03-01 00:34:48 +00:00
namespace llarp
{
void
2020-03-07 01:20:11 +00:00
RouterID_Init(py::module& mod)
2020-03-01 00:34:48 +00:00
{
py::class_<RouterID>(mod, "RouterID")
.def(
"FromHex",
[](RouterID* r, const std::string& hex) {
if (hex.size() != 2 * r->size() || !oxenc::is_hex(hex))
throw std::runtime_error("FromHex requires a 64-digit hex string");
oxenc::from_hex(hex.begin(), hex.end(), r->data());
})
2020-03-01 00:34:48 +00:00
.def("__repr__", &RouterID::ToString)
.def("__str__", &RouterID::ToString)
2020-03-01 00:42:42 +00:00
.def("ShortString", &RouterID::ShortString)
.def("__eq__", [](const RouterID& lhs, const RouterID& rhs) { return lhs == rhs; });
2020-03-01 00:34:48 +00:00
}
2020-03-07 01:20:11 +00:00
} // namespace llarp