MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ProcessGenesisBlock

Function ProcessGenesisBlock

src/main.cpp:766–873  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764}
765
766static bool ProcessGenesisBlock(CBlock &block, CCacheWrapper &cw, CBlockIndex *pIndex, CValidationState &state) {
767
768 cw.blockCache.SetBestBlock(pIndex->GetBlockHash());
769 for (uint32_t i = 1; i < block.vptx.size(); i++) {
770 if (block.vptx[i]->nTxType == BLOCK_REWARD_TX) {
771 assert(i <= 1);
772 CBlockRewardTx *pRewardTx = (CBlockRewardTx *)block.vptx[i].get();
773 CAccount account;
774 CRegID regId(pIndex->height, i);
775 CPubKey pubKey = pRewardTx->txUid.get<CPubKey>();
776 CKeyID keyId = pubKey.GetKeyId();
777 account.keyid = keyId;
778 account.owner_pubkey = pubKey;
779 account.regid = regId;
780
781 account.OperateBalance(SYMB::WICC, BalanceOpType::ADD_FREE, pRewardTx->reward_fees,
782 ReceiptType::BLOCK_REWARD_TO_MINER, pRewardTx->receipts);
783
784 if (!cw.txReceiptCache.SetTxReceipts(pRewardTx->GetHash(), pRewardTx->receipts))
785 return state.DoS(100, ERRORMSG("Set genesis block receipts failed!"),
786 REJECT_INVALID, "set-tx-receipt-failed");
787
788 assert( cw.accountCache.SaveAccount(account) );
789 } else if (block.vptx[i]->nTxType == DELEGATE_VOTE_TX) {
790
791 CDelegateVoteTx *pDelegateTx = (CDelegateVoteTx *)block.vptx[i].get();
792 assert(pDelegateTx->txUid.is<CRegID>()); // Vote Tx must use RegId
793
794 CAccount voterAcct;
795 assert(cw.accountCache.GetAccount(pDelegateTx->txUid, voterAcct));
796 CUserID uid(pDelegateTx->txUid);
797 uint64_t maxVotes = 0;
798 vector<CCandidateReceivedVote> candidateVotes;
799 int32_t j = i;
800 for (const auto &vote : pDelegateTx->candidateVotes) {
801 assert(vote.GetCandidateVoteType() == ADD_BCOIN); // it has to be ADD in GensisBlock
802 if (vote.GetVotedBcoins() > maxVotes) {
803 maxVotes = vote.GetVotedBcoins();
804 }
805
806 CUserID votedUid = vote.GetCandidateUid();
807
808 if (uid == votedUid) { // vote for self
809 voterAcct.received_votes = vote.GetVotedBcoins();
810 assert(cw.delegateCache.SetDelegateVotes(voterAcct.regid, voterAcct.received_votes));
811 } else { // vote for others
812 CAccount votedAcct;
813 assert(!cw.accountCache.GetAccount(votedUid, votedAcct));
814
815 CRegID votedRegId(pIndex->height, j++); // generate RegId in genesis block
816 votedAcct.SetRegId(votedRegId);
817 votedAcct.received_votes = vote.GetVotedBcoins();
818
819 if (votedUid.is<CPubKey>()) {
820 votedAcct.owner_pubkey = votedUid.get<CPubKey>();
821 votedAcct.keyid = votedAcct.owner_pubkey.GetKeyId();
822 }
823

Callers 1

ConnectBlockFunction · 0.85

Calls 15

sortFunction · 0.85
PersistNativeAssetFunction · 0.85
SetBestBlockMethod · 0.80
OperateBalanceMethod · 0.80
SetTxReceiptsMethod · 0.80
DoSMethod · 0.80
SaveAccountMethod · 0.80
GetCandidateVoteTypeMethod · 0.80
SetDelegateVotesMethod · 0.80
SetRegIdMethod · 0.80

Tested by

no test coverage detected