bool CzPIVWallet::RegenerateMint(const CDeterministicMint& dMint, CZerocoinMint& mint) { if (!CheckSeed(dMint)) { uint256 hashSeed = Hash(seedMaster.begin(), seedMaster.end()); return error("%s: master seed does not match!\ndmint:\n %s \nhashSeed: %s\nseed: %s", __func__, dMint.ToString(), hashSeed.GetHex(), seedMaster.GetHex()); } //Generate the coin PrivateCoin coin(Params().Zerocoin_Params(false), dMint.GetDenomination(), false); CDeterministicMint dMintDummy; GenerateMint(dMint.GetCount(), dMint.GetDenomination(), coin, dMintDummy); //Fill in the zerocoinmint object's details CBigNum bnValue = coin.getPublicCoin().getValue(); if (GetPubCoinHash(bnValue) != dMint.GetPubcoinHash()) return error("%s: failed to correctly generate mint, pubcoin hash mismatch", __func__); mint.SetValue(bnValue); CBigNum bnSerial = coin.getSerialNumber(); if (GetSerialHash(bnSerial) != dMint.GetSerialHash()) return error("%s: failed to correctly generate mint, serial hash mismatch", __func__); mint.SetSerialNumber(bnSerial); mint.SetRandomness(coin.getRandomness()); mint.SetPrivKey(coin.getPrivKey()); mint.SetVersion(coin.getVersion()); mint.SetDenomination(dMint.GetDenomination()); mint.SetUsed(dMint.IsUsed()); mint.SetTxHash(dMint.GetTxHash()); mint.SetHeight(dMint.GetHeight()); return true; }
bool CzTNXTracker::UpdateState(const CMintMeta& meta) { CWalletDB walletdb(strWalletFile); if (meta.isDeterministic) { CDeterministicMint dMint; if (!walletdb.ReadDeterministicMint(meta.hashPubcoin, dMint)) { // Check archive just in case if (!meta.isArchived) return error("%s: failed to read deterministic mint from database", __func__); // Unarchive this mint since it is being requested and updated if (!walletdb.UnarchiveDeterministicMint(meta.hashPubcoin, dMint)) return error("%s: failed to unarchive deterministic mint from database", __func__); } dMint.SetTxHash(meta.txid); dMint.SetHeight(meta.nHeight); dMint.SetUsed(meta.isUsed); dMint.SetDenomination(meta.denom); dMint.SetStakeHash(meta.hashStake); if (!walletdb.WriteDeterministicMint(dMint)) return error("%s: failed to update deterministic mint when writing to db", __func__); } else { CZerocoinMint mint; if (!walletdb.ReadZerocoinMint(meta.hashPubcoin, mint)) return error("%s: failed to read mint from database", __func__); mint.SetTxHash(meta.txid); mint.SetHeight(meta.nHeight); mint.SetUsed(meta.isUsed); mint.SetDenomination(meta.denom); if (!walletdb.WriteZerocoinMint(mint)) return error("%s: failed to write mint to database", __func__); } mapSerialHashes[meta.hashSerial] = meta; return true; }
void CzTNXTracker::Add(const CZerocoinMint& mint, bool isNew, bool isArchived) { CMintMeta meta; meta.hashPubcoin = GetPubCoinHash(mint.GetValue()); meta.nHeight = mint.GetHeight(); meta.nVersion = libzerocoin::ExtractVersionFromSerial(mint.GetSerialNumber()); meta.txid = mint.GetTxHash(); meta.isUsed = mint.IsUsed(); meta.hashSerial = GetSerialHash(mint.GetSerialNumber()); uint256 nSerial = mint.GetSerialNumber().getuint256(); meta.hashStake = Hash(nSerial.begin(), nSerial.end()); meta.denom = mint.GetDenomination(); meta.isArchived = isArchived; meta.isDeterministic = false; mapSerialHashes[meta.hashSerial] = meta; if (isNew) CWalletDB(strWalletFile).WriteZerocoinMint(mint); }
bool CzTNXTracker::UpdateZerocoinMint(const CZerocoinMint& mint) { if (!HasSerial(mint.GetSerialNumber())) return error("%s: mint %s is not known", __func__, mint.GetValue().GetHex()); uint256 hashSerial = GetSerialHash(mint.GetSerialNumber()); //Update the meta object CMintMeta meta = Get(hashSerial); meta.isUsed = mint.IsUsed(); meta.denom = mint.GetDenomination(); meta.nHeight = mint.GetHeight(); mapSerialHashes.at(hashSerial) = meta; //Write to db return CWalletDB(strWalletFile).WriteZerocoinMint(mint); }