Skip to content
Permalink
Browse files

wallet: move light wallet RPC out of core RPC

It's not nothing to do with it
  • Loading branch information...
moneromooo-monero committed Mar 15, 2019
1 parent c88e992 commit 8fd7452b6e5d97db3986ae280e8cd5a7c8edaa4f
Showing with 334 additions and 296 deletions.
  1. +0 −283 src/rpc/core_rpc_server_commands_defs.h
  2. +11 −11 src/wallet/wallet2.cpp
  3. +3 −2 src/wallet/wallet2.h
  4. +320 −0 src/wallet/wallet_light_rpc.h
@@ -251,223 +251,6 @@ namespace cryptonote
typedef epee::misc_utils::struct_init<response_t> response;
};

//-----------------------------------------------
struct COMMAND_RPC_GET_ADDRESS_TXS
{
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;

struct spent_output {
uint64_t amount;
std::string key_image;
std::string tx_pub_key;
uint64_t out_index;
uint32_t mixin;


BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
KV_SERIALIZE(key_image)
KV_SERIALIZE(tx_pub_key)
KV_SERIALIZE(out_index)
KV_SERIALIZE(mixin)
END_KV_SERIALIZE_MAP()
};

struct transaction
{
uint64_t id;
std::string hash;
uint64_t timestamp;
uint64_t total_received;
uint64_t total_sent;
uint64_t unlock_time;
uint64_t height;
std::list<spent_output> spent_outputs;
std::string payment_id;
bool coinbase;
bool mempool;
uint32_t mixin;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(id)
KV_SERIALIZE(hash)
KV_SERIALIZE(timestamp)
KV_SERIALIZE(total_received)
KV_SERIALIZE(total_sent)
KV_SERIALIZE(unlock_time)
KV_SERIALIZE(height)
KV_SERIALIZE(spent_outputs)
KV_SERIALIZE(payment_id)
KV_SERIALIZE(coinbase)
KV_SERIALIZE(mempool)
KV_SERIALIZE(mixin)
END_KV_SERIALIZE_MAP()
};


struct response_t
{
//std::list<std::string> txs_as_json;
uint64_t total_received;
uint64_t total_received_unlocked = 0; // OpenMonero only
uint64_t scanned_height;
std::vector<transaction> transactions;
uint64_t blockchain_height;
uint64_t scanned_block_height;
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(total_received)
KV_SERIALIZE(total_received_unlocked)
KV_SERIALIZE(scanned_height)
KV_SERIALIZE(transactions)
KV_SERIALIZE(blockchain_height)
KV_SERIALIZE(scanned_block_height)
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};

//-----------------------------------------------
struct COMMAND_RPC_GET_ADDRESS_INFO
{
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;

struct spent_output
{
uint64_t amount;
std::string key_image;
std::string tx_pub_key;
uint64_t out_index;
uint32_t mixin;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
KV_SERIALIZE(key_image)
KV_SERIALIZE(tx_pub_key)
KV_SERIALIZE(out_index)
KV_SERIALIZE(mixin)
END_KV_SERIALIZE_MAP()
};

struct response_t
{
uint64_t locked_funds;
uint64_t total_received;
uint64_t total_sent;
uint64_t scanned_height;
uint64_t scanned_block_height;
uint64_t start_height;
uint64_t transaction_height;
uint64_t blockchain_height;
std::list<spent_output> spent_outputs;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(locked_funds)
KV_SERIALIZE(total_received)
KV_SERIALIZE(total_sent)
KV_SERIALIZE(scanned_height)
KV_SERIALIZE(scanned_block_height)
KV_SERIALIZE(start_height)
KV_SERIALIZE(transaction_height)
KV_SERIALIZE(blockchain_height)
KV_SERIALIZE(spent_outputs)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};

//-----------------------------------------------
struct COMMAND_RPC_GET_UNSPENT_OUTS
{
struct request_t
{
std::string amount;
std::string address;
std::string view_key;
// OpenMonero specific
uint64_t mixin;
bool use_dust;
std::string dust_threshold;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
KV_SERIALIZE(address)
KV_SERIALIZE(view_key)
KV_SERIALIZE(mixin)
KV_SERIALIZE(use_dust)
KV_SERIALIZE(dust_threshold)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;


struct output {
uint64_t amount;
std::string public_key;
uint64_t index;
uint64_t global_index;
std::string rct;
std::string tx_hash;
std::string tx_pub_key;
std::string tx_prefix_hash;
std::vector<std::string> spend_key_images;
uint64_t timestamp;
uint64_t height;


BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
KV_SERIALIZE(public_key)
KV_SERIALIZE(index)
KV_SERIALIZE(global_index)
KV_SERIALIZE(rct)
KV_SERIALIZE(tx_hash)
KV_SERIALIZE(tx_pub_key)
KV_SERIALIZE(tx_prefix_hash)
KV_SERIALIZE(spend_key_images)
KV_SERIALIZE(timestamp)
KV_SERIALIZE(height)
END_KV_SERIALIZE_MAP()
};

struct response_t
{
uint64_t amount;
std::list<output> outputs;
uint64_t per_kb_fee;
std::string status;
std::string reason;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
KV_SERIALIZE(outputs)
KV_SERIALIZE(per_kb_fee)
KV_SERIALIZE(status)
KV_SERIALIZE(reason)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};

//-----------------------------------------------
struct COMMAND_RPC_GET_RANDOM_OUTS
{
@@ -548,72 +331,6 @@ namespace cryptonote
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_LOGIN
{
struct request_t
{
std::string address;
std::string view_key;
bool create_account;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address)
KV_SERIALIZE(view_key)
KV_SERIALIZE(create_account)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;

struct response_t
{
std::string status;
std::string reason;
bool new_address;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
KV_SERIALIZE(reason)
KV_SERIALIZE(new_address)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_IMPORT_WALLET_REQUEST
{
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;

struct response_t
{
std::string payment_id;
uint64_t import_fee;
bool new_request;
bool request_fulfilled;
std::string payment_address;
std::string status;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(payment_id)
KV_SERIALIZE(import_fee)
KV_SERIALIZE(new_request)
KV_SERIALIZE(request_fulfilled)
KV_SERIALIZE(payment_address)
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_TRANSACTIONS
{
struct request_t
@@ -2843,7 +2843,7 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo

// MyMonero get_address_info needs to be called occasionally to trigger wallet sync.
// This call is not really needed for other purposes and can be removed if mymonero changes their backend.
cryptonote::COMMAND_RPC_GET_ADDRESS_INFO::response res;
tools::COMMAND_RPC_GET_ADDRESS_INFO::response res;

// Get basic info
if(light_wallet_get_address_info(res)) {
@@ -8317,8 +8317,8 @@ bool wallet2::light_wallet_login(bool &new_address)
{
MDEBUG("Light wallet login request");
m_light_wallet_connected = false;
cryptonote::COMMAND_RPC_LOGIN::request request;
cryptonote::COMMAND_RPC_LOGIN::response response;
tools::COMMAND_RPC_LOGIN::request request;
tools::COMMAND_RPC_LOGIN::response response;
request.address = get_account().get_public_address_str(m_nettype);
request.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key);
// Always create account if it doesn't exist.
@@ -8342,10 +8342,10 @@ bool wallet2::light_wallet_login(bool &new_address)
return m_light_wallet_connected;
}

bool wallet2::light_wallet_import_wallet_request(cryptonote::COMMAND_RPC_IMPORT_WALLET_REQUEST::response &response)
bool wallet2::light_wallet_import_wallet_request(tools::COMMAND_RPC_IMPORT_WALLET_REQUEST::response &response)
{
MDEBUG("Light wallet import wallet request");
cryptonote::COMMAND_RPC_IMPORT_WALLET_REQUEST::request oreq;
tools::COMMAND_RPC_IMPORT_WALLET_REQUEST::request oreq;
oreq.address = get_account().get_public_address_str(m_nettype);
oreq.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key);
m_daemon_rpc_mutex.lock();
@@ -8361,8 +8361,8 @@ void wallet2::light_wallet_get_unspent_outs()
{
MDEBUG("Getting unspent outs");

cryptonote::COMMAND_RPC_GET_UNSPENT_OUTS::request oreq;
cryptonote::COMMAND_RPC_GET_UNSPENT_OUTS::response ores;
tools::COMMAND_RPC_GET_UNSPENT_OUTS::request oreq;
tools::COMMAND_RPC_GET_UNSPENT_OUTS::response ores;

oreq.amount = "0";
oreq.address = get_account().get_public_address_str(m_nettype);
@@ -8510,11 +8510,11 @@ void wallet2::light_wallet_get_unspent_outs()
}
}

bool wallet2::light_wallet_get_address_info(cryptonote::COMMAND_RPC_GET_ADDRESS_INFO::response &response)
bool wallet2::light_wallet_get_address_info(tools::COMMAND_RPC_GET_ADDRESS_INFO::response &response)
{
MTRACE(__FUNCTION__);

cryptonote::COMMAND_RPC_GET_ADDRESS_INFO::request request;
tools::COMMAND_RPC_GET_ADDRESS_INFO::request request;

request.address = get_account().get_public_address_str(m_nettype);
request.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key);
@@ -8530,8 +8530,8 @@ void wallet2::light_wallet_get_address_txs()
{
MDEBUG("Refreshing light wallet");

cryptonote::COMMAND_RPC_GET_ADDRESS_TXS::request ireq;
cryptonote::COMMAND_RPC_GET_ADDRESS_TXS::response ires;
tools::COMMAND_RPC_GET_ADDRESS_TXS::request ireq;
tools::COMMAND_RPC_GET_ADDRESS_TXS::response ires;

ireq.address = get_account().get_public_address_str(m_nettype);
ireq.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key);
@@ -62,6 +62,7 @@
#include "common/password.h"
#include "node_rpc_proxy.h"
#include "message_store.h"
#include "wallet_light_rpc.h"

#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
@@ -1167,11 +1168,11 @@ namespace tools
// fetch txs and store in m_payments
void light_wallet_get_address_txs();
// get_address_info
bool light_wallet_get_address_info(cryptonote::COMMAND_RPC_GET_ADDRESS_INFO::response &response);
bool light_wallet_get_address_info(tools::COMMAND_RPC_GET_ADDRESS_INFO::response &response);
// Login. new_address is true if address hasn't been used on lw node before.
bool light_wallet_login(bool &new_address);
// Send an import request to lw node. returns info about import fee, address and payment_id
bool light_wallet_import_wallet_request(cryptonote::COMMAND_RPC_IMPORT_WALLET_REQUEST::response &response);
bool light_wallet_import_wallet_request(tools::COMMAND_RPC_IMPORT_WALLET_REQUEST::response &response);
// get random outputs from light wallet server
void light_wallet_get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count);
// Parse rct string
Oops, something went wrong.

0 comments on commit 8fd7452

Please sign in to comment.
You can’t perform that action at this time.