forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpop_common.cpp
62 lines (48 loc) · 1.9 KB
/
pop_common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2019-2021 Xenios SEZC
// https://www.veriblock.org
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "pop_common.hpp"
#include <chain.h>
#include <utility>
namespace VeriBlock {
static std::shared_ptr<altintegration::PopContext> app = nullptr;
static std::shared_ptr<altintegration::Config> config = nullptr;
altintegration::PopContext& GetPop()
{
assert(app && "Altintegration is not initialized. Invoke InitPopContext.");
return *app;
}
void StopPop()
{
if (app) {
app->shutdown();
}
}
void SetPopConfig(const altintegration::Config& newConfig)
{
config = std::make_shared<altintegration::Config>(newConfig);
}
void SetPop(std::shared_ptr<altintegration::PayloadsStorage> payloads_provider, std::shared_ptr<altintegration::BlockReader> block_provider, std::unique_ptr<altintegration::EthashCache> ethash_cache, std::unique_ptr<altintegration::ProgpowHeaderCache> progpow_header_cache)
{
assert(config && "Config is not initialized. Invoke SetPopConfig.");
app = altintegration::PopContext::create(config, payloads_provider, block_provider, std::move(ethash_cache), std::move(progpow_header_cache));
}
std::string toPrettyString(const altintegration::PopContext& pop)
{
return pop.getAltBlockTree().toPrettyString();
}
altintegration::BlockIndex<altintegration::AltBlock>* GetAltBlockIndex(const uint256& hash)
{
return GetPop().getAltBlockTree().getBlockIndex(hash.asVector());
}
altintegration::BlockIndex<altintegration::AltBlock>* GetAltBlockIndex(const CBlockIndex* index)
{
return index == nullptr ? nullptr : GetAltBlockIndex(index->GetBlockHash());
}
bool isKeystone(const CBlockIndex& block)
{
auto keystoneInterval = GetPop().getConfig().getAltParams().getKeystoneInterval();
return (block.nHeight % keystoneInterval) == 0;
}
} // namespace VeriBlock