Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/.formatted-files
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ chain/chain.cpp
chain/chain.h
chain/chainman.cpp
chain/chainman.h
chain/chainparams.cpp
chain/chainparams.h
chain/checkpoints.cpp
chain/checkpoints.h
chain/outpoint.h
Expand Down Expand Up @@ -114,10 +116,6 @@ net/tagdb.cpp
net/tagdb.h
net/tagstore.cpp
net/tagstore.h
networks/netman.cpp
networks/netman.h
networks/network.h
networks/networktemplate.h
policy/fees.cpp
policy/fees.h
policy/policy.cpp
Expand Down
6 changes: 2 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ BITCOIN_CORE_H = \
net/routingtag.h \
net/tagdb.h \
net/tagstore.h \
networks/netman.h \
networks/network.h \
networks/networktemplate.h \
chain/chainparams.h \
policy/fees.h \
policy/policy.h \
pow.h \
Expand Down Expand Up @@ -203,6 +201,7 @@ libbitcoin_server_a_SOURCES = \
chain/blockindex.cpp \
chain/chain.cpp \
chain/chainman.cpp \
chain/chainparams.cpp \
chain/checkpoints.cpp \
chain/tx.cpp \
clientversion.cpp \
Expand Down Expand Up @@ -260,7 +259,6 @@ libbitcoin_server_a_SOURCES = \
net/packetmanager.cpp \
net/protocol.cpp \
net/routingtag.cpp \
networks/netman.cpp \
policy/fees.cpp \
policy/policy.cpp \
pow.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "args.h"
#include "util/util.h"

#include "networks/netman.h"
#include "chain/chainparams.h"
#include "random.h"
#include "serialize.h"
#include "util/utilstrencodings.h"
Expand Down
24 changes: 12 additions & 12 deletions src/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ class CBitcoinAddressVisitor : public boost::static_visitor<bool>

bool CBitcoinAddress::Set(const CKeyID &id)
{
SetData(pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::PUBKEY_ADDRESS), &id, 20);
SetData(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS), &id, 20);
return true;
}

bool CBitcoinAddress::Set(const CScriptID &id)
{
SetData(pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::SCRIPT_ADDRESS), &id, 20);
SetData(Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS), &id, 20);
return true;
}

Expand All @@ -239,12 +239,12 @@ bool CBitcoinAddress::Set(const CTxDestination &dest)
return boost::apply_visitor(CBitcoinAddressVisitor(this), dest);
}

bool CBitcoinAddress::IsValid() const { return IsValid(pnetMan->getActivePaymentNetwork()); }
bool CBitcoinAddress::IsValid(const CNetworkTemplate &params) const
bool CBitcoinAddress::IsValid() const { return IsValid(Params()); }
bool CBitcoinAddress::IsValid(const CChainParams &params) const
{
bool fCorrectSize = vchData.size() == 20;
bool fKnownVersion = vchVersion == params.Base58Prefix(CNetworkTemplate::PUBKEY_ADDRESS) ||
vchVersion == params.Base58Prefix(CNetworkTemplate::SCRIPT_ADDRESS);
bool fKnownVersion = vchVersion == params.Base58Prefix(CChainParams::PUBKEY_ADDRESS) ||
vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS);
return fCorrectSize && fKnownVersion;
}

Expand All @@ -254,17 +254,17 @@ CTxDestination CBitcoinAddress::Get() const
return CNoDestination();
uint160 id;
memcpy(&id, &vchData[0], 20);
if (vchVersion == pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::PUBKEY_ADDRESS))
if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
return CKeyID(id);
else if (vchVersion == pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::SCRIPT_ADDRESS))
else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS))
return CScriptID(id);
else
return CNoDestination();
}

bool CBitcoinAddress::GetKeyID(CKeyID &keyID) const
{
if (!IsValid() || vchVersion != pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::PUBKEY_ADDRESS))
if (!IsValid() || vchVersion != Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
return false;
uint160 id;
memcpy(&id, &vchData[0], 20);
Expand All @@ -275,13 +275,13 @@ bool CBitcoinAddress::GetKeyID(CKeyID &keyID) const
bool CBitcoinAddress::IsScript() const
{
return IsValid() &&
vchVersion == pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::SCRIPT_ADDRESS);
vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS);
}

void CBitcoinSecret::SetKey(const CKey &vchSecret)
{
assert(vchSecret.IsValid());
SetData(pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::SECRET_KEY), vchSecret.begin(),
SetData(Params().Base58Prefix(CChainParams::SECRET_KEY), vchSecret.begin(),
vchSecret.size());
if (vchSecret.IsCompressed())
vchData.push_back(1);
Expand All @@ -298,7 +298,7 @@ CKey CBitcoinSecret::GetKey()
bool CBitcoinSecret::IsValid() const
{
bool fExpectedFormat = vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1);
bool fCorrectVersion = vchVersion == pnetMan->getActivePaymentNetwork()->Base58Prefix(CNetworkTemplate::SECRET_KEY);
bool fCorrectVersion = vchVersion == Params().Base58Prefix(CChainParams::SECRET_KEY);
return fExpectedFormat && fCorrectVersion;
}

Expand Down
17 changes: 8 additions & 9 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
#define BITCOIN_BASE58_H

#include "key.h"
#include "networks/netman.h"
#include "networks/networktemplate.h"
#include "chain/chainparams.h"
#include "pubkey.h"
#include "script/script.h"
#include "script/standard.h"
Expand All @@ -27,7 +26,7 @@
#include <string>
#include <vector>

extern CNetworkManager *pnetMan;


/**
* Encode a byte sequence as a base58-encoded string.
Expand Down Expand Up @@ -115,7 +114,7 @@ class CBitcoinAddress : public CBase58Data
bool Set(const CScriptID &id);
bool Set(const CTxDestination &dest);
bool IsValid() const;
bool IsValid(const CNetworkTemplate &params) const;
bool IsValid(const CChainParams &params) const;

CBitcoinAddress() {}
CBitcoinAddress(const CTxDestination &dest) { Set(dest); }
Expand All @@ -142,15 +141,15 @@ class CBitcoinSecret : public CBase58Data
CBitcoinSecret() {}
};

template <typename K, int Size, CNetworkTemplate::Base58Type Type>
template <typename K, int Size, CChainParams::Base58Type Type>
class CBitcoinExtKeyBase : public CBase58Data
{
public:
void SetKey(const K &key)
{
unsigned char vch[Size];
key.Encode(vch);
SetData(pnetMan->getActivePaymentNetwork()->Base58Prefix(Type), vch, vch + Size);
SetData(Params().Base58Prefix(Type), vch, vch + Size);
}

K GetKey()
Expand All @@ -167,13 +166,13 @@ class CBitcoinExtKeyBase : public CBase58Data
CBitcoinExtKeyBase(const K &key) { SetKey(key); }
CBitcoinExtKeyBase(const std::string &strBase58c)
{
SetString(strBase58c.c_str(), pnetMan->getActivePaymentNetwork()->Base58Prefix(Type).size());
SetString(strBase58c.c_str(), Params().Base58Prefix(Type).size());
}

CBitcoinExtKeyBase() {}
};

typedef CBitcoinExtKeyBase<CExtKey, 74, CNetworkTemplate::EXT_SECRET_KEY> CBitcoinExtKey;
typedef CBitcoinExtKeyBase<CExtPubKey, 74, CNetworkTemplate::EXT_PUBLIC_KEY> CBitcoinExtPubKey;
typedef CBitcoinExtKeyBase<CExtKey, 74, CChainParams::EXT_SECRET_KEY> CBitcoinExtKey;
typedef CBitcoinExtKeyBase<CExtPubKey, 74, CChainParams::EXT_PUBLIC_KEY> CBitcoinExtPubKey;

#endif // BITCOIN_BASE58_H
21 changes: 10 additions & 11 deletions src/blockgeneration/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "init.h"
#include "kernel.h"
#include "net/net.h"
#include "networks/netman.h"
#include "networks/networktemplate.h"
#include "chain/chainparams.h"
#include "policy/policy.h"
#include "processblock.h"
#include "timedata.h"
Expand Down Expand Up @@ -130,7 +129,7 @@ std::unique_ptr<CBlockTemplate> CreateNewPoWBlock(CWallet *pwallet, const CScrip
// ppcoin: if coinstake available add coinstake tx
// Commented out unused variable assuming no side effect within GetAdjustedTime()
// static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // only initialized at startup
CBlockIndex *pindexPrev = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *pindexPrev = g_chainman.chainActive.Tip();


// This vector will be sorted into a priority queue:
Expand All @@ -151,7 +150,7 @@ std::unique_ptr<CBlockTemplate> CreateNewPoWBlock(CWallet *pwallet, const CScrip
{
LOCK(cs_main);
READLOCK(mempool.cs);
CBlockIndex *_pindexPrev = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *_pindexPrev = g_chainman.chainActive.Tip();
const int nHeight = _pindexPrev->nHeight + 1;
pblock->nTime = GetAdjustedTime();
const int64_t nMedianTimePast = _pindexPrev->GetMedianTimePast();
Expand Down Expand Up @@ -305,7 +304,7 @@ std::unique_ptr<CBlockTemplate> CreateNewPoWBlock(CWallet *pwallet, const CScrip
pblock->hashPrevBlock = _pindexPrev->GetBlockHash();
pblock->nTime = std::max(_pindexPrev->GetMedianTimePast() + 1, pblock->GetMaxTransactionTime());
pblock->nTime = std::max(pblock->GetBlockTime(), _pindexPrev->GetBlockTime() - nMaxClockDrift);
UpdateTime(pblock, pnetMan->getActivePaymentNetwork()->GetConsensus(), _pindexPrev);
UpdateTime(pblock, Params().GetConsensus(), _pindexPrev);
pblock->vtx[0]->vout[0].nValue =
GetProofOfWorkReward(nFees, _pindexPrev->nHeight + 1, _pindexPrev->GetBlockHash());
pblock->nNonce = 0;
Expand Down Expand Up @@ -373,7 +372,7 @@ bool CheckWork(const CBlock *pblock, CWallet &wallet, boost::shared_ptr<CReserve

// Found a solution
{
CBlockIndex *ptip = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *ptip = g_chainman.chainActive.Tip();
if (ptip == nullptr)
{
return false;
Expand All @@ -394,7 +393,7 @@ bool CheckWork(const CBlock *pblock, CWallet &wallet, boost::shared_ptr<CReserve

// Process this block the same as if we had received it from another node
CValidationState state;
const CNetworkTemplate &chainparams = pnetMan->getActivePaymentNetwork();
const CChainParams &chainparams = Params();
if (!ProcessNewBlock(state, chainparams, NULL, pblock, true, NULL))
return error("Miner : ProcessBlock, block not accepted");
}
Expand Down Expand Up @@ -433,7 +432,7 @@ void EccMiner(CWallet *pwallet)
if (shutdown_threads.load() || shutdown_miner_threads.load())
return;
}
while (pnetMan->getChainActive()->IsInitialBlockDownload() || pwallet->IsLocked())
while (g_chainman.IsInitialBlockDownload() || pwallet->IsLocked())
{
MilliSleep(1000);
if (shutdown_threads.load() || shutdown_miner_threads.load())
Expand All @@ -449,7 +448,7 @@ void EccMiner(CWallet *pwallet)
// Create new block
//
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex *pindexPrev = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *pindexPrev = g_chainman.chainActive.Tip();
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewPoWBlock(pwallet, coinbaseScript->reserveScript));
if (!pblocktemplate.get())
{
Expand Down Expand Up @@ -538,12 +537,12 @@ void EccMiner(CWallet *pwallet)
break;
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
break;
if (pindexPrev != pnetMan->getChainActive()->chainActive.Tip())
if (pindexPrev != g_chainman.chainActive.Tip())
break;
// Update nTime every few seconds
pblock->nTime = std::max(pindexPrev->GetMedianTimePast() + 1, pblock->GetMaxTransactionTime());
pblock->nTime = std::max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift);
UpdateTime(pblock, pnetMan->getActivePaymentNetwork()->GetConsensus(), pindexPrev);
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
nBlockTime = ByteReverse(pblock->nTime);
if (pblock->GetBlockTime() >= (int64_t)pblock->vtx[0]->nTime + nMaxClockDrift)
break; // need to update coinbase timestamp
Expand Down
12 changes: 6 additions & 6 deletions src/blockgeneration/minter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bool CheckStake(const CBlock *pblock, CWallet &wallet, boost::shared_ptr<CReserv

// Found a solution
{
CBlockIndex *ptip = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *ptip = g_chainman.chainActive.Tip();
if (ptip == nullptr)
{
return false;
Expand All @@ -54,7 +54,7 @@ bool CheckStake(const CBlock *pblock, CWallet &wallet, boost::shared_ptr<CReserv
}
// Process this block the same as if we had received it from another node
CValidationState state;
const CNetworkTemplate &chainparams = pnetMan->getActivePaymentNetwork();
const CChainParams &chainparams = Params();
if (!ProcessNewBlock(state, chainparams, nullptr, pblock, true, nullptr))
{
return error("Minter : ProcessBlock, block not accepted");
Expand Down Expand Up @@ -97,7 +97,7 @@ std::unique_ptr<CBlockTemplate> CreateNewPoSBlock(CWallet *pwallet, const CScrip

// ppcoin: if coinstake available add coinstake tx
static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // only initialized at startup
CBlockIndex *pindexPrev = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *pindexPrev = g_chainman.chainActive.Tip();


// This vector will be sorted into a priority queue:
Expand Down Expand Up @@ -146,7 +146,7 @@ std::unique_ptr<CBlockTemplate> CreateNewPoSBlock(CWallet *pwallet, const CScrip
{
LOCK(cs_main);
READLOCK(mempool.cs);
CBlockIndex *_pindexPrev = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *_pindexPrev = g_chainman.chainActive.Tip();
const int nHeight = _pindexPrev->nHeight + 1;
pblock->nTime = GetAdjustedTime();
const int64_t nMedianTimePast = _pindexPrev->GetMedianTimePast();
Expand Down Expand Up @@ -340,7 +340,7 @@ void EccMinter(CWallet *pwallet)
if (shutdown_threads.load() || shutdown_minter_threads.load())
return;
}
while (pnetMan->getChainActive()->IsInitialBlockDownload() || pwallet->IsLocked())
while (g_chainman.IsInitialBlockDownload() || pwallet->IsLocked())
{
MilliSleep(1000);
if (shutdown_threads.load() || shutdown_minter_threads.load())
Expand All @@ -352,7 +352,7 @@ void EccMinter(CWallet *pwallet)
if (shutdown_threads.load() || shutdown_minter_threads.load())
return;
}
CBlockIndex *pindexPrev = pnetMan->getChainActive()->chainActive.Tip();
CBlockIndex *pindexPrev = g_chainman.chainActive.Tip();
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewPoSBlock(pwallet, coinbaseScript->reserveScript));
if (!pblocktemplate.get())
{
Expand Down
5 changes: 2 additions & 3 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include "crypto/scrypt.h"
#include "init.h"
#include "main.h"
#include "networks/netman.h"
#include "networks/networktemplate.h"
#include "chain/chainparams.h"
#include "timedata.h"
#include "tinyformat.h"
#include "util/util.h"
Expand Down Expand Up @@ -122,7 +121,7 @@ bool CBlock::SignScryptBlock(const CKeyStore &keystore)

bool CBlock::CheckBlockSignature() const
{
if (GetHash() == pnetMan->getActivePaymentNetwork()->GetConsensus().hashGenesisBlock)
if (GetHash() == Params().GetConsensus().hashGenesisBlock)
return vchBlockSig.empty();

std::vector<std::vector<unsigned char> > vSolutions;
Expand Down
Loading