aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2020-01-23 19:31:16 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2020-05-23 20:02:04 -0300
commit2f867203b0c7a4438ce484be4cfa2b29dbf1abf0 (patch)
treee8db2784b603a7c802625cef6db7d18b0a4236ad /src/interfaces
parentcfe22a5f9e1d9e2d3dc8ce177e6c8eb04bc96615 (diff)
Added best block hash to the NotifyHeaderTip and NotifyBlockTip signals.
[ClientModel] best header/block hash cached.
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/node.cpp9
-rw-r--r--src/interfaces/node.h7
-rw-r--r--src/interfaces/wallet.cpp4
-rw-r--r--src/interfaces/wallet.h2
4 files changed, 15 insertions, 7 deletions
diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp
index 3c94e44b53..582bf68ff8 100644
--- a/src/interfaces/node.cpp
+++ b/src/interfaces/node.cpp
@@ -187,6 +187,11 @@ public:
LOCK(::cs_main);
return ::ChainActive().Height();
}
+ uint256 getBestBlockHash() override
+ {
+ const CBlockIndex* tip = WITH_LOCK(::cs_main, return ::ChainActive().Tip());
+ return tip ? tip->GetBlockHash() : Params().GenesisBlock().GetHash();
+ }
int64_t getLastBlockTime() override
{
LOCK(::cs_main);
@@ -310,7 +315,7 @@ public:
std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
{
return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
- fn(sync_state, block->nHeight, block->GetBlockTime(),
+ fn(sync_state, block->GetBlockHash(), block->nHeight, block->GetBlockTime(),
GuessVerificationProgress(Params().TxData(), block));
}));
}
@@ -318,7 +323,7 @@ public:
{
return MakeHandler(
::uiInterface.NotifyHeaderTip_connect([fn](SynchronizationState sync_state, const CBlockIndex* block) {
- fn(sync_state, block->nHeight, block->GetBlockTime(),
+ fn(sync_state, block->GetBlockHash(), block->nHeight, block->GetBlockTime(),
/* verification progress is unused when a header was received */ 0);
}));
}
diff --git a/src/interfaces/node.h b/src/interfaces/node.h
index 45b0e18fae..e4df908847 100644
--- a/src/interfaces/node.h
+++ b/src/interfaces/node.h
@@ -149,6 +149,9 @@ public:
//! Get num blocks.
virtual int getNumBlocks() = 0;
+ //! Get best block hash.
+ virtual uint256 getBestBlockHash() = 0;
+
//! Get last block time.
virtual int64_t getLastBlockTime() = 0;
@@ -250,12 +253,12 @@ public:
//! Register handler for block tip messages.
using NotifyBlockTipFn =
- std::function<void(SynchronizationState, int height, int64_t block_time, double verification_progress)>;
+ std::function<void(SynchronizationState, const uint256& block_hash, int height, int64_t block_time, double verification_progress)>;
virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
//! Register handler for header tip messages.
using NotifyHeaderTipFn =
- std::function<void(SynchronizationState, int height, int64_t block_time, double verification_progress)>;
+ std::function<void(SynchronizationState, const uint256& block_hash, int height, int64_t block_time, double verification_progress)>;
virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
//! Return pointer to internal chain interface, useful for testing.
diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp
index 349dce0247..cec75030ad 100644
--- a/src/interfaces/wallet.cpp
+++ b/src/interfaces/wallet.cpp
@@ -351,13 +351,13 @@ public:
}
return result;
}
- bool tryGetBalances(WalletBalances& balances, int& num_blocks) override
+ bool tryGetBalances(WalletBalances& balances, uint256& block_hash) override
{
TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
if (!locked_wallet) {
return false;
}
- num_blocks = m_wallet->GetLastBlockHeight();
+ block_hash = m_wallet->GetLastBlockHash();
balances = getBalances();
return true;
}
diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h
index 421d35af15..67569a3e55 100644
--- a/src/interfaces/wallet.h
+++ b/src/interfaces/wallet.h
@@ -203,7 +203,7 @@ public:
virtual WalletBalances getBalances() = 0;
//! Get balances if possible without blocking.
- virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;
+ virtual bool tryGetBalances(WalletBalances& balances, uint256& block_hash) = 0;
//! Get balance.
virtual CAmount getBalance() = 0;