Skip to content

Commit

Permalink
Add time helpers
Browse files Browse the repository at this point in the history
To be used in the next commit
  • Loading branch information
MacroFake committed Aug 5, 2022
1 parent 7d82f86 commit fa3be79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <primitives/block.h>
#include <sync.h>
#include <uint256.h>
#include <util/time.h>

#include <vector>

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

NodeSeconds Time() const
{
return NodeSeconds{std::chrono::seconds{nTime}};
}

int64_t GetBlockTime() const
{
return (int64_t)nTime;
Expand Down
5 changes: 5 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <uint256.h>

#include <chrono>
#include <limits>
#include <map>

Expand Down Expand Up @@ -109,6 +110,10 @@ struct Params {
bool fPowNoRetargeting;
int64_t nPowTargetSpacing;
int64_t nPowTargetTimespan;
std::chrono::seconds PowTargetSpacing() const
{
return std::chrono::seconds{nPowTargetSpacing};
}
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
/** The best chain should have at least this much work */
uint256 nMinimumChainWork;
Expand Down
6 changes: 6 additions & 0 deletions src/primitives/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <primitives/transaction.h>
#include <serialize.h>
#include <uint256.h>
#include <util/time.h>

/** 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
Expand Down Expand Up @@ -52,6 +53,11 @@ class CBlockHeader

uint256 GetHash() const;

NodeSeconds Time() const
{
return NodeSeconds{std::chrono::seconds{nTime}};
}

int64_t GetBlockTime() const
{
return (int64_t)nTime;
Expand Down

0 comments on commit fa3be79

Please sign in to comment.