- use only trusted coins to calculate anon balance/avg rounds

- use only non-conflicted coins to calculate denom balance
- move GetDepthInMainChain and some conditions out of loops
This commit is contained in:
UdjinM6 2015-02-06 04:53:28 +03:00
parent 6149e55710
commit 16f725961a

View File

@ -1096,10 +1096,14 @@ int64_t CWallet::GetAnonymizedBalance() const
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
if (pcoin->IsTrusted()){
if (pcoin->IsTrusted())
{
int nDepth = pcoin->GetDepthInMainChain(false);
for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain(false));
COutput out = COutput(pcoin, i, nDepth);
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);
if(IsSpent(out.tx->GetHash(), i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue;
@ -1127,9 +1131,13 @@ double CWallet::GetAverageAnonymizedRounds() const
{
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, pcoin->GetDepthInMainChain(false));
COutput out = COutput(pcoin, i, nDepth);
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);
if(IsSpent(out.tx->GetHash(), i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue;
@ -1140,6 +1148,7 @@ double CWallet::GetAverageAnonymizedRounds() const
}
}
}
}
if(fCount == 0) return 0;
@ -1155,9 +1164,14 @@ int64_t CWallet::GetNormalizedAnonymizedBalance() const
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, pcoin->GetDepthInMainChain(false));
COutput out = COutput(pcoin, i, nDepth);
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);
if(IsSpent(out.tx->GetHash(), i) || !IsMine(pcoin->vout[i]) || !IsDenominated(vin)) continue;
@ -1167,6 +1181,7 @@ int64_t CWallet::GetNormalizedAnonymizedBalance() const
}
}
}
}
return nTotal;
}
@ -1180,16 +1195,20 @@ int64_t CWallet::GetDenominatedBalance(bool onlyDenom, bool onlyUnconfirmed) con
{
const CWalletTx* pcoin = &(*it).second;
int nDepth = pcoin->GetDepthInMainChain(false);
// skip conflicted
if(nDepth < 0) continue;
bool unconfirmed = (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && nDepth == 0));
if(onlyUnconfirmed != unconfirmed) continue;
for (unsigned int i = 0; i < pcoin->vout.size(); i++)
{
COutput out = COutput(pcoin, i, pcoin->GetDepthInMainChain(false));
CTxIn vin = CTxIn(out.tx->GetHash(), out.i);
bool unconfirmed = (!IsFinalTx(*pcoin) || (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain(false) == 0));
COutput out = COutput(pcoin, i, nDepth);
if(IsSpent(out.tx->GetHash(), i)) continue;
if(!IsMine(pcoin->vout[i])) continue;
if(onlyUnconfirmed != unconfirmed) continue;
if(onlyDenom != IsDenominatedAmount(pcoin->vout[i].nValue)) continue;
nTotal += pcoin->vout[i].nValue;
@ -1681,22 +1700,21 @@ int CWallet::CountInputsWithAmount(int64_t nInputAmount)
{
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, pcoin->GetDepthInMainChain());
COutput out = COutput(pcoin, i, nDepth);
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]) || !IsDenominated(vin)) continue;
int rounds = GetInputDarksendRounds(vin);
if(rounds >= nDarksendRounds){
nTotal++;
}
}
}
}
}
return nTotal;
}