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(); }
Value getnewaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "getnewaddress (\"IsMiner\")\n" "\nget a new address\n" "\nArguments:\n" "1. \"IsMiner\" (bool, optional) private key Is used for miner if true will create tow key ,another for miner.\n" "\nExamples:\n" + HelpExampleCli("getnewaddress", "") + HelpExampleCli("getnewaddress", "true") ); EnsureWalletIsUnlocked(); CKey mCkey; mCkey.MakeNewKey(); CKey Minter; bool IsForMiner = false; if (params.size() == 1) { RPCTypeCheck(params, list_of(bool_type)); Minter.MakeNewKey(); IsForMiner = params[0].get_bool(); } CPubKey newKey = mCkey.GetPubKey(); CKeyID keyID = newKey.GetKeyID(); if (IsForMiner) { if (!pwalletMain->AddKey(mCkey, Minter)) throw runtime_error("add key failed "); } else if (!pwalletMain->AddKey(mCkey)) { throw runtime_error("add key failed "); } Object obj; obj.push_back(Pair("addr", keyID.ToAddress())); obj.push_back(Pair("minerpubkey", IsForMiner?Minter.GetPubKey().ToString(): "no" )); return obj; }