New accounts are 'pushed' to worker threads (#102)

This commit is contained in:
Lee *!* Clagett
2024-04-08 12:58:43 -04:00
committed by Lee *!* Clagett
parent f300bff69f
commit 80604e8133
21 changed files with 743 additions and 50 deletions

View File

@@ -33,6 +33,11 @@
#include "common/expect.h"
#include "db/data.h"
#include "db/string.h"
#include "wire/adapted/crypto.h"
#include "wire/adapted/pair.h"
#include "wire/msgpack.h"
#include "wire/vector.h"
#include "wire/wrapper/trusted_array.h"
namespace lws
{
@@ -50,6 +55,10 @@ namespace lws
struct account::internal
{
internal()
: address(), id(db::account_id::invalid), pubs{}, view_key{}
{}
explicit internal(db::account const& source)
: address(db::address_string(source.address)), id(source.id), pubs(source.address), view_key()
{
@@ -66,6 +75,23 @@ namespace lws
);
}
void read_bytes(wire::msgpack_reader& source)
{ map(source, *this); }
void write_bytes(wire::msgpack_writer& dest) const
{ map(dest, *this); }
template<typename F, typename T>
static void map(F& format, T& self)
{
wire::object(format,
WIRE_FIELD_ID(0, address),
WIRE_FIELD_ID(1, id),
WIRE_FIELD_ID(2, pubs),
WIRE_FIELD_ID(3, view_key)
);
}
std::string address;
db::account_id id;
db::account_address pubs;
@@ -87,6 +113,23 @@ namespace lws
MONERO_THROW(::common_error::kInvalidArgument, "using moved from account");
}
template<typename F, typename T, typename U>
void account::map(F& format, T& self, U& immutable)
{
wire::object(format,
wire::field<0>("immutable_", std::ref(immutable)),
wire::optional_field<1>("spendable_", wire::trusted_array(std::ref(self.spendable_))),
wire::optional_field<2>("pubs_", wire::trusted_array(std::ref(self.pubs_))),
wire::optional_field<3>("spends_", wire::trusted_array(std::ref(self.spends_))),
wire::optional_field<4>("outputs_", wire::trusted_array(std::ref(self.outputs_))),
WIRE_FIELD_ID(5, height_)
);
}
account::account() noexcept
: immutable_(nullptr), spendable_(), pubs_(), spends_(), outputs_(), height_(db::block_id(0))
{}
account::account(db::account const& source, std::vector<std::pair<db::output_id, db::address_index>> spendable, std::vector<crypto::public_key> pubs)
: account(std::make_shared<internal>(source), source.scan_height, std::move(spendable), std::move(pubs))
{
@@ -97,6 +140,21 @@ namespace lws
account::~account() noexcept
{}
void account::read_bytes(::wire::msgpack_reader& source)
{
auto immutable = std::make_shared<internal>();
map(source, *this, *immutable);
immutable_ = std::move(immutable);
std::sort(spendable_.begin(), spendable_.end());
std::sort(pubs_.begin(), pubs_.end(), sort_pubs{});
}
void account::write_bytes(::wire::msgpack_writer& dest) const
{
null_check();
map(dest, *this, *immutable_);
}
account account::clone() const
{
account result{immutable_, height_, spendable_, pubs_};