2014-03-10 08:46:53 -07:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
|
|
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
|
|
#include "pow.h"
|
|
|
|
|
|
2014-10-22 01:31:01 +02:00
|
|
|
#include "chain.h"
|
2014-03-10 08:46:53 -07:00
|
|
|
#include "chainparams.h"
|
2014-10-29 23:07:30 +01:00
|
|
|
#include "hash.h"
|
2014-10-30 00:15:01 +01:00
|
|
|
#include "keystore.h"
|
2014-11-18 21:03:02 +00:00
|
|
|
#include "primitives/block.h"
|
2014-10-30 00:15:01 +01:00
|
|
|
#include "script/generic.hpp"
|
|
|
|
|
#include "script/standard.h"
|
2014-03-10 08:46:53 -07:00
|
|
|
#include "uint256.h"
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 16:11:09 +02:00
|
|
|
#include "util.h"
|
2014-10-30 00:15:01 +01:00
|
|
|
#include "wallet.h"
|
2014-03-10 08:46:53 -07:00
|
|
|
|
2014-10-30 00:15:01 +01:00
|
|
|
extern CWallet* pwalletMain;
|
2014-03-10 08:46:53 -07:00
|
|
|
|
2014-10-30 00:15:01 +01:00
|
|
|
CScript CombineBlockSignatures(const CBlockHeader& header, const CScript& scriptSig1, const CScript& scriptSig2)
|
|
|
|
|
{
|
|
|
|
|
return GenericCombineSignatures(header.proof.challenge, header, scriptSig1, scriptSig2);
|
2014-03-10 08:46:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-10-29 23:07:30 +01:00
|
|
|
bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast)
|
|
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
return block.proof.challenge == indexLast.proof.challenge;
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast)
|
|
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
block.proof.challenge = indexLast.proof.challenge;
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-08 14:45:37 +01:00
|
|
|
|
|
|
|
|
bool CheckBitcoinProof(const CBlockHeader& block)
|
|
|
|
|
{
|
|
|
|
|
bool fNegative;
|
|
|
|
|
bool fOverflow;
|
|
|
|
|
uint256 bnTarget;
|
|
|
|
|
|
|
|
|
|
bnTarget.SetCompact(block.bitcoinproof.challenge, &fNegative, &fOverflow);
|
|
|
|
|
|
|
|
|
|
// Check range
|
|
|
|
|
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > Params().ProofOfWorkLimit())
|
|
|
|
|
return error("%s : nBits below minimum work", __func__);
|
|
|
|
|
|
|
|
|
|
// Check proof of work matches claimed amount
|
|
|
|
|
if (block.GetHash() > bnTarget)
|
|
|
|
|
return error("%s : hash doesn't match nBits", __func__);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 23:07:30 +01:00
|
|
|
bool CheckProof(const CBlockHeader& block)
|
2014-03-10 08:46:53 -07:00
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
if (block.GetHash() == Params().HashGenesisBlock())
|
2014-09-04 16:23:42 -03:00
|
|
|
return true;
|
2014-10-30 00:15:01 +01:00
|
|
|
return GenericVerifyScript(block.proof.solution, block.proof.challenge, SCRIPT_VERIFY_P2SH, block);
|
2014-03-10 08:46:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-10-30 00:15:01 +01:00
|
|
|
bool GenerateProof(CBlockHeader *pblock, CWallet *pwallet)
|
2014-10-29 23:07:30 +01:00
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
return GenericSignScript(*pwallet, *pblock, pblock->proof.challenge, pblock->proof.solution);
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ResetProof(CBlockHeader& block)
|
|
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
block.proof.solution.clear();
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-29 17:00:02 +01:00
|
|
|
uint256 GetBlockProof(const CBlockIndex& block)
|
2014-07-05 12:05:33 +02:00
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
return 1;
|
2014-03-10 08:46:53 -07:00
|
|
|
}
|
2014-10-29 23:07:30 +01:00
|
|
|
|
|
|
|
|
double GetChallengeDifficulty(const CBlockIndex* blockindex)
|
|
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
return 1;
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetChallengeStr(const CBlockIndex& block)
|
|
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
return block.proof.challenge.ToString();
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string GetChallengeStrHex(const CBlockIndex& block)
|
|
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
return block.proof.challenge.ToString();
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t GetNonce(const CBlockHeader& block)
|
|
|
|
|
{
|
2014-10-30 00:15:01 +01:00
|
|
|
return 1;
|
2014-10-29 23:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetNonce(CBlockHeader& block, uint32_t nNonce)
|
|
|
|
|
{
|
|
|
|
|
}
|