Maintenance of light wallet methods

This commit is contained in:
everoddandeven 2024-10-01 15:34:33 +02:00
parent 5c8c898ffd
commit b200b6e527
4 changed files with 1014 additions and 175 deletions

View File

@ -353,6 +353,14 @@ namespace cryptonote
};
typedef epee::misc_utils::struct_init<request_t> request;
struct standard_response_t
{
bool status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<standard_response_t> standard_response;
struct response_t
{

File diff suppressed because it is too large Load Diff

View File

@ -91,6 +91,14 @@ class wallet_accessor_test;
namespace tools
{
enum light_wallet_server_type : uint8_t
{
STANDARD = 0,
OPENMONERO,
MYMONERO,
UNDEFINED = 255
};
class ringdb;
class wallet2;
class Notify;
@ -1023,6 +1031,7 @@ private:
*/
bool light_wallet() const { return m_light_wallet; }
void set_light_wallet(bool light_wallet) { m_light_wallet = light_wallet; }
void set_light_wallet_server_type(light_wallet_server_type server_type){ m_light_wallet_server_type = server_type; };
uint64_t get_light_wallet_scanned_block_height() const { return m_light_wallet_scanned_block_height; }
uint64_t get_light_wallet_blockchain_height() const { return m_light_wallet_blockchain_height; }
@ -1611,7 +1620,39 @@ private:
// Parse rct string
bool light_wallet_parse_rct_str(const std::string& rct_string, const crypto::public_key& tx_pub_key, uint64_t internal_output_index, rct::key& decrypted_mask, rct::key& rct_commit, bool decrypt) const;
// check if key image is ours
bool light_wallet_key_image_is_ours(const crypto::key_image& key_image, const crypto::public_key& tx_public_key, uint64_t out_index);
bool light_wallet_key_image_is_ours(const crypto::key_image& key_image, const crypto::public_key& tx_public_key, uint64_t out_index, const cryptonote::subaddress_index subaddress_index);
bool light_wallet_is_output_spent(const std::string& out_public_key, const std::string& tx_public_key, uint64_t out_index);
bool light_wallet_is_output_spent(const crypto::public_key& out_public_key, const crypto::public_key& tx_public_key, uint64_t out_index);
bool light_wallet_is_key_image_spent(const crypto::key_image& key_image) {
std::vector<crypto::key_image> key_images;
key_images.push_back(key_image);
std::vector<bool> spent_list = light_wallet_is_key_image_spent(key_images);
if (spent_list.empty()) return false;
return spent_list[0];
}
bool m_light_wallet_is_logged_in;
boost::optional<tools::COMMAND_RPC_GET_UNSPENT_OUTS::response> m_unspent_outputs_response;
boost::optional<tools::COMMAND_RPC_GET_ADDRESS_TXS::response> m_address_txs_response;
void light_wallet_get_tx_unspent_outs(const std::string tx_hash, std::vector<tools::COMMAND_RPC_GET_UNSPENT_OUTS::output> &outputs) const;
void light_wallet_refresh(uint64_t & blocks_fectched, bool& received_money);
std::vector<bool> light_wallet_is_key_image_spent(const std::vector<crypto::key_image>& key_images);
std::vector<cryptonote::subaddress_index> m_light_wallet_subaddrs;
std::vector<uint32_t> m_light_wallet_accounts;
std::list<tools::COMMAND_RPC_GET_UNSPENT_OUTS::output> m_light_wallet_unspent_outputs;
bool light_wallet_supports_subaddrs();
void light_wallet_get_subaddrs();
bool light_wallet_provision_subaddrs(uint32_t maj_i, uint32_t min_i, uint32_t n_maj, uint32_t n_min);
bool light_wallet_upsert_subaddrs(std::vector<cryptonote::subaddress_index> subaddrs);
bool generate_output_key_image(const std::string& out_public_key, const std::string& tx_public_key, uint64_t out_index, const cryptonote::subaddress_index subaddress, crypto::key_image& ki) const;
bool generate_output_key_image(const crypto::public_key& out_public_key, const crypto::public_key& tx_public_key, uint64_t out_index, const cryptonote::subaddress_index subaddress, crypto::key_image& ki) const;
/*
* "attributes" are a mechanism to store an arbitrary number of string values
@ -1823,6 +1864,7 @@ private:
void on_device_progress(const hw::device_progress& event);
std::string get_rpc_status(const std::string &s) const;
std::string get_rpc_status(const bool &s) const;
void throw_on_rpc_response_error(bool r, const epee::json_rpc::error &error, const std::string &status, const char *method) const;
std::string get_client_signature() const;
@ -1849,6 +1891,7 @@ private:
transfer_container m_transfers;
payment_container m_payments;
serializable_unordered_map<crypto::key_image, size_t> m_key_images;
std::set<std::string> m_spent_key_images;
serializable_unordered_map<crypto::public_key, size_t> m_pub_keys;
cryptonote::account_public_address m_account_public_address;
serializable_unordered_map<crypto::public_key, cryptonote::subaddress_index> m_subaddresses;
@ -1940,6 +1983,7 @@ private:
// Light wallet
bool m_light_wallet; /* sends view key to daemon for scanning */
light_wallet_server_type m_light_wallet_server_type = STANDARD;
uint64_t m_light_wallet_scanned_block_height;
uint64_t m_light_wallet_blockchain_height;
uint64_t m_light_wallet_per_kb_fee = FEE_PER_KB;
@ -1949,6 +1993,7 @@ private:
// Light wallet info needed to populate m_payment requires 2 separate api calls (get_address_txs and get_unspent_outs)
// We save the info from the first call in m_light_wallet_address_txs for easier lookup.
std::unordered_map<crypto::hash, address_tx> m_light_wallet_address_txs;
std::vector<crypto::public_key> m_light_wallet_processed_out_public_keys;
// store calculated key image for faster lookup
serializable_unordered_map<crypto::public_key, serializable_map<uint64_t, crypto::key_image> > m_key_image_cache;

View File

@ -49,13 +49,28 @@ namespace tools
};
typedef epee::misc_utils::struct_init<request_t> request;
struct address_meta {
uint32_t maj_i;
uint32_t min_i;
BEGIN_SERIALIZE_OBJECT()
FIELD(maj_i)
FIELD(min_i)
END_SERIALIZE()
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(maj_i)
KV_SERIALIZE(min_i)
END_KV_SERIALIZE_MAP()
};
struct spent_output {
uint64_t amount;
std::string key_image;
std::string tx_pub_key;
uint64_t out_index;
uint32_t mixin;
address_meta sender;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
@ -63,6 +78,7 @@ namespace tools
KV_SERIALIZE(tx_pub_key)
KV_SERIALIZE(out_index)
KV_SERIALIZE(mixin)
KV_SERIALIZE(sender)
END_KV_SERIALIZE_MAP()
};
@ -75,11 +91,13 @@ namespace tools
uint64_t total_sent;
uint64_t unlock_time;
uint64_t height;
uint64_t fee;
std::list<spent_output> spent_outputs;
std::string payment_id;
bool coinbase;
bool mempool;
uint32_t mixin;
address_meta recipient;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(id)
@ -89,11 +107,13 @@ namespace tools
KV_SERIALIZE(total_sent)
KV_SERIALIZE(unlock_time)
KV_SERIALIZE(height)
KV_SERIALIZE_OPT(fee, (uint64_t)0)
KV_SERIALIZE(spent_outputs)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(coinbase)
KV_SERIALIZE(mempool)
KV_SERIALIZE(mixin)
KV_SERIALIZE(recipient)
END_KV_SERIALIZE_MAP()
};
@ -136,6 +156,21 @@ namespace tools
};
typedef epee::misc_utils::struct_init<request_t> request;
struct address_meta {
uint32_t maj_i;
uint32_t min_i;
BEGIN_SERIALIZE_OBJECT()
FIELD(maj_i)
FIELD(min_i)
END_SERIALIZE()
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(maj_i)
KV_SERIALIZE(min_i)
END_KV_SERIALIZE_MAP()
};
struct spent_output
{
uint64_t amount;
@ -143,6 +178,7 @@ namespace tools
std::string tx_pub_key;
uint64_t out_index;
uint32_t mixin;
address_meta sender;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
@ -150,6 +186,7 @@ namespace tools
KV_SERIALIZE(tx_pub_key)
KV_SERIALIZE(out_index)
KV_SERIALIZE(mixin)
KV_SERIALIZE(sender)
END_KV_SERIALIZE_MAP()
};
@ -203,6 +240,20 @@ namespace tools
};
typedef epee::misc_utils::struct_init<request_t> request;
struct address_meta {
uint32_t maj_i;
uint32_t min_i;
BEGIN_SERIALIZE_OBJECT()
FIELD(maj_i)
FIELD(min_i)
END_SERIALIZE()
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(maj_i)
KV_SERIALIZE(min_i)
END_KV_SERIALIZE_MAP()
};
struct output {
uint64_t amount;
@ -216,7 +267,7 @@ namespace tools
std::vector<std::string> spend_key_images;
uint64_t timestamp;
uint64_t height;
address_meta recipient;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
@ -230,6 +281,7 @@ namespace tools
KV_SERIALIZE(spend_key_images)
KV_SERIALIZE(timestamp)
KV_SERIALIZE(height)
KV_SERIALIZE(recipient)
END_KV_SERIALIZE_MAP()
};
@ -364,4 +416,148 @@ namespace tools
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_PROVISION_SUBADDRS
{
class index_range : public std::vector<uint32_t> {
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
struct subaddrs_t {
uint32_t key;
std::vector<index_range> value;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(key)
KV_SERIALIZE(value)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<subaddrs_t> subaddrs;
struct request_t
{
std::string address;
std::string view_key;
uint32_t maj_i;
uint32_t min_i;
uint32_t n_maj;
uint32_t n_min;
bool get_all;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address)
KV_SERIALIZE(view_key)
KV_SERIALIZE(maj_i)
KV_SERIALIZE(min_i)
KV_SERIALIZE(n_maj)
KV_SERIALIZE(n_min)
KV_SERIALIZE(get_all)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;
struct response_t
{
std::vector<subaddrs> new_subaddrs;
std::vector<subaddrs> all_subaddrs;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(new_subaddrs)
KV_SERIALIZE(all_subaddrs)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_UPSERT_SUBADDRS
{
class index_range : public std::vector<uint32_t> {
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
struct subaddrs_obj_t {
uint32_t key;
std::vector<index_range> value;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(key)
KV_SERIALIZE(value)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<subaddrs_obj_t> subaddrs_obj;
struct request_t
{
std::string address;
std::string view_key;
subaddrs_obj subaddrs;
bool get_all;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address)
KV_SERIALIZE(view_key)
KV_SERIALIZE(subaddrs)
KV_SERIALIZE(get_all)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;
struct response_t
{
std::vector<subaddrs_obj> new_subaddrs;
std::vector<subaddrs_obj> all_subaddrs;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(new_subaddrs)
KV_SERIALIZE(all_subaddrs)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_SUBADDRS
{
struct request_t
{
std::string address;
std::string view_key;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address)
KV_SERIALIZE(view_key)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;
class index_range : public std::vector<uint32_t> {
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
struct subaddrs_t {
uint32_t key;
std::vector<index_range> value;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(key)
KV_SERIALIZE(value)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<subaddrs_t> subaddrs;
struct response_t
{
std::vector<subaddrs> all_subaddrs;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(all_subaddrs)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
}