Add support for subaddress lookahead (#195)

This commit is contained in:
Lee *!* Clagett
2025-12-04 14:29:41 -05:00
committed by Lee *!* Clagett
parent e8b889e95f
commit 16111cae2c
20 changed files with 1588 additions and 210 deletions

View File

@@ -164,6 +164,7 @@ namespace lws { namespace rpc
void read_bytes(wire::reader& source, address_requests& self)
{
read_addresses(source, self, WIRE_FIELD(type));
self.max_subaddresses = 0;
}
void read_bytes(wire::reader& source, modify_account_req& self)
{
@@ -205,7 +206,7 @@ namespace lws { namespace rpc
expect<void> accept_requests_::operator()(wire::writer& dest, db::storage disk, const request& req) const
{
return write_addresses(dest, disk.accept_requests(req.type, epee::to_span(req.addresses)));
return write_addresses(dest, disk.accept_requests(req.type, epee::to_span(req.addresses), req.max_subaddresses));
}
expect<void> add_account_::operator()(wire::writer& out, db::storage disk, const request& req) const

View File

@@ -40,7 +40,7 @@
namespace lws
{
namespace rpc
{
{
struct add_account_req
{
db::account_address address;
@@ -52,6 +52,7 @@ namespace rpc
struct address_requests
{
std::vector<db::account_address> addresses;
std::uint32_t max_subaddresses;
db::request type;
};
void read_bytes(wire::reader&, address_requests&);
@@ -102,6 +103,16 @@ namespace rpc
void read_bytes(wire::reader&, webhook_delete_uuid_req&);
// Hack for passing max_subaddresses via cli option
template<typename T, typename U>
inline void add_values(const T&, const U&) noexcept
{}
template<typename T>
inline void add_values(address_requests& out, const T& src) noexcept
{ out.max_subaddresses = src.max_subaddresses; }
struct accept_requests_
{
using request = address_requests;

View File

@@ -266,8 +266,10 @@ namespace lws
WIRE_FIELD_COPY(start_height),
WIRE_FIELD_COPY(transaction_height),
WIRE_FIELD_COPY(blockchain_height),
WIRE_FIELD_DEFAULTED(lookahead_fail, unsigned(0)),
WIRE_FIELD(spent_outputs),
WIRE_OPTIONAL_FIELD(rates)
WIRE_OPTIONAL_FIELD(rates),
WIRE_FIELD_DEFAULTED(lookahead, db::address_index{})
);
}
@@ -318,6 +320,8 @@ namespace lws
WIRE_FIELD_COPY(start_height),
WIRE_FIELD_COPY(transaction_height),
WIRE_FIELD_COPY(blockchain_height),
WIRE_FIELD_DEFAULTED(lookahead_fail, unsigned(0)),
WIRE_FIELD_DEFAULTED(lookahead, db::address_index{}),
wire::optional_field("transactions", wire::array(boost::adaptors::index(self.transactions)))
);
}
@@ -359,6 +363,7 @@ namespace lws
WIRE_FIELD_COPY(per_byte_fee),
WIRE_FIELD_COPY(fee_mask),
WIRE_FIELD_COPY(amount),
WIRE_FIELD_DEFAULTED(lookahead_fail, unsigned(0)),
wire::optional_field("outputs", wire::array(boost::adaptors::transform(self.outputs, expand))),
WIRE_FIELD(fees)
);
@@ -400,7 +405,8 @@ namespace lws
wire::object(source,
wire::field("address", std::ref(address)),
wire::field("view_key", std::ref(unwrap(unwrap(self.creds.key)))),
WIRE_FIELD_DEFAULTED(from_height, unsigned(0))
WIRE_FIELD_DEFAULTED(from_height, unsigned(0)),
WIRE_FIELD_DEFAULTED(lookahead, db::address_index{})
);
convert_address(address, self.creds.address);
}
@@ -411,7 +417,8 @@ namespace lws
WIRE_FIELD_COPY(import_fee),
WIRE_FIELD(status),
WIRE_FIELD_COPY(new_request),
WIRE_FIELD_COPY(request_fulfilled)
WIRE_FIELD_COPY(request_fulfilled),
WIRE_FIELD_COPY(lookahead)
);
}
@@ -421,6 +428,7 @@ namespace lws
wire::object(source,
wire::field("address", std::ref(address)),
wire::field("view_key", std::ref(unwrap(unwrap(self.creds.key)))),
WIRE_FIELD_DEFAULTED(lookahead, db::address_index{}),
WIRE_FIELD(create_account),
WIRE_FIELD(generated_locally)
);
@@ -428,7 +436,11 @@ namespace lws
}
void rpc::write_bytes(wire::json_writer& dest, const login_response self)
{
wire::object(dest, WIRE_FIELD_COPY(new_address), WIRE_FIELD_COPY(generated_locally));
wire::object(dest,
WIRE_FIELD_COPY(new_address),
WIRE_FIELD_COPY(generated_locally),
WIRE_FIELD_COPY(lookahead)
);
}
void rpc::read_bytes(wire::json_reader& source, provision_subaddrs_request& self)

View File

@@ -136,6 +136,7 @@ namespace rpc
start_height(0),
transaction_height(0),
blockchain_height(0),
lookahead_fail(0),
spent_outputs(),
rates(common_error::kInvalidArgument)
{}
@@ -148,8 +149,10 @@ namespace rpc
std::uint64_t start_height;
std::uint64_t transaction_height;
std::uint64_t blockchain_height;
std::uint64_t lookahead_fail;
std::vector<transaction_spend> spent_outputs;
expect<lws::rates> rates;
db::address_index lookahead;
};
void write_bytes(wire::json_writer&, const get_address_info_response&);
@@ -171,7 +174,9 @@ namespace rpc
std::uint64_t start_height;
std::uint64_t transaction_height;
std::uint64_t blockchain_height;
std::uint64_t lookahead_fail;
std::vector<transaction> transactions;
db::address_index lookahead;
};
void write_bytes(wire::json_writer&, const get_address_txs_response&);
@@ -209,6 +214,7 @@ namespace rpc
std::uint64_t per_byte_fee;
std::uint64_t fee_mask;
safe_uint64 amount;
std::uint64_t lookahead_fail;
std::vector<std::pair<db::output, std::vector<crypto::key_image>>> outputs;
std::vector<std::uint64_t> fees;
crypto::secret_key user_key;
@@ -258,6 +264,7 @@ namespace rpc
import_request() = delete;
account_credentials creds;
std::uint64_t from_height;
db::address_index lookahead;
};
void read_bytes(wire::json_reader&, import_request&);
@@ -266,6 +273,7 @@ namespace rpc
import_response() = delete;
safe_uint64 import_fee;
std::string status;
db::address_index lookahead;
bool new_request;
bool request_fulfilled;
};
@@ -276,6 +284,7 @@ namespace rpc
{
login_request() = delete;
account_credentials creds;
db::address_index lookahead;
bool create_account;
bool generated_locally;
};
@@ -286,6 +295,7 @@ namespace rpc
login_response() = delete;
bool new_address;
bool generated_locally;
db::address_index lookahead;
};
void write_bytes(wire::json_writer&, login_response);