 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
33 if (!pindex)
return false;
38 if (nBlockHeight == 0)
39 nBlockHeight = tipHeight;
49 if (BlockLastSolved ==
nullptr || BlockLastSolved->
nHeight == 0 || tipHeight + 1 < nBlockHeight)
return false;
52 if (nBlockHeight > 0) nBlocksAgo = (tipHeight + 1) - nBlockHeight;
53 assert(nBlocksAgo >= 0);
56 for (
unsigned int i = 1; BlockReading && BlockReading->
nHeight > 0; i++) {
57 if (n >= nBlocksAgo) {
64 if (BlockReading->
pprev == NULL) {
68 BlockReading = BlockReading->
pprev;
81 sig = std::vector<unsigned char>();
195 uint256 r = (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3);
222 if (!lockMain)
return;
247 int64_t month = 60 * 60 * 24 * 30;
248 if (sec < month)
return sec;
262 if (pindexPrev == NULL)
return false;
264 std::vector<unsigned char> mnpayee;
273 int64_t nOffset = hash.
GetCompact(
false) % 150;
281 for (
unsigned int i = 1; BlockReading && BlockReading->
nHeight > 0; i++) {
293 return BlockReading->
nTime + nOffset;
297 if (BlockReading->
pprev == NULL) {
298 assert(BlockReading);
301 BlockReading = BlockReading->
pprev;
311 return "PRE_ENABLED";
317 return "OUTPOINT_SPENT";
321 return "WATCHDOG_EXPIRED";
351 std::vector<unsigned char> commitment;
357 if (amount ==
Params().MNCollateralAmt()) {
371 sig = std::vector<unsigned char>();
391 sig = std::vector<unsigned char>();
428 CPubKey pubKeyCollateralAddressNew;
429 CKey keyCollateralAddressNew;
431 CKey keyMasternodeNew;
435 strErrorRet =
"Sync in progress. Must wait until sync is complete to start Masternode";
441 strErrorRet =
strprintf(
"Invalid masternode key %s", strKeyMasternode);
446 std::string strError;
448 strErrorRet = strError;
449 LogPrint(
BCLog::MASTERNODE,
"CMasternodeBroadcast::Create -- %s\n",
strprintf(
"Could not allocate txin %s:%s for masternode %s", strTxHash, strOutputIndex, strService));
457 if (nPort == 0) nPort = nDefaultPort;
461 if(!
CheckDefaultPort(_service, strErrorRet,
"CMasternodeBroadcast::Create"))
464 return Create(txin, _service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
472 LogPrint(
BCLog::MASTERNODE,
"CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n",
477 if (!mnp.
Sign(keyMasternodeNew, pubKeyMasternodeNew)) {
484 mnbRet =
CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION);
494 if (!mnbRet.
Sign(keyCollateralAddressNew)) {
509 if (service.
GetPort() != nDefaultPort) {
510 strErrorRet =
strprintf(
"Invalid port %u for masternode %s, only %d is supported on %s-net.",
512 LogPrintf(
"%s - %s\n", strContext, strErrorRet);
548 if ((pubkeyScript.
size() != 35) && (pubkeyScript.
size() != 67)) {
556 if ((pubkeyScript2.
size() != 35) && (pubkeyScript2.
size() != 67)) {
567 std::string errorMessage =
"";
687 if (
Params().IsRegTestNet()) isLocal =
false;
689 if (!isLocal)
Relay();
702 std::string strError =
"";
712 return error(
"CMasternodeBroadcast::Sign() - Error.");
715 return error(
"CMasternodeBroadcast::Sign() - Error: %s", strError);
722 std::string strError;
725 return error(
"CMasternodeBroadcast::VerifySignature() - Error: %s", strError);
733 std::string strMessage =
HEX_STR(ser);
743 vchSig = std::vector<unsigned char>();
751 vchSig = std::vector<unsigned char>();
757 std::string strError =
"";
758 std::string strMasterNodeSignMessage;
762 std::string strMessage =
HEX_STR(ser);
778 std::string strError =
"";
780 std::string strMessage =
HEX_STR(ser);
784 return error(
"CMasternodePing::VerifySignature - Got bad Masternode ping signature %s Error: %s",
vin.
ToString(), strError);
803 if(fCheckSigTimeOnly) {
814 if (fRequireEnabled && !pmn->
IsEnabled())
return false;
821 std::string strMessage =
HEX_STR(ser);
823 std::string errorMessage =
"";
int64_t GetBlockTime() const
An input of a transaction.
bool EnableHotColdMasterNode(CTxIn &vin, CService &addr)
Enable cold wallet mode (run a Masternode with no funds)
A combination of a network address (CNetAddr) and a (TCP) port.
const uint256 UINT256_ZERO
constant uint256 instances
std::atomic< bool > fImporting
bool Sign(CKey &keyCollateralAddress)
std::vector< unsigned char > encryptionKey
void SplitHostPort(std::string in, int &portOut, std::string &hostOut)
int CountEnabled(int protocolVersion=-1)
int64_t GetTime()
For unit testing.
CActiveMasternode activeMasternode
Keep track of the active Masternode.
int GetMinMasternodePaymentsProto()
static bool CheckDefaultPort(CService service, std::string &strErrorRet, const std::string &strContext)
@ MASTERNODE_WATCHDOG_EXPIRED
static bool Create(CTxIn vin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string &strErrorRet, CMasternodeBroadcast &mnbRet)
Create Masternode broadcast, needs to be relayed manually after that.
CChain chainActive
The currently-connected chain of blocks.
CScript GetScriptForDestination(const CTxDestination &dest)
base58-encoded PRCY addresses.
bool CheckAndUpdate(int &nDos, bool fRequireEnabled=true, bool fCheckSigTimeOnly=false)
CMasternode * Find(const CScript &payee)
Find an entry.
bool IsBlockchainSynced()
CBlockIndex * pprev
pointer to the index of the predecessor of this block
bool Sign(CKey &keyMasternode, CPubKey &pubKeyMasternode)
int nHeight
height of the entry in the chain. The genesis block has height 0
bool CheckAndUpdate(int &nDoS)
bool UpdateFromNewBroadcast(CMasternodeBroadcast &mnb)
void AddedMasternodeList(uint256 hash)
std::string ToStringShort() const
int64_t SecondsSincePayment()
#define TRY_LOCK(cs, name)
@ MSG_MASTERNODE_ANNOUNCE
bool IsRegTestNet() const
static bool VerifyMessage(const CPubKey &pubkey, const std::vector< unsigned char > &vchSig, const std::string &strMessage, std::string &strErrorRet)
Verify the message signature, returns true if succcessful.
std::string ToString() const
uint32_t GetCompact(bool fNegative=false) const
std::string GetHex() const
#define MASTERNODE_EXPIRATION_SECONDS
std::vector< unsigned char > masternodeStealthAddress
The basic transaction that is broadcasted on the network and contained in blocks.
std::string ToStringIP() const
static bool SignMessage(const std::string &strMessage, std::vector< unsigned char > &vchSigRet, const CKey &key)
Sign the message, returns true if successful.
CMasternodeSync masternodeSync
void const uint64_t uint64_t * r
bool GetMasternodeVinAndKeys(CTxIn &txinRet, CPubKey &pubKeyRet, CKey &keyRet, std::string strTxHash, std::string strOutputIndex, std::string &strError)
Get 5000 PRCY output and keys which can be used for the Masternode.
const unsigned char * begin() const
RecursiveMutex cs_main
Global state.
const unsigned char * begin() const
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
CMasternodeMan mnodeman
Masternode manager.
std::string ToString() const
CPubKey pubKeyMasternode1
An output of a transaction.
bool IsReachable(enum Network net)
check whether a given network is one we can probably connect to
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.
std::vector< CTxOut > vout
bool GetBlockHash(uint256 &hash, int nBlockHeight)
const unsigned char * end() const
#define MASTERNODE_CHECK_SECONDS
bool CheckInputsAndAdd(int &nDos)
uint256 CalculateScore(int mod=1, int64_t nBlockHeight=0)
int64_t CAmount
Amount in PRCY (Can be negative)
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
CMasternodePayments masternodePayments
Object for who's going to get paid on which blocks.
#define MASTERNODE_MIN_MNP_SECONDS
std::map< uint256, int > mapSeenMasternodeScanningErrors
int GetInputAge(CTxIn &vin)
std::map< uint256, CMasternodeBroadcast > mapSeenMasternodeBroadcast
256-bit unsigned big integer.
#define HEX_DATA_STREAM_PROTOCOL(protocolVersion)
bool Add(CMasternode &mn)
Add an entry.
static bool CreateCommitment(const CAmount val, CKey &blind, std::vector< unsigned char > &commitment)
unsigned short GetPort() const
std::map< int64_t, uint256 > mapCacheBlockHashes
#define LogPrint(category,...)
#define MASTERNODE_MIN_CONFIRMATIONS
Serialized script, used inside transaction inputs and outputs.
uint256 GetBlockHash() const
#define MASTERNODE_REMOVAL_SECONDS
std::map< int, CMasternodeBlockPayees > mapMasternodeBlocks
int Height() const
Return the maximal height in the chain.
static bool GetKeysFromSecret(const std::string &strSecret, CKey &keyRet, CPubKey &pubkeyRet)
Set the private/public key values, returns true if successful.
int GetDefaultPort() const
std::vector< unsigned char > sig
An encapsulated public key.
int64_t GetAdjustedTime()
int nLastScanningErrorBlockHeight
An encapsulated private key.
@ MASTERNODE_OUTPOINT_SPENT
std::string ToString() const
std::atomic< bool > fReindex
std::map< uint256, CMasternodePing > mapSeenMasternodePing
std::string ToString() const
std::map< uint256, int > mapSeenSyncMNB
A writer stream (for serialization) that computes a 256-bit hash.
CService LookupNumeric(const char *pszName, int portDefault)
const CChainParams & Params()
Return the currently selected parameters.
bool IsPingedWithin(int seconds, int64_t now=-1)
bool VerifyShnorrKeyImageTxIn(const CTxIn &txin, uint256 ctsHash)
std::vector< unsigned char > commitment
bool IsBroadcastedWithin(int seconds)
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
std::vector< unsigned char > vchSig
uint256 GetTxInSignatureHash(const CTxIn &txin)
The block chain is a tree shaped structure starting with the genesis block at the root,...
std::string GetStrMessage()
#define MASTERNODE_MIN_MNB_SECONDS
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
void Check(bool forceCheck=false)
bool VerifySignature(CPubKey &pubKeyMasternode, int &nDos)
CPubKey pubKeyCollateralAddress
bool IsSpentKeyImage(const std::string &kiHex, const uint256 &againsHash)
bool error(const char *fmt, const Args &... args)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
bool IsInputAssociatedWithPubkey(CTxIn &vin, CPubKey &pubkey) const
Is the input associated with collateral public key? (and there is 5000 PRCY - checking if valid maste...
static void Decode(unsigned char *encodedMask, unsigned char *encodedAmount, const CPubKey &sharedSec, CKey &decodedMask, CAmount &decodedAmount)
std::string ToString() const