Skip to content

Commit

Permalink
Remove unused functions in wallet.cpp
Browse files Browse the repository at this point in the history
these functions were used back when obfuscation existed and are no
longer called anywhere in the source tree.
  • Loading branch information
Fuzzbawls committed May 15, 2019
1 parent 166b2d3 commit 3bb5c76
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 294 deletions.
282 changes: 0 additions & 282 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,122 +1744,6 @@ std::map<libzerocoin::CoinDenomination, CAmount> CWallet::GetMyZerocoinDistribut
}


CAmount CWallet::GetAnonymizableBalance() const
{
if (fLiteMode) return 0;

CAmount nTotal = 0;
{
LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;

if (pcoin->IsTrusted())
nTotal += pcoin->GetAnonymizableCredit();
}
}

return nTotal;
}

CAmount CWallet::GetAnonymizedBalance() const
{
if (fLiteMode) return 0;

CAmount nTotal = 0;
{
LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;

if (pcoin->IsTrusted())
nTotal += pcoin->GetAnonymizedCredit();
}
}

return nTotal;
}

// Note: calculated including unconfirmed,
// that's ok as long as we use it for informational purposes only
double CWallet::GetAverageAnonymizedRounds() const
{
if (fLiteMode) return 0;

double fTotal = 0;
double fCount = 0;

{
LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;

uint256 hash = (*it).first;

for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
CTxIn vin = CTxIn(hash, i);

if (IsSpent(hash, i) || IsMine(pcoin->vout[i]) != ISMINE_SPENDABLE || !IsDenominated(vin)) continue;

int rounds = GetInputObfuscationRounds(vin);
fTotal += (float)rounds;
fCount += 1;
}
}
}

if (fCount == 0) return 0;

return fTotal / fCount;
}

// Note: calculated including unconfirmed,
// that's ok as long as we use it for informational purposes only
CAmount CWallet::GetNormalizedAnonymizedBalance() const
{
if (fLiteMode) return 0;

CAmount nTotal = 0;

{
LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;

uint256 hash = (*it).first;

for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
CTxIn vin = CTxIn(hash, i);

if (IsSpent(hash, i) || IsMine(pcoin->vout[i]) != ISMINE_SPENDABLE || !IsDenominated(vin)) continue;
if (pcoin->GetDepthInMainChain() < 0) continue;

int rounds = GetInputObfuscationRounds(vin);
nTotal += pcoin->vout[i].nValue * rounds / nZeromintPercentage;
}
}
}

return nTotal;
}

CAmount CWallet::GetDenominatedBalance(bool unconfirmed) const
{
if (fLiteMode) return 0;

CAmount nTotal = 0;
{
LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;

nTotal += pcoin->GetDenominatedCredit(unconfirmed);
}
}

return nTotal;
}

CAmount CWallet::GetUnconfirmedBalance() const
{
CAmount nTotal = 0;
Expand Down Expand Up @@ -2498,48 +2382,6 @@ bool CWallet::SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount
return (nValueRet >= nValueMin && fFound10000 && fFound1000 && fFound100 && fFound10 && fFound1 && fFoundDot1);
}

bool CWallet::SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& setCoinsRet, CAmount& nValueRet, int nObfuscationRoundsMin, int nObfuscationRoundsMax) const
{
CCoinControl* coinControl = NULL;

setCoinsRet.clear();
nValueRet = 0;

vector<COutput> vCoins;
AvailableCoins(vCoins, true, coinControl, false, nObfuscationRoundsMin < 0 ? ONLY_NONDENOMINATED_NOT10000IFMN : ONLY_DENOMINATED);

set<pair<const CWalletTx*, unsigned int> > setCoinsRet2;

//order the array so largest nondenom are first, then denominations, then very small inputs.
sort(vCoins.rbegin(), vCoins.rend(), CompareByPriority());

for (const COutput& out : vCoins) {
//do not allow inputs less than 1 CENT
if (out.tx->vout[out.i].nValue < CENT) continue;
//do not allow collaterals to be selected
if (IsCollateralAmount(out.tx->vout[out.i].nValue)) continue;
if (fMasterNode && out.tx->vout[out.i].nValue == 10000 * COIN) continue; //masternode input

if (nValueRet + out.tx->vout[out.i].nValue <= nValueMax) {
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);

int rounds = GetInputObfuscationRounds(vin);
if (rounds >= nObfuscationRoundsMax) continue;
if (rounds < nObfuscationRoundsMin) continue;

vin.prevPubKey = out.tx->vout[out.i].scriptPubKey; // the inputs PubKey
nValueRet += out.tx->vout[out.i].nValue;
setCoinsRet.push_back(vin);
setCoinsRet2.insert(make_pair(out.tx, out.i));
}
}

// if it's more than min, we're good to return
if (nValueRet >= nValueMin) return true;

return false;
}

bool CWallet::SelectCoinsCollateral(std::vector<CTxIn>& setCoinsRet, CAmount& nValueRet) const
{
vector<COutput> vCoins;
Expand Down Expand Up @@ -2567,33 +2409,6 @@ bool CWallet::SelectCoinsCollateral(std::vector<CTxIn>& setCoinsRet, CAmount& nV
return false;
}

int CWallet::CountInputsWithAmount(CAmount nInputAmount)
{
CAmount nTotal = 0;
{
LOCK(cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) {
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsTrusted()) {
int nDepth = pcoin->GetDepthInMainChain(false);

for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
COutput out = COutput(pcoin, i, nDepth, true);
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);

if (out.tx->vout[out.i].nValue != nInputAmount) continue;
if (!IsDenominatedAmount(pcoin->vout[i].nValue)) continue;
if (IsSpent(out.tx->GetHash(), i) || IsMine(pcoin->vout[i]) != ISMINE_SPENDABLE || !IsDenominated(vin)) continue;

nTotal++;
}
}
}
}

return nTotal;
}

bool CWallet::HasCollateralInputs(bool fOnlyConfirmed) const
{
vector<COutput> vCoins;
Expand All @@ -2611,57 +2426,6 @@ bool CWallet::IsCollateralAmount(CAmount nInputAmount) const
return nInputAmount != 0 && nInputAmount % OBFUSCATION_COLLATERAL == 0 && nInputAmount < OBFUSCATION_COLLATERAL * 5 && nInputAmount > OBFUSCATION_COLLATERAL;
}

bool CWallet::CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason)
{
/*
To doublespend a collateral transaction, it will require a fee higher than this. So there's
still a significant cost.
*/
CAmount nFeeRet = 1 * COIN;

txCollateral.vin.clear();
txCollateral.vout.clear();

CReserveKey reservekey(this);
CAmount nValueIn2 = 0;
std::vector<CTxIn> vCoinsCollateral;

if (!SelectCoinsCollateral(vCoinsCollateral, nValueIn2)) {
strReason = "Error: Obfuscation requires a collateral transaction and could not locate an acceptable input!";
return false;
}

// make our change address
CScript scriptChange;
CPubKey vchPubKey;
assert(reservekey.GetReservedKey(vchPubKey)); // should never fail, as we just unlocked
scriptChange = GetScriptForDestination(vchPubKey.GetID());
reservekey.KeepKey();

for (CTxIn v : vCoinsCollateral)
txCollateral.vin.push_back(v);

if (nValueIn2 - OBFUSCATION_COLLATERAL - nFeeRet > 0) {
//pay collateral charge in fees
CTxOut vout3 = CTxOut(nValueIn2 - OBFUSCATION_COLLATERAL, scriptChange);
txCollateral.vout.push_back(vout3);
}

int vinNumber = 0;
for (CTxIn v : txCollateral.vin) {
if (!SignSignature(*this, v.prevPubKey, txCollateral, vinNumber, int(SIGHASH_ALL | SIGHASH_ANYONECANPAY))) {
for (CTxIn v : vCoinsCollateral)
UnlockCoin(v.prevout);

strReason = "CObfuscationPool::Sign - Unable to sign collateral transaction! \n";
return false;
}
vinNumber++;
}

return true;
}

bool CWallet::GetBudgetSystemCollateralTX(CWalletTx& tx, uint256 hash, bool useIX)
{
// make our change address
Expand Down Expand Up @@ -2708,21 +2472,6 @@ bool CWallet::GetBudgetFinalizationCollateralTX(CWalletTx& tx, uint256 hash, boo
return true;
}

bool CWallet::ConvertList(std::vector<CTxIn> vCoins, std::vector<CAmount>& vecAmounts)
{
for (CTxIn i : vCoins) {
if (mapWallet.count(i.prevout.hash)) {
CWalletTx& wtx = mapWallet[i.prevout.hash];
if (i.prevout.n < wtx.vout.size()) {
vecAmounts.push_back(wtx.vout[i.prevout.n].nValue);
}
} else {
LogPrintf("ConvertList -- Couldn't find transaction\n");
}
}
return true;
}

bool CWallet::CreateTransaction(const vector<pair<CScript, CAmount> >& vecSend,
CWalletTx& wtxNew,
CReserveKey& reservekey,
Expand Down Expand Up @@ -3235,23 +2984,6 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
return nFeeNeeded;
}

CAmount CWallet::GetTotalValue(std::vector<CTxIn> vCoins)
{
CAmount nTotalValue = 0;
CWalletTx wtx;
for (CTxIn i : vCoins) {
if (mapWallet.count(i.prevout.hash)) {
CWalletTx& wtx = mapWallet[i.prevout.hash];
if (i.prevout.n < wtx.vout.size()) {
nTotalValue += wtx.vout[i.prevout.n].nValue;
}
} else {
LogPrintf("GetTotalValue -- Couldn't find transaction\n");
}
}
return nTotalValue;
}

string CWallet::PrepareObfuscationDenominate(int minRounds, int maxRounds)
{
if (IsLocked())
Expand Down Expand Up @@ -4013,20 +3745,6 @@ bool CWallet::LoadDestData(const CTxDestination& dest, const std::string& key, c
return true;
}

bool CWallet::GetDestData(const CTxDestination& dest, const std::string& key, std::string* value) const
{
std::map<CTxDestination, CAddressBookData>::const_iterator i = mapAddressBook.find(dest);
if (i != mapAddressBook.end()) {
CAddressBookData::StringMap::const_iterator j = i->second.destdata.find(key);
if (j != i->second.destdata.end()) {
if (value)
*value = j->second;
return true;
}
}
return false;
}

void CWallet::InitAutoConvertAddresses()
{
CWalletDB walletdb(strWalletFile);
Expand Down
12 changes: 0 additions & 12 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,10 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
public:
bool MintableCoins();
bool SelectStakeCoins(std::list<std::unique_ptr<CStakeInput> >& listInputs, CAmount nTargetAmount, bool fPrecompute = false);
bool SelectCoinsDark(CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& setCoinsRet, CAmount& nValueRet, int nObfuscationRoundsMin, int nObfuscationRoundsMax) const;
bool SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount nValueMax, std::vector<CTxIn>& vCoinsRet, std::vector<COutput>& vCoinsRet2, CAmount& nValueRet, int nObfuscationRoundsMin, int nObfuscationRoundsMax);
bool SelectCoinsDarkDenominated(CAmount nTargetValue, std::vector<CTxIn>& setCoinsRet, CAmount& nValueRet) const;
bool HasCollateralInputs(bool fOnlyConfirmed = true) const;
bool IsCollateralAmount(CAmount nInputAmount) const;
int CountInputsWithAmount(CAmount nInputAmount);

bool SelectCoinsCollateral(std::vector<CTxIn>& setCoinsRet, CAmount& nValueRet) const;

Expand Down Expand Up @@ -411,7 +409,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
void UnlockCoin(COutPoint& output);
void UnlockAllCoins();
void ListLockedCoins(std::vector<COutPoint>& vOutpts);
CAmount GetTotalValue(std::vector<CTxIn> vCoins);

// keystore implementation
// Generate a new key
Expand Down Expand Up @@ -446,8 +443,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
bool EraseDestData(const CTxDestination& dest, const std::string& key);
//! Adds a destination data tuple to the store, without saving it to disk
bool LoadDestData(const CTxDestination& dest, const std::string& key, const std::string& value);
//! Look up a destination data tuple in the store, return true if found false otherwise
bool GetDestData(const CTxDestination& dest, const std::string& key, std::string* value) const;

//! Adds a watch-only address to the store, and saves it to disk.
bool AddWatchOnly(const CScript& dest);
Expand Down Expand Up @@ -491,11 +486,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
std::map<libzerocoin::CoinDenomination, CAmount> GetMyZerocoinDistribution() const;
CAmount GetUnconfirmedBalance() const;
CAmount GetImmatureBalance() const;
CAmount GetAnonymizableBalance() const;
CAmount GetAnonymizedBalance() const;
double GetAverageAnonymizedRounds() const;
CAmount GetNormalizedAnonymizedBalance() const;
CAmount GetDenominatedBalance(bool unconfirmed = false) const;
CAmount GetWatchOnlyBalance() const;
CAmount GetUnconfirmedWatchOnlyBalance() const;
CAmount GetImmatureWatchOnlyBalance() const;
Expand All @@ -515,8 +505,6 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
bool AddAccountingEntry(const CAccountingEntry&, CWalletDB & pwalletdb);
std::string PrepareObfuscationDenominate(int minRounds, int maxRounds);
int GenerateObfuscationOutputs(int nTotalValue, std::vector<CTxOut>& vout);
bool CreateCollateralTransaction(CMutableTransaction& txCollateral, std::string& strReason);
bool ConvertList(std::vector<CTxIn> vCoins, std::vector<int64_t>& vecAmounts);
bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, CMutableTransaction& txNew, unsigned int& nTxNewTime);
bool MultiSend();
void AutoCombineDust();
Expand Down

0 comments on commit 3bb5c76

Please sign in to comment.