sample code completing successfully;

implement wait_for_next_block() without returning height;
fix query make_shared copy
This commit is contained in:
woodser
2019-08-11 09:47:09 -04:00
parent 0c0e4e0b32
commit c111b0acd7
4 changed files with 68 additions and 16 deletions
+42 -6
View File
@@ -1481,15 +1481,17 @@ namespace monero {
// copy and normalize query
shared_ptr<monero_transfer_query> _query;
if (query.m_tx_query == boost::none) _query = query.copy(make_shared<monero_transfer_query>(query), make_shared<monero_transfer_query>());
else {
if (query.m_tx_query == boost::none) {
shared_ptr<monero_transfer_query> query_ptr = make_shared<monero_transfer_query>(query); // convert to shared pointer for copy // TODO: does this copy unecessarily? copy constructor is not defined
_query = query_ptr->copy(query_ptr, make_shared<monero_transfer_query>());
} else {
shared_ptr<monero_tx_query> tx_query = query.m_tx_query.get()->copy(query.m_tx_query.get(), make_shared<monero_tx_query>());
if (query.m_tx_query.get()->m_transfer_query != boost::none && query.m_tx_query.get()->m_transfer_query.get().get() == &query) {
_query = tx_query->m_transfer_query.get();
} else {
if (query.m_tx_query.get()->m_transfer_query != boost::none) throw new runtime_error("Transfer query's tx query must be a circular reference or null");
shared_ptr<monero_transfer_query> querySp = make_shared<monero_transfer_query>(query); // convert query to shared pointer for copy
_query = querySp->copy(querySp, make_shared<monero_transfer_query>());
shared_ptr<monero_transfer_query> query_ptr = make_shared<monero_transfer_query>(query); // convert query to shared pointer for copy
_query = query_ptr->copy(query_ptr, make_shared<monero_transfer_query>());
_query->m_tx_query = tx_query;
}
}
@@ -1617,8 +1619,10 @@ namespace monero {
// copy and normalize query
shared_ptr<monero_output_query> _query;
if (query.m_tx_query == boost::none) _query = query.copy(make_shared<monero_output_query>(query), make_shared<monero_output_query>());
else {
if (query.m_tx_query == boost::none) {
shared_ptr<monero_output_query> query_ptr = make_shared<monero_output_query>(query); // convert to shared pointer for copy
_query = query_ptr->copy(query_ptr, make_shared<monero_output_query>());
} else {
shared_ptr<monero_tx_query> tx_query = query.m_tx_query.get()->copy(query.m_tx_query.get(), make_shared<monero_tx_query>());
if (query.m_tx_query.get()->m_output_query != boost::none && query.m_tx_query.get()->m_output_query.get().get() == &query) {
_query = tx_query->m_output_query.get();
@@ -2490,6 +2494,38 @@ namespace monero {
m_w2->store();
}
uint64_t monero_wallet::wait_for_next_block() {
// use mutex and condition variable to wait for block
boost::mutex temp;
boost::condition_variable cv;
// create listener which notifies condition variable when block is added
struct block_notifier : monero_wallet_listener {
boost::mutex* temp;
boost::condition_variable* cv;
block_notifier(boost::mutex* temp, boost::condition_variable* cv) { this->temp = temp; this->cv = cv; }
void on_new_block(uint64_t height) {
cout << "ON NEW BLOCK!!!! " << height << endl;
//boost::lock_guard<boost::mutex> guarg(*temp);
cv->notify_one();
}
} block_listener(&temp, &cv);
// register the listener
add_listener(block_listener);
// wait until condition variable is notified
boost::mutex::scoped_lock lock(temp);
cv.wait(lock);
// unregister the listener
remove_listener(block_listener);
// return notified height
return 0; // TODO
}
void monero_wallet::move_to(string path, string password) {
MTRACE("move_to(" << path << ", " << password << ")");
m_w2->store_to(path, password);
+7
View File
@@ -1276,6 +1276,13 @@ namespace monero {
*/
void stop_mining();
/**
* Wait for the next block to be added to the chain.
*
* @return the height of the next block when it is added to the chain
*/
uint64_t wait_for_next_block();
/**
* Save the wallet at its current path.
*/