bool isSerialSpendable(CCoinsView &v,const uint256 &txid, const uint256 &serial,uint256 &idOfTxThatSpentIt){ if(v.GetSerial(txid,idOfTxThatSpentIt)){ return idOfTxThatSpentIt == always_spendable_txid; }else{ return true; } }
NameIterationTester::EntryList NameIterationTester::getNamesFromView (const CCoinsView& view, const valtype& start) { std::auto_ptr<CNameIterator> iter(view.IterateNames ()); iter->seek (start); return getNamesFromIterator (*iter); }
void NameIterationTester::verify (const CCoinsView& view) const { /* Try out everything with all names as "start". This thoroughly checks that also the start implementation is correct. It also checks using a single iterator and seeking vs using a fresh iterator. */ valtype start; EntryList remaining(data.begin (), data.end ()); /* Seek the iterator to the end first for "maximum confusion". This ensures that seeking to valtype() works. */ std::auto_ptr<CNameIterator> iter(view.IterateNames ()); const valtype end = ValtypeFromString ("zzzzzzzzzzzzzzzz"); { valtype name; CNameData data; iter->seek (end); BOOST_CHECK (!iter->next (name, data)); } while (true) { EntryList got = getNamesFromView (view, start); BOOST_CHECK (got == remaining); iter->seek (start); got = getNamesFromIterator (*iter); BOOST_CHECK (got == remaining); if (remaining.empty ()) break; if (start == remaining.front ().first) remaining.pop_front (); if (remaining.empty ()) start = end; else start = remaining.front ().first; } }
bool markSerialAsUnSpent(CCoinsView &v, const uint256 &serial){ LogPrint("zerocoin","zerocoin markSerialAsUnSpent: marking serial %s as unspent.\n",serial.ToString()); return v.SetSerial(serial,always_spendable_txid); }
bool markSerialAsSpent(CCoinsView &v, const uint256 &serial,const uint256 &txid){ LogPrint("zerocoin","zerocoin markSerialAsSpent: marking serial %s as spent by %s \n",serial.ToString(),txid.ToString()); return v.SetSerial(serial,txid); }
void CNameTxUndo::fromOldState (const valtype& nm, const CCoinsView& view) { name = nm; isNew = !view.GetName (name, oldData); }
void WriteCoinsViewEntry(CCoinsView& view, CAmount value, char flags) { CCoinsMap map; InsertCoinsMapEntry(map, value, flags); view.BatchWrite(map, {}); }
bool CreateGameTransactions (const CCoinsView& view, unsigned nHeight, const StepResult& stepResult, std::vector<CTransaction>& vGameTx) { vGameTx.clear (); /* Destroy name-coins of killed players. */ bool haveTxKills = false; CMutableTransaction txKills; txKills.SetGameTx (); const PlayerSet& killedPlayers = stepResult.GetKilledPlayers (); const KilledByMap& killedBy = stepResult.GetKilledBy (); txKills.vin.reserve (killedPlayers.size ()); BOOST_FOREACH(const PlayerID &victim, killedPlayers) { const valtype vchName = ValtypeFromString (victim); CNameData data; if (!view.GetName (vchName, data)) return error ("Game engine killed a non-existing player %s", victim.c_str ()); CTxIn txin(data.getUpdateOutpoint ()); /* List all killers, if player was simultaneously killed by several other players. If the reason was not KILLED_DESTRUCT, handle it also. If multiple reasons apply, the game tx is constructed for the first reason according to the ordering inside of KilledByMap. (Which in turn is determined by the enum values for KILLED_*.) */ typedef KilledByMap::const_iterator Iter; const std::pair<Iter, Iter> iters = killedBy.equal_range (victim); if (iters.first == iters.second) return error ("No reason for killed player %s", victim.c_str ()); const KilledByInfo::Reason reason = iters.first->second.reason; /* Unless we have destruct, there should be exactly one entry with the "first" reason. There may be multiple entries for different reasons, for instance, killed by poison and staying in spawn area at the same time. */ { Iter it = iters.first; ++it; if (reason != KilledByInfo::KILLED_DESTRUCT && it != iters.second && reason == it->second.reason) return error ("Multiple same-reason, non-destruct killed-by" " entries for %s", victim.c_str ()); } switch (reason) { case KilledByInfo::KILLED_DESTRUCT: txin.scriptSig << vchName << GAMEOP_KILLED_BY; for (Iter it = iters.first; it != iters.second; ++it) { if (it->second.reason != KilledByInfo::KILLED_DESTRUCT) { assert (it != iters.first); break; } txin.scriptSig << ValtypeFromString (it->second.killer.ToString ()); } break; case KilledByInfo::KILLED_SPAWN: txin.scriptSig << vchName << GAMEOP_KILLED_BY; break; case KilledByInfo::KILLED_POISON: txin.scriptSig << vchName << GAMEOP_KILLED_POISON; break; default: assert (false); } txKills.vin.push_back (txin); haveTxKills = true; } if (haveTxKills) { const CTransaction tx(txKills); assert (tx.IsGameTx () && !tx.IsBountyTx ()); vGameTx.push_back (tx); } /* Pay bounties to the players who collected them. The transaction inputs are just "dummy" containing informational messages. */ bool haveTxBounties = false; CMutableTransaction txBounties; txBounties.SetGameTx (); txBounties.vin.reserve (stepResult.bounties.size ()); txBounties.vout.reserve (stepResult.bounties.size ()); BOOST_FOREACH(const CollectedBounty& bounty, stepResult.bounties) { const valtype vchName = ValtypeFromString (bounty.character.player); CNameData data; if (!view.GetName (vchName, data)) return error ("Game engine created bounty for non-existing player"); CTxOut txout; txout.nValue = bounty.loot.nAmount; if (!bounty.address.empty ()) { /* Player-provided addresses are validated before accepting them, so failing here is ok. */ CBitcoinAddress addr(bounty.address); if (!addr.IsValid ()) return error ("Failed to set player-provided address for bounty"); txout.scriptPubKey = GetScriptForDestination (addr.Get ()); } else txout.scriptPubKey = data.getAddress (); txBounties.vout.push_back (txout); CTxIn txin; if (bounty.loot.IsRefund ()) txin.scriptSig << vchName << GAMEOP_REFUND << bounty.character.index << bounty.loot.GetRefundHeight (); else txin.scriptSig << vchName << GAMEOP_COLLECTED_BOUNTY << bounty.character.index << bounty.loot.firstBlock << bounty.loot.lastBlock << bounty.loot.collectedFirstBlock << bounty.loot.collectedLastBlock; txBounties.vin.push_back (txin); haveTxBounties = true; } if (haveTxBounties) { const CTransaction tx(txBounties); assert (tx.IsGameTx () && tx.IsBountyTx ()); vGameTx.push_back (tx); } /* Print log chatter. */ if (haveTxKills || haveTxBounties) { LogPrint ("game", "Game transactions @%d:\n", nHeight); if (haveTxKills) LogPrint ("game", " kills: %s\n", txKills.GetHash ().ToString ()); if (haveTxBounties) LogPrint ("game", " bounties: %s\n", txBounties.GetHash ().ToString ()); } return true; }