mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Add time methods to the Chain interface
And use them to remove uses of chainActive and mapBlockIndex in wallet code This commit does not change behavior. Co-authored-by: Ben Woosley <ben.woosley@gmail.com>
This commit is contained in:
@@ -46,6 +46,18 @@ class LockImpl : public Chain::Lock
|
||||
assert(block != nullptr);
|
||||
return block->GetBlockHash();
|
||||
}
|
||||
int64_t getBlockTime(int height) override
|
||||
{
|
||||
CBlockIndex* block = ::chainActive[height];
|
||||
assert(block != nullptr);
|
||||
return block->GetBlockTime();
|
||||
}
|
||||
int64_t getBlockMedianTimePast(int height) override
|
||||
{
|
||||
CBlockIndex* block = ::chainActive[height];
|
||||
assert(block != nullptr);
|
||||
return block->GetMedianTimePast();
|
||||
}
|
||||
};
|
||||
|
||||
class LockingStateImpl : public LockImpl, public UniqueLock<CCriticalSection>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <optional.h>
|
||||
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -48,6 +49,13 @@ public:
|
||||
|
||||
//! Get block hash. Height must be valid or this function will abort.
|
||||
virtual uint256 getBlockHash(int height) = 0;
|
||||
|
||||
//! Get block time. Height must be valid or this function will abort.
|
||||
virtual int64_t getBlockTime(int height) = 0;
|
||||
|
||||
//! Get block median time past. Height must be valid or this function
|
||||
//! will abort.
|
||||
virtual int64_t getBlockMedianTimePast(int height) = 0;
|
||||
};
|
||||
|
||||
//! Return Lock interface. Chain is locked when this is called, and
|
||||
|
||||
@@ -333,8 +333,13 @@ public:
|
||||
if (mi == m_wallet.mapWallet.end()) {
|
||||
return false;
|
||||
}
|
||||
num_blocks = locked_chain->getHeight().value_or(-1);
|
||||
block_time = ::chainActive.Tip()->GetBlockTime();
|
||||
if (Optional<int> height = locked_chain->getHeight()) {
|
||||
num_blocks = *height;
|
||||
block_time = locked_chain->getBlockTime(*height);
|
||||
} else {
|
||||
num_blocks = -1;
|
||||
block_time = -1;
|
||||
}
|
||||
tx_status = MakeWalletTxStatus(*locked_chain, mi->second);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user