Add time helpers
To be used in the next commit
This commit is contained in:
3 files changed
+17
No files matched your search
@@ -12,6 +12,7 @@
|
|||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
#include <util/time.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -275,6 +276,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool HaveTxsDownloaded() const { return nChainTx != 0; }
|
bool HaveTxsDownloaded() const { return nChainTx != 0; }
|
||||||
|
|
||||||
|
NodeSeconds Time() const
|
||||||
|
{
|
||||||
|
return NodeSeconds{std::chrono::seconds{nTime}};
|
||||||
|
}
|
||||||
|
|
||||||
int64_t GetBlockTime() const
|
int64_t GetBlockTime() const
|
||||||
{
|
{
|
||||||
return (int64_t)nTime;
|
return (int64_t)nTime;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@@ -109,6 +110,10 @@ struct Params {
|
|||||||
bool fPowNoRetargeting;
|
bool fPowNoRetargeting;
|
||||||
int64_t nPowTargetSpacing;
|
int64_t nPowTargetSpacing;
|
||||||
int64_t nPowTargetTimespan;
|
int64_t nPowTargetTimespan;
|
||||||
|
std::chrono::seconds PowTargetSpacing() const
|
||||||
|
{
|
||||||
|
return std::chrono::seconds{nPowTargetSpacing};
|
||||||
|
}
|
||||||
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
|
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
|
||||||
/** The best chain should have at least this much work */
|
/** The best chain should have at least this much work */
|
||||||
uint256 nMinimumChainWork;
|
uint256 nMinimumChainWork;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
#include <util/time.h>
|
||||||
|
|
||||||
/** Nodes collect new transactions into a block, hash them into a hash tree,
|
/** Nodes collect new transactions into a block, hash them into a hash tree,
|
||||||
* and scan through nonce values to make the block's hash satisfy proof-of-work
|
* and scan through nonce values to make the block's hash satisfy proof-of-work
|
||||||
@@ -52,6 +53,11 @@ public:
|
|||||||
|
|
||||||
uint256 GetHash() const;
|
uint256 GetHash() const;
|
||||||
|
|
||||||
|
NodeSeconds Time() const
|
||||||
|
{
|
||||||
|
return NodeSeconds{std::chrono::seconds{nTime}};
|
||||||
|
}
|
||||||
|
|
||||||
int64_t GetBlockTime() const
|
int64_t GetBlockTime() const
|
||||||
{
|
{
|
||||||
return (int64_t)nTime;
|
return (int64_t)nTime;
|
||||||
|
|||||||
Reference in new issue
Block a user