Example #1
0
uint256 CreateBlockWithAppointedAddr(CKeyID const &keyID)
{
	if (SysCfg().NetworkID() == CBaseParams::REGTEST)
	{
//		unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
		mempool.GetTransactionsUpdated();
		CBlockIndex* pindexPrev = chainActive.Tip();

		CAccountViewCache accview(*pAccountViewTip, true);
		CTransactionDBCache txCache(*pTxCacheTip, true);
		CScriptDBViewCache ScriptDbTemp(*pScriptDBTip, true);
		shared_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(accview,txCache,ScriptDbTemp));
		if (!pblocktemplate.get())
			return uint256();
		CBlock *pblock = &pblocktemplate.get()->block;

//		int nBlockSize = pblock->GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION);
		pblock->GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION);

//		int64_t nStart = GetTime();
		while (true) {
			pblock->SetTime(max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime()));
			set<CKeyID> setCreateKey;
			setCreateKey.clear();
			setCreateKey.insert(keyID);
			if (CreatePosTx(pindexPrev, pblock,setCreateKey,accview,txCache,ScriptDbTemp)) {
				CheckWork(pblock, *pwalletMain);
//				int nBlockSize = pblock->GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION);
			}
			if(setCreateKey.empty())
			{
				LogPrint("postx", "%s is not exist in the wallet\r\n",keyID.ToAddress());
				break;
			}
			::MilliSleep(1);
			if (pindexPrev != chainActive.Tip())
			{
				return chainActive.Tip()->GetBlockHash() ;
			}
		}
	}
	return uint256();
}