From fa3be799fe951a7ea9b4de78d5a907c6db71eeb8 Mon Sep 17 00:00:00 2001 From: MacroFake Date: Fri, 5 Aug 2022 14:45:30 +0200 Subject: [PATCH] Add time helpers To be used in the next commit --- src/chain.h | 6 ++++++ src/consensus/params.h | 5 +++++ src/primitives/block.h | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/chain.h b/src/chain.h index 1c5cd3f1f6..cc1d9e2d22 100644 --- a/src/chain.h +++ b/src/chain.h @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -275,6 +276,11 @@ public: */ bool HaveTxsDownloaded() const { return nChainTx != 0; } + NodeSeconds Time() const + { + return NodeSeconds{std::chrono::seconds{nTime}}; + } + int64_t GetBlockTime() const { return (int64_t)nTime; diff --git a/src/consensus/params.h b/src/consensus/params.h index 794e0f5383..7c35222713 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -8,6 +8,7 @@ #include +#include #include #include @@ -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; diff --git a/src/primitives/block.h b/src/primitives/block.h index 2d10853607..76aba6c899 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -9,6 +9,7 @@ #include #include #include +#include /** 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 @@ -52,6 +53,11 @@ public: uint256 GetHash() const; + NodeSeconds Time() const + { + return NodeSeconds{std::chrono::seconds{nTime}}; + } + int64_t GetBlockTime() const { return (int64_t)nTime;