mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-23 01:48:52 +00:00
WalletListener functionality
This commit is contained in:
parent
d27b883b2d
commit
9d2cb4f36c
@ -46,6 +46,7 @@ namespace Bitmonero {
|
|||||||
namespace {
|
namespace {
|
||||||
// copy-pasted from simplewallet
|
// copy-pasted from simplewallet
|
||||||
static const size_t DEFAULT_MIXIN = 4;
|
static const size_t DEFAULT_MIXIN = 4;
|
||||||
|
static const int DEFAULT_REFRESH_INTERVAL_SECONDS = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
||||||
@ -75,7 +76,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
|||||||
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
|
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
|
||||||
{
|
{
|
||||||
// TODO;
|
// TODO;
|
||||||
LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
|
LOG_PRINT_L0(__FUNCTION__ << ": new block. height: " << height);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void on_money_received(uint64_t height, const cryptonote::transaction& tx, size_t out_index)
|
virtual void on_money_received(uint64_t height, const cryptonote::transaction& tx, size_t out_index)
|
||||||
@ -84,11 +85,12 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
|||||||
std::string tx_hash = epee::string_tools::pod_to_hex(get_transaction_hash(tx));
|
std::string tx_hash = epee::string_tools::pod_to_hex(get_transaction_hash(tx));
|
||||||
uint64_t amount = tx.vout[out_index].amount;
|
uint64_t amount = tx.vout[out_index].amount;
|
||||||
|
|
||||||
LOG_PRINT_L3(__FUNCTION__ << ": money received. height: " << height
|
LOG_PRINT_L0(__FUNCTION__ << ": money received. height: " << height
|
||||||
<< ", tx: " << tx_hash
|
<< ", tx: " << tx_hash
|
||||||
<< ", amount: " << print_money(amount));
|
<< ", amount: " << print_money(amount));
|
||||||
if (m_listener) {
|
if (m_listener) {
|
||||||
m_listener->moneyReceived(tx_hash, amount);
|
m_listener->moneyReceived(tx_hash, amount);
|
||||||
|
m_listener->updated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,11 +100,12 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
|
|||||||
// TODO;
|
// TODO;
|
||||||
std::string tx_hash = epee::string_tools::pod_to_hex(get_transaction_hash(spend_tx));
|
std::string tx_hash = epee::string_tools::pod_to_hex(get_transaction_hash(spend_tx));
|
||||||
uint64_t amount = in_tx.vout[out_index].amount;
|
uint64_t amount = in_tx.vout[out_index].amount;
|
||||||
LOG_PRINT_L3(__FUNCTION__ << ": money spent. height: " << height
|
LOG_PRINT_L0(__FUNCTION__ << ": money spent. height: " << height
|
||||||
<< ", tx: " << tx_hash
|
<< ", tx: " << tx_hash
|
||||||
<< ", amount: " << print_money(amount));
|
<< ", amount: " << print_money(amount));
|
||||||
if (m_listener) {
|
if (m_listener) {
|
||||||
m_listener->moneySpent(tx_hash, amount);
|
m_listener->moneySpent(tx_hash, amount);
|
||||||
|
m_listener->updated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,13 +162,22 @@ WalletImpl::WalletImpl(bool testnet)
|
|||||||
m_wallet = new tools::wallet2(testnet);
|
m_wallet = new tools::wallet2(testnet);
|
||||||
m_history = new TransactionHistoryImpl(this);
|
m_history = new TransactionHistoryImpl(this);
|
||||||
m_wallet2Callback = new Wallet2CallbackImpl;
|
m_wallet2Callback = new Wallet2CallbackImpl;
|
||||||
|
m_wallet->callback(m_wallet2Callback);
|
||||||
|
m_refreshThreadDone = false;
|
||||||
|
m_refreshEnabled = false;
|
||||||
|
m_refreshIntervalSeconds = DEFAULT_REFRESH_INTERVAL_SECONDS;
|
||||||
|
m_refreshThread = std::thread([this] () {
|
||||||
|
this->refreshThreadFunc();
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletImpl::~WalletImpl()
|
WalletImpl::~WalletImpl()
|
||||||
{
|
{
|
||||||
delete m_wallet2Callback;
|
stopRefresh();
|
||||||
delete m_history;
|
delete m_history;
|
||||||
delete m_wallet;
|
delete m_wallet;
|
||||||
|
delete m_wallet2Callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WalletImpl::create(const std::string &path, const std::string &password, const std::string &language)
|
bool WalletImpl::create(const std::string &path, const std::string &password, const std::string &language)
|
||||||
@ -359,6 +371,7 @@ bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transact
|
|||||||
if (Utils::isAddressLocal(daemon_address)) {
|
if (Utils::isAddressLocal(daemon_address)) {
|
||||||
this->setTrustedDaemon(true);
|
this->setTrustedDaemon(true);
|
||||||
}
|
}
|
||||||
|
startRefresh();
|
||||||
|
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
LOG_ERROR("Error initializing wallet: " << e.what());
|
LOG_ERROR("Error initializing wallet: " << e.what());
|
||||||
@ -383,15 +396,17 @@ uint64_t WalletImpl::unlockedBalance() const
|
|||||||
bool WalletImpl::refresh()
|
bool WalletImpl::refresh()
|
||||||
{
|
{
|
||||||
clearStatus();
|
clearStatus();
|
||||||
try {
|
doRefresh();
|
||||||
m_wallet->refresh();
|
|
||||||
} catch (const std::exception &e) {
|
|
||||||
m_status = Status_Error;
|
|
||||||
m_errorString = e.what();
|
|
||||||
}
|
|
||||||
return m_status == Status_Ok;
|
return m_status == Status_Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WalletImpl::refreshAsync()
|
||||||
|
{
|
||||||
|
LOG_PRINT_L3(__FUNCTION__ << ": Refreshing asyncronously..");
|
||||||
|
clearStatus();
|
||||||
|
m_refreshCV.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// 1 - properly handle payment id (add another menthod with explicit 'payment_id' param)
|
// 1 - properly handle payment id (add another menthod with explicit 'payment_id' param)
|
||||||
// 2 - check / design how "Transaction" can be single interface
|
// 2 - check / design how "Transaction" can be single interface
|
||||||
@ -574,6 +589,8 @@ bool WalletImpl::connectToDaemon()
|
|||||||
m_status = result ? Status_Ok : Status_Error;
|
m_status = result ? Status_Ok : Status_Error;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
m_errorString = "Error connecting to daemon at " + m_wallet->get_daemon_address();
|
m_errorString = "Error connecting to daemon at " + m_wallet->get_daemon_address();
|
||||||
|
} else {
|
||||||
|
// start refreshing here
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -594,5 +611,57 @@ void WalletImpl::clearStatus()
|
|||||||
m_errorString.clear();
|
m_errorString.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WalletImpl::refreshThreadFunc()
|
||||||
|
{
|
||||||
|
LOG_PRINT_L3(__FUNCTION__ << ": starting refresh thread");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
std::unique_lock<std::mutex> lock(m_refreshMutex);
|
||||||
|
if (m_refreshThreadDone) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
m_refreshCV.wait_for(lock, std::chrono::seconds(m_refreshIntervalSeconds));
|
||||||
|
if (m_refreshEnabled && m_status == Status_Ok) {
|
||||||
|
doRefresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_PRINT_L3(__FUNCTION__ << ": refresh thread stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
void WalletImpl::doRefresh()
|
||||||
|
{
|
||||||
|
// synchronizing async and sync refresh calls
|
||||||
|
std::lock_guard<std::mutex> guarg(m_refreshMutex2);
|
||||||
|
try {
|
||||||
|
m_wallet->refresh();
|
||||||
|
if (m_walletListener) {
|
||||||
|
m_walletListener->refreshed();
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
m_status = Status_Error;
|
||||||
|
m_errorString = e.what();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// supposed to be called from ctor only
|
||||||
|
void WalletImpl::startRefresh()
|
||||||
|
{
|
||||||
|
if (!m_refreshEnabled) {
|
||||||
|
m_refreshEnabled = true;
|
||||||
|
m_refreshCV.notify_one();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// supposed to be called from dtor only
|
||||||
|
void WalletImpl::stopRefresh()
|
||||||
|
{
|
||||||
|
if (!m_refreshThreadDone) {
|
||||||
|
m_refreshEnabled = false;
|
||||||
|
m_refreshThreadDone = true;
|
||||||
|
m_refreshThread.join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -35,6 +35,9 @@
|
|||||||
#include "wallet/wallet2.h"
|
#include "wallet/wallet2.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
|
|
||||||
namespace Bitmonero {
|
namespace Bitmonero {
|
||||||
@ -71,7 +74,7 @@ public:
|
|||||||
uint64_t balance() const;
|
uint64_t balance() const;
|
||||||
uint64_t unlockedBalance() const;
|
uint64_t unlockedBalance() const;
|
||||||
bool refresh();
|
bool refresh();
|
||||||
|
void refreshAsync();
|
||||||
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
|
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
|
||||||
uint64_t amount, uint32_t mixin_count,
|
uint64_t amount, uint32_t mixin_count,
|
||||||
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
|
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
|
||||||
@ -84,19 +87,33 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void clearStatus();
|
void clearStatus();
|
||||||
|
void refreshThreadFunc();
|
||||||
|
void doRefresh();
|
||||||
|
void startRefresh();
|
||||||
|
void stopRefresh();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PendingTransactionImpl;
|
friend class PendingTransactionImpl;
|
||||||
friend class TransactionHistoryImpl;
|
friend class TransactionHistoryImpl;
|
||||||
|
|
||||||
tools::wallet2 * m_wallet;
|
tools::wallet2 * m_wallet;
|
||||||
int m_status;
|
std::atomic<int> m_status;
|
||||||
std::string m_errorString;
|
std::string m_errorString;
|
||||||
std::string m_password;
|
std::string m_password;
|
||||||
TransactionHistoryImpl * m_history;
|
TransactionHistoryImpl * m_history;
|
||||||
bool m_trustedDaemon;
|
bool m_trustedDaemon;
|
||||||
WalletListener * m_walletListener;
|
WalletListener * m_walletListener;
|
||||||
Wallet2CallbackImpl * m_wallet2Callback;
|
Wallet2CallbackImpl * m_wallet2Callback;
|
||||||
|
|
||||||
|
// multi-threaded refresh stuff
|
||||||
|
std::atomic<bool> m_refreshEnabled;
|
||||||
|
std::atomic<bool> m_refreshThreadDone;
|
||||||
|
std::atomic<int> m_refreshIntervalSeconds;
|
||||||
|
std::mutex m_refreshMutex;
|
||||||
|
std::mutex m_refreshMutex2;
|
||||||
|
std::condition_variable m_refreshCV;
|
||||||
|
std::thread m_refreshThread;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,7 +116,11 @@ struct WalletListener
|
|||||||
virtual ~WalletListener() = 0;
|
virtual ~WalletListener() = 0;
|
||||||
virtual void moneySpent(const std::string &txId, uint64_t amount) = 0;
|
virtual void moneySpent(const std::string &txId, uint64_t amount) = 0;
|
||||||
virtual void moneyReceived(const std::string &txId, uint64_t amount) = 0;
|
virtual void moneyReceived(const std::string &txId, uint64_t amount) = 0;
|
||||||
// TODO: on_skip_transaction;
|
// generic callback, called when any event happened with the wallet;
|
||||||
|
virtual void updated() = 0;
|
||||||
|
// called when wallet refreshed by background thread or explicitly
|
||||||
|
virtual void refreshed() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -188,6 +192,8 @@ struct Wallet
|
|||||||
// TODO?
|
// TODO?
|
||||||
// virtual uint64_t unlockedDustBalance() const = 0;
|
// virtual uint64_t unlockedDustBalance() const = 0;
|
||||||
virtual bool refresh() = 0;
|
virtual bool refresh() = 0;
|
||||||
|
|
||||||
|
virtual void refreshAsync() = 0;
|
||||||
/*!
|
/*!
|
||||||
* \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored
|
* \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored
|
||||||
* \param dst_addr destination address as string
|
* \param dst_addr destination address as string
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -71,7 +73,7 @@ const std::string TESTNET_WALLET6_NAME = WALLETS_ROOT_DIR + "wallet_06.bin";
|
|||||||
|
|
||||||
const char * TESTNET_WALLET_PASS = "";
|
const char * TESTNET_WALLET_PASS = "";
|
||||||
|
|
||||||
const std::string CURRENT_SRC_WALLET = TESTNET_WALLET1_NAME;
|
const std::string CURRENT_SRC_WALLET = TESTNET_WALLET3_NAME;
|
||||||
const std::string CURRENT_DST_WALLET = TESTNET_WALLET6_NAME;
|
const std::string CURRENT_DST_WALLET = TESTNET_WALLET6_NAME;
|
||||||
|
|
||||||
const char * TESTNET_DAEMON_ADDRESS = "localhost:38081";
|
const char * TESTNET_DAEMON_ADDRESS = "localhost:38081";
|
||||||
@ -176,6 +178,7 @@ struct WalletTest2 : public testing::Test
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
|
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
|
||||||
{
|
{
|
||||||
@ -235,7 +238,7 @@ TEST_F(WalletManagerTest, WalletManagerMovesWallet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
|
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
|
||||||
{
|
{
|
||||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||||
@ -345,6 +348,8 @@ TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
TEST_F(WalletManagerTest, WalletManagerFindsWallet)
|
TEST_F(WalletManagerTest, WalletManagerFindsWallet)
|
||||||
{
|
{
|
||||||
std::vector<std::string> wallets = wmgr->findWallets(WALLETS_ROOT_DIR);
|
std::vector<std::string> wallets = wmgr->findWallets(WALLETS_ROOT_DIR);
|
||||||
@ -415,7 +420,7 @@ TEST_F(WalletTest1, WalletConvertsToString)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
TEST_F(WalletTest1, WalletTransaction)
|
TEST_F(WalletTest1, WalletTransaction)
|
||||||
{
|
{
|
||||||
Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
||||||
@ -429,8 +434,10 @@ TEST_F(WalletTest1, WalletTransaction)
|
|||||||
wallet1->setDefaultMixin(1);
|
wallet1->setDefaultMixin(1);
|
||||||
ASSERT_TRUE(wallet1->defaultMixin() == 1);
|
ASSERT_TRUE(wallet1->defaultMixin() == 1);
|
||||||
|
|
||||||
Bitmonero::PendingTransaction * transaction = wallet1->createTransaction(
|
Bitmonero::PendingTransaction * transaction = wallet1->createTransaction(recepient_address,
|
||||||
recepient_address, AMOUNT_10XMR);
|
PAYMENT_ID_EMPTY,
|
||||||
|
AMOUNT_10XMR,
|
||||||
|
1);
|
||||||
ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok);
|
ASSERT_TRUE(transaction->status() == Bitmonero::PendingTransaction::Status_Ok);
|
||||||
wallet1->refresh();
|
wallet1->refresh();
|
||||||
|
|
||||||
@ -440,7 +447,6 @@ TEST_F(WalletTest1, WalletTransaction)
|
|||||||
ASSERT_FALSE(wallet1->balance() == balance);
|
ASSERT_FALSE(wallet1->balance() == balance);
|
||||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
TEST_F(WalletTest1, WalletTransactionWithMixin)
|
TEST_F(WalletTest1, WalletTransactionWithMixin)
|
||||||
{
|
{
|
||||||
@ -564,7 +570,7 @@ TEST_F(WalletTest1, WalletTransactionAndHistory)
|
|||||||
|
|
||||||
Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
|
Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet4_addr,
|
||||||
PAYMENT_ID_EMPTY,
|
PAYMENT_ID_EMPTY,
|
||||||
AMOUNT_10XMR * 5, 0);
|
AMOUNT_10XMR * 5, 1);
|
||||||
|
|
||||||
ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
|
ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
|
||||||
ASSERT_TRUE(tx->commit());
|
ASSERT_TRUE(tx->commit());
|
||||||
@ -627,6 +633,7 @@ TEST_F(WalletTest1, WalletTransactionWithPaymentId)
|
|||||||
|
|
||||||
ASSERT_TRUE(payment_id_in_history);
|
ASSERT_TRUE(payment_id_in_history);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
struct MyWalletListener : public Bitmonero::WalletListener
|
struct MyWalletListener : public Bitmonero::WalletListener
|
||||||
{
|
{
|
||||||
@ -634,7 +641,8 @@ struct MyWalletListener : public Bitmonero::WalletListener
|
|||||||
Bitmonero::Wallet * wallet;
|
Bitmonero::Wallet * wallet;
|
||||||
uint64_t total_tx;
|
uint64_t total_tx;
|
||||||
uint64_t total_rx;
|
uint64_t total_rx;
|
||||||
std::timed_mutex guard;
|
std::mutex mutex;
|
||||||
|
std::condition_variable cv;
|
||||||
|
|
||||||
MyWalletListener(Bitmonero::Wallet * wallet)
|
MyWalletListener(Bitmonero::Wallet * wallet)
|
||||||
: total_tx(0), total_rx(0)
|
: total_tx(0), total_rx(0)
|
||||||
@ -645,79 +653,110 @@ struct MyWalletListener : public Bitmonero::WalletListener
|
|||||||
|
|
||||||
virtual void moneySpent(const string &txId, uint64_t amount)
|
virtual void moneySpent(const string &txId, uint64_t amount)
|
||||||
{
|
{
|
||||||
std::cout << "wallet: " << wallet->address() << " just spent money ("
|
std::cerr << "wallet: " << wallet->address() << "**** just spent money ("
|
||||||
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
|
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
|
||||||
total_tx += amount;
|
total_tx += amount;
|
||||||
guard.unlock();
|
cv.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void moneyReceived(const string &txId, uint64_t amount)
|
virtual void moneyReceived(const string &txId, uint64_t amount)
|
||||||
{
|
{
|
||||||
std::cout << "wallet: " << wallet->address() << " just received money ("
|
std::cout << "wallet: " << wallet->address() << "**** just received money ("
|
||||||
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
|
<< txId << ", " << wallet->displayAmount(amount) << ")" << std::endl;
|
||||||
total_rx += amount;
|
total_rx += amount;
|
||||||
guard.unlock();
|
cv.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void updated()
|
||||||
|
{
|
||||||
|
cv.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void refreshed()
|
||||||
|
{
|
||||||
|
std::cout << "Wallet refreshed";
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
TEST_F(WalletTest2, WalletCallbackSent)
|
TEST_F(WalletTest2, WalletCallbackSent)
|
||||||
{
|
{
|
||||||
|
|
||||||
Bitmonero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET3_NAME, TESTNET_WALLET_PASS, true);
|
Bitmonero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
||||||
// make sure testnet daemon is running
|
// make sure testnet daemon is running
|
||||||
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||||
ASSERT_TRUE(wallet_src->refresh());
|
ASSERT_TRUE(wallet_src->refresh());
|
||||||
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
|
MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src);
|
||||||
|
uint64_t balance = wallet_src->balance();
|
||||||
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
|
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
|
||||||
|
Bitmonero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
|
||||||
|
|
||||||
|
uint64_t amount = AMOUNT_1XMR * 5;
|
||||||
|
std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
|
||||||
|
|
||||||
|
|
||||||
uint64_t amount = AMOUNT_10XMR * 5;
|
Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
|
||||||
std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << TESTNET_WALLET4_ADDRESS;
|
PAYMENT_ID_EMPTY,
|
||||||
Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(TESTNET_WALLET4_ADDRESS, AMOUNT_1XMR * 5);
|
amount, 1);
|
||||||
|
std::cout << "** Committing transaction: " << Bitmonero::Wallet::displayAmount(tx->amount())
|
||||||
|
<< " with fee: " << Bitmonero::Wallet::displayAmount(tx->fee());
|
||||||
|
|
||||||
ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
|
ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
|
||||||
ASSERT_TRUE(tx->commit());
|
ASSERT_TRUE(tx->commit());
|
||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(60*3);
|
std::chrono::seconds wait_for = std::chrono::seconds(60*3);
|
||||||
|
std::unique_lock<std::mutex> lock (wallet_src_listener->mutex);
|
||||||
wallet_src_listener->guard.lock();
|
wallet_src_listener->cv.wait_for(lock, wait_for);
|
||||||
wallet_src_listener->guard.try_lock_for(wait_for);
|
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
|
||||||
|
ASSERT_TRUE(wallet_src->balance() < balance);
|
||||||
ASSERT_TRUE(wallet_src_listener->total_tx != 0);
|
wmgr->closeWallet(wallet_src);
|
||||||
|
wmgr->closeWallet(wallet_dst);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
TEST_F(WalletTest2, WalletCallbackReceived)
|
TEST_F(WalletTest2, WalletCallbackReceived)
|
||||||
{
|
{
|
||||||
|
|
||||||
Bitmonero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET3_NAME, TESTNET_WALLET_PASS, true);
|
Bitmonero::Wallet * wallet_src = wmgr->openWallet(TESTNET_WALLET5_NAME, TESTNET_WALLET_PASS, true);
|
||||||
// make sure testnet daemon is running
|
// make sure testnet daemon is running
|
||||||
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||||
ASSERT_TRUE(wallet_src->refresh());
|
ASSERT_TRUE(wallet_src->refresh());
|
||||||
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
|
std::cout << "** Balance: " << wallet_src->displayAmount(wallet_src->balance()) << std::endl;
|
||||||
|
|
||||||
Bitmonero::Wallet * wallet_dst = wmgr->openWallet(TESTNET_WALLET4_NAME, TESTNET_WALLET_PASS, true);
|
Bitmonero::Wallet * wallet_dst = wmgr->openWallet(CURRENT_DST_WALLET, TESTNET_WALLET_PASS, true);
|
||||||
ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0));
|
ASSERT_TRUE(wallet_dst->init(TESTNET_DAEMON_ADDRESS, 0));
|
||||||
ASSERT_TRUE(wallet_dst->refresh());
|
ASSERT_TRUE(wallet_dst->refresh());
|
||||||
|
uint64_t balance = wallet_dst->balance();
|
||||||
MyWalletListener * wallet_dst_listener = new MyWalletListener(wallet_dst);
|
MyWalletListener * wallet_dst_listener = new MyWalletListener(wallet_dst);
|
||||||
|
|
||||||
|
|
||||||
uint64_t amount = AMOUNT_1XMR * 5;
|
uint64_t amount = AMOUNT_1XMR * 5;
|
||||||
std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << TESTNET_WALLET4_ADDRESS;
|
std::cout << "** Sending " << Bitmonero::Wallet::displayAmount(amount) << " to " << wallet_dst->address();
|
||||||
Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(TESTNET_WALLET4_ADDRESS, AMOUNT_1XMR * 5);
|
Bitmonero::PendingTransaction * tx = wallet_src->createTransaction(wallet_dst->address(),
|
||||||
|
PAYMENT_ID_EMPTY,
|
||||||
|
amount, 1);
|
||||||
|
|
||||||
|
std::cout << "** Committing transaction: " << Bitmonero::Wallet::displayAmount(tx->amount())
|
||||||
|
<< " with fee: " << Bitmonero::Wallet::displayAmount(tx->fee());
|
||||||
|
|
||||||
ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
|
ASSERT_TRUE(tx->status() == Bitmonero::PendingTransaction::Status_Ok);
|
||||||
ASSERT_TRUE(tx->commit());
|
ASSERT_TRUE(tx->commit());
|
||||||
|
|
||||||
std::chrono::seconds wait_for = std::chrono::seconds(60*4);
|
std::chrono::seconds wait_for = std::chrono::seconds(60*4);
|
||||||
|
std::unique_lock<std::mutex> lock (wallet_dst_listener->mutex);
|
||||||
|
wallet_dst_listener->cv.wait_for(lock, wait_for);
|
||||||
|
std::cout << "** Balance: " << wallet_dst->displayAmount(wallet_src->balance()) << std::endl;
|
||||||
|
ASSERT_TRUE(wallet_dst->balance() > balance);
|
||||||
|
|
||||||
wallet_dst_listener->guard.lock();
|
wmgr->closeWallet(wallet_src);
|
||||||
wallet_dst_listener->guard.try_lock_for(wait_for);
|
wmgr->closeWallet(wallet_dst);
|
||||||
|
|
||||||
ASSERT_TRUE(wallet_dst_listener->total_tx != 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -12,11 +12,23 @@ function send_funds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
send_funds 100 wallet_01.bin
|
function seed_wallets {
|
||||||
send_funds 100 wallet_02.bin
|
local amount=$1
|
||||||
send_funds 100 wallet_03.bin
|
send_funds $amount wallet_01.bin
|
||||||
send_funds 100 wallet_04.bin
|
send_funds $amount wallet_02.bin
|
||||||
send_funds 100 wallet_05.bin
|
send_funds $amount wallet_03.bin
|
||||||
send_funds 100 wallet_06.bin
|
send_funds $amount wallet_04.bin
|
||||||
|
send_funds $amount wallet_05.bin
|
||||||
|
send_funds $amount wallet_06.bin
|
||||||
|
}
|
||||||
|
|
||||||
|
seed_wallets 1
|
||||||
|
seed_wallets 2
|
||||||
|
seed_wallets 5
|
||||||
|
seed_wallets 10
|
||||||
|
seed_wallets 20
|
||||||
|
seed_wallets 50
|
||||||
|
seed_wallets 100
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user