mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-18 15:51:34 +02:00
implemented block notifications in wallet listener
This commit is contained in:
+24
-21
@@ -7,6 +7,30 @@
|
||||
|
||||
using namespace cryptonote;
|
||||
|
||||
/**
|
||||
* Adapts wallet2 notifications to a public listener.
|
||||
*/
|
||||
struct Wallet2ListenerAdapter : public tools::i_wallet2_callback {
|
||||
|
||||
Wallet2ListenerAdapter(MoneroWalletListener* listener) {
|
||||
this->listener = listener;
|
||||
}
|
||||
|
||||
~Wallet2ListenerAdapter() {
|
||||
|
||||
}
|
||||
|
||||
virtual void on_new_block(uint64_t height, const cryptonote::block& cnBlock) {
|
||||
MoneroBlock block;
|
||||
block.height = height;
|
||||
listener->onNewBlock(block);
|
||||
}
|
||||
|
||||
MoneroWalletListener* listener;
|
||||
};
|
||||
|
||||
// ------------------------------- WALLET METHODS -----------------------------
|
||||
|
||||
bool MoneroWallet::walletExists(const string& path) {
|
||||
cout << "walletExists(" << path << ")" << endl;
|
||||
bool keyFileExists;
|
||||
@@ -128,27 +152,6 @@ uint64_t MoneroWallet::getRestoreHeight() const {
|
||||
return wallet2->get_refresh_from_block_height();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts wallet2 notifications to a public listener.
|
||||
*/
|
||||
struct Wallet2ListenerAdapter : public tools::i_wallet2_callback {
|
||||
|
||||
Wallet2ListenerAdapter(MoneroWalletListener* listener) {
|
||||
this->listener = listener;
|
||||
}
|
||||
|
||||
~Wallet2ListenerAdapter() {
|
||||
|
||||
}
|
||||
|
||||
virtual void on_new_block(uint64_t height, const cryptonote::block& block) {
|
||||
cout << "Wallet2ListenerAdapter.on_new_block()" << endl;
|
||||
throw runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
MoneroWalletListener* listener;
|
||||
};
|
||||
|
||||
void MoneroWallet::setListener(MoneroWalletListener* listener) {
|
||||
cout << "setListener()" << endl;
|
||||
this->listener = listener;
|
||||
|
||||
@@ -23,15 +23,14 @@ namespace monero {
|
||||
};
|
||||
|
||||
/**
|
||||
* Models a result of syncing a wallet.
|
||||
* Models a Monero block header.
|
||||
*/
|
||||
struct MoneroBlockHeader {
|
||||
uint64_t height;
|
||||
MoneroBlockHeader() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Models a result of syncing a wallet.
|
||||
* Models a Monero block.
|
||||
*/
|
||||
struct MoneroBlock : public MoneroBlockHeader {
|
||||
// TODO
|
||||
@@ -69,6 +68,7 @@ namespace monero {
|
||||
* Receives progress notifications as a wallet is synchronized.
|
||||
*/
|
||||
class MoneroSyncListener {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Invoked when sync progress is made.
|
||||
@@ -86,6 +86,7 @@ namespace monero {
|
||||
* Receives notifications as a wallet is updated.
|
||||
*/
|
||||
class MoneroWalletListener : public MoneroSyncListener {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Invoked when a new block is processed.
|
||||
|
||||
Reference in New Issue
Block a user