Skip to content

Commit

Permalink
refactor: Move SignBlock() to <node/miner.cpp>
Browse files Browse the repository at this point in the history
  • Loading branch information
lateminer committed Jan 23, 2024
1 parent 5facf3c commit 3a984bb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
34 changes: 34 additions & 0 deletions src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,40 @@ bool CanStake() {
return canStake;
}

// peercoin: sign block
typedef std::vector<unsigned char> valtype;
bool SignBlock(CBlock& block, const CWallet& keystore)
{
std::vector<valtype> vSolutions;
const CTxOut& txout = block.IsProofOfStake() ? block.vtx[1]->vout[1] : block.vtx[0]->vout[0];

if (Solver(txout.scriptPubKey, vSolutions) != TxoutType::PUBKEY)
return false;

// Sign
if (keystore.IsLegacy())
{
const valtype& vchPubKey = vSolutions[0];
CKey key;
if (!keystore.GetLegacyScriptPubKeyMan()->GetKey(CKeyID(Hash160(vchPubKey)), key))
return false;
if (key.GetPubKey() != CPubKey(vchPubKey))
return false;
return key.Sign(block.GetHash(), block.vchBlockSig, 0);
}
else
{
CTxDestination address;
CPubKey pubKey(vSolutions[0]);
address = PKHash(pubKey);
PKHash* pkhash = std::get_if<PKHash>(&address);
SigningResult res = keystore.SignBlockHash(block.GetHash(), *pkhash, block.vchBlockSig);
if (res == SigningResult::OK)
return true;
return false;
}
}

// peercoin
void PoSMiner(wallet::CWallet *pwallet)
{
Expand Down
37 changes: 0 additions & 37 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3510,43 +3510,6 @@ void Chainstate::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pin
}
}

#ifdef ENABLE_WALLET
// Blackcoin
// peercoin: sign block
typedef std::vector<unsigned char> valtype;
bool SignBlock(CBlock& block, const CWallet& keystore)
{
std::vector<valtype> vSolutions;
const CTxOut& txout = block.IsProofOfStake() ? block.vtx[1]->vout[1] : block.vtx[0]->vout[0];

if (Solver(txout.scriptPubKey, vSolutions) != TxoutType::PUBKEY)
return false;

// Sign
if (keystore.IsLegacy())
{
const valtype& vchPubKey = vSolutions[0];
CKey key;
if (!keystore.GetLegacyScriptPubKeyMan()->GetKey(CKeyID(Hash160(vchPubKey)), key))
return false;
if (key.GetPubKey() != CPubKey(vchPubKey))
return false;
return key.Sign(block.GetHash(), block.vchBlockSig, 0);
}
else
{
CTxDestination address;
CPubKey pubKey(vSolutions[0]);
address = PKHash(pubKey);
PKHash* pkhash = std::get_if<PKHash>(&address);
SigningResult res = keystore.SignBlockHash(block.GetHash(), *pkhash, block.vchBlockSig);
if (res == SigningResult::OK)
return true;
return false;
}
}
#endif

static bool CheckBlockSignature(const CBlock& block)
{
if (block.IsProofOfWork())
Expand Down
3 changes: 0 additions & 3 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@ class CScriptCheck

/** Functions for validating blocks and updating the block tree */

/** Sign proof-of-stake block */
bool SignBlock(CBlock& block, const CWallet& keystore);

/** Context-independent validity checks */
bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, Chainstate& chainstate, bool fCheckPOW = true, bool fCheckMerkleRoot = true, bool fCheckSig = true);
bool CheckCanonicalBlockSignature(const std::shared_ptr<const CBlock>& pblock);
Expand Down

0 comments on commit 3a984bb

Please sign in to comment.