Skip to content

Commit fa3be79

Browse files
author
MacroFake
committed
Add time helpers
To be used in the next commit
1 parent 7d82f86 commit fa3be79

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/chain.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <primitives/block.h>
1313
#include <sync.h>
1414
#include <uint256.h>
15+
#include <util/time.h>
1516

1617
#include <vector>
1718

@@ -275,6 +276,11 @@ class CBlockIndex
275276
*/
276277
bool HaveTxsDownloaded() const { return nChainTx != 0; }
277278

279+
NodeSeconds Time() const
280+
{
281+
return NodeSeconds{std::chrono::seconds{nTime}};
282+
}
283+
278284
int64_t GetBlockTime() const
279285
{
280286
return (int64_t)nTime;

src/consensus/params.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <uint256.h>
1010

11+
#include <chrono>
1112
#include <limits>
1213
#include <map>
1314

@@ -109,6 +110,10 @@ struct Params {
109110
bool fPowNoRetargeting;
110111
int64_t nPowTargetSpacing;
111112
int64_t nPowTargetTimespan;
113+
std::chrono::seconds PowTargetSpacing() const
114+
{
115+
return std::chrono::seconds{nPowTargetSpacing};
116+
}
112117
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
113118
/** The best chain should have at least this much work */
114119
uint256 nMinimumChainWork;

src/primitives/block.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <primitives/transaction.h>
1010
#include <serialize.h>
1111
#include <uint256.h>
12+
#include <util/time.h>
1213

1314
/** Nodes collect new transactions into a block, hash them into a hash tree,
1415
* and scan through nonce values to make the block's hash satisfy proof-of-work
@@ -52,6 +53,11 @@ class CBlockHeader
5253

5354
uint256 GetHash() const;
5455

56+
NodeSeconds Time() const
57+
{
58+
return NodeSeconds{std::chrono::seconds{nTime}};
59+
}
60+
5561
int64_t GetBlockTime() const
5662
{
5763
return (int64_t)nTime;

0 commit comments

Comments
 (0)