Skip to content

Commit

Permalink
Fix wallet output scanning, remove lightwallet
Browse files Browse the repository at this point in the history
  • Loading branch information
who-biz committed Jul 10, 2019
1 parent 92748d5 commit 81bdea5
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 926 deletions.
2 changes: 0 additions & 2 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ namespace
} refresh_type_names[] =
{
{ "full", tools::wallet2::RefreshFull },
{ "optimize-coinbase", tools::wallet2::RefreshOptimizeCoinbase },
{ "optimized-coinbase", tools::wallet2::RefreshOptimizeCoinbase },
{ "no-coinbase", tools::wallet2::RefreshNoCoinbase },
{ "default", tools::wallet2::RefreshDefault },
};
Expand Down
81 changes: 2 additions & 79 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,37 +170,6 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
// TODO;
}

// Light wallet callbacks
virtual void on_lw_new_block(uint64_t height)
{
if (m_listener) {
m_listener->newBlock(height);
}
}

virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount)
{
if (m_listener) {
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
m_listener->moneyReceived(tx_hash, amount);
}
}

virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount)
{
if (m_listener) {
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
m_listener->unconfirmedMoneyReceived(tx_hash, amount);
}
}

virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount)
{
if (m_listener) {
std::string tx_hash = epee::string_tools::pod_to_hex(txid);
m_listener->moneySpent(tx_hash, amount);
}
}

WalletListener * m_listener;
WalletImpl * m_wallet;
Expand Down Expand Up @@ -799,47 +768,14 @@ string WalletImpl::keysFilename() const
return m_wallet->get_keys_file();
}

bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password, bool use_ssl, bool lightWallet)
bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password, bool use_ssl)
{
clearStatus();
m_wallet->set_light_wallet(lightWallet);
if(daemon_username != "")
m_daemon_login.emplace(daemon_username, daemon_password);
return doInit(daemon_address, upper_transaction_size_limit, use_ssl);
}

bool WalletImpl::lightWalletLogin(bool &isNewWallet) const
{
return m_wallet->light_wallet_login(isNewWallet);
}

bool WalletImpl::lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status)
{
try
{
cryptonote::COMMAND_RPC_IMPORT_WALLET_REQUEST::response response;
if(!m_wallet->light_wallet_import_wallet_request(response)){
m_errorString = tr("Failed to send import wallet request");
m_status = Status_Error;
return false;
}
fee = response.import_fee;
payment_id = response.payment_id;
new_request = response.new_request;
request_fulfilled = response.request_fulfilled;
payment_address = response.payment_address;
status = response.status;
}
catch (const std::exception &e)
{
LOG_ERROR("Error sending import wallet request: " << e.what());
m_errorString = e.what();
m_status = Status_Error;
return false;
}
return true;
}

void WalletImpl::setRefreshFromBlockHeight(uint64_t refresh_from_block_height)
{
m_wallet->set_refresh_from_block_height(refresh_from_block_height);
Expand All @@ -862,9 +798,6 @@ uint64_t WalletImpl::unlockedBalance(uint32_t accountIndex) const

uint64_t WalletImpl::blockChainHeight() const
{
if(m_wallet->light_wallet()) {
return m_wallet->get_light_wallet_scanned_block_height();
}
return m_wallet->get_blockchain_current_height();
}
uint64_t WalletImpl::approximateBlockChainHeight() const
Expand All @@ -879,9 +812,6 @@ uint64_t WalletImpl::estimateBlockChainHeight() const

uint64_t WalletImpl::daemonBlockChainHeight() const
{
if(m_wallet->light_wallet()) {
return m_wallet->get_light_wallet_scanned_block_height();
}
if (!m_is_connected)
return 0;
std::string err;
Expand All @@ -901,9 +831,6 @@ uint64_t WalletImpl::daemonBlockChainHeight() const

uint64_t WalletImpl::daemonBlockChainTargetHeight() const
{
if(m_wallet->light_wallet()) {
return m_wallet->get_light_wallet_blockchain_height();
}
if (!m_is_connected)
return 0;
std::string err;
Expand Down Expand Up @@ -1630,9 +1557,6 @@ Wallet::ConnectionStatus WalletImpl::connected() const
m_is_connected = m_wallet->check_connection(&version, DEFAULT_CONNECTION_TIMEOUT_MILLIS);
if (!m_is_connected)
return Wallet::ConnectionStatus_Disconnected;
// Version check is not implemented in light wallets nodes/wallets
if (!m_wallet->light_wallet() && (version >> 16) != CORE_RPC_VERSION_MAJOR)
return Wallet::ConnectionStatus_WrongVersion;
return Wallet::ConnectionStatus_Connected;
}

Expand Down Expand Up @@ -1694,7 +1618,7 @@ void WalletImpl::doRefresh()
try {
// Syncing daemon and refreshing wallet simultaneously is very resource intensive.
// Disable refresh if wallet is disconnected or daemon isn't synced.
if (m_wallet->light_wallet() || daemonSynced()) {
if (daemonSynced()) {
m_wallet->refresh();
if (!m_synchronized) {
m_synchronized = true;
Expand Down Expand Up @@ -1767,7 +1691,6 @@ bool WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction

// in case new wallet, this will force fast-refresh (pulling hashes instead of blocks)
// If daemon isn't synced a calculated block height will be used instead
//TODO: Handle light wallet scenario where block height = 0.
if (isNewWallet() && daemonSynced()) {
LOG_PRINT_L2(__FUNCTION__ << ":New Wallet - fast refresh until " << daemonBlockChainHeight());
m_wallet->set_refresh_from_block_height(daemonBlockChainHeight());
Expand Down
4 changes: 1 addition & 3 deletions src/wallet/api/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class WalletImpl : public Wallet
bool store(const std::string &path);
std::string filename() const;
std::string keysFilename() const;
bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false);
bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false);
bool connectToDaemon();
ConnectionStatus connected() const;
void setTrustedDaemon(bool arg);
Expand Down Expand Up @@ -162,8 +162,6 @@ class WalletImpl : public Wallet
virtual void pauseRefresh();
virtual bool parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error);
virtual std::string getDefaultDataDir() const;
virtual bool lightWalletLogin(bool &isNewWallet) const;
virtual bool lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status);
virtual bool blackballOutputs(const std::vector<std::string> &pubkeys, bool add);
virtual bool unblackballOutput(const std::string &pubkey);
virtual bool getRing(const std::string &key_image, std::vector<uint64_t> &ring) const;
Expand Down
8 changes: 1 addition & 7 deletions src/wallet/api/wallet2_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,9 @@ struct Wallet
* \param upper_transaction_size_limit
* \param daemon_username
* \param daemon_password
* \param lightWallet - start wallet in light mode, connect to a openmonero compatible server.
* \return - true on success
*/
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false) = 0;
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false) = 0;

/*!
* \brief createWatchOnly - Creates a watch only wallet
Expand Down Expand Up @@ -781,11 +780,6 @@ struct Wallet
//! secondary key reuse mitigation
virtual void keyReuseMitigation2(bool mitigation) = 0;

//! Light wallet authenticate and login
virtual bool lightWalletLogin(bool &isNewWallet) const = 0;

//! Initiates a light wallet import wallet request
virtual bool lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status) = 0;
};

/**
Expand Down
Loading

0 comments on commit 81bdea5

Please sign in to comment.