implement bip69

This commit is contained in:
UdjinM6 2015-08-21 04:28:17 +03:00
parent 0002fd1d6e
commit 9055883eab
3 changed files with 19 additions and 10 deletions

View File

@ -379,8 +379,6 @@ void CDarksendPool::ProcessMessageDarksend(CNode* pfrom, std::string& strCommand
}
int randomizeList (int i) { return std::rand()%i;}
void CDarksendPool::Reset(){
cachedLastSuccess = 0;
lastNewBlock = 0;
@ -533,9 +531,9 @@ void CDarksendPool::Check()
txNew.vin.push_back(s);
}
// shuffle the outputs for improved anonymity
std::random_shuffle ( txNew.vin.begin(), txNew.vin.end(), randomizeList);
std::random_shuffle ( txNew.vout.begin(), txNew.vout.end(), randomizeList);
// BIP69 https://github.com/kristovatlas/bips/blob/master/bip-0069.mediawiki
sort(txNew.vin.begin(), txNew.vin.end());
sort(txNew.vout.begin(), txNew.vout.end());
LogPrint("darksend", "Transaction 1: %s\n", txNew.ToString());

View File

@ -99,6 +99,11 @@ public:
return !(a == b);
}
friend bool operator<(const CTxIn& a, const CTxIn& b)
{
return a.prevout<b.prevout;
}
std::string ToString() const;
};
@ -166,6 +171,11 @@ public:
return !(a == b);
}
friend bool operator<(const CTxOut& a, const CTxOut& b)
{
return a.nValue < b.nValue || (a.nValue == b.nValue && a.scriptPubKey < b.scriptPubKey);
}
std::string ToString() const;
};

View File

@ -2234,10 +2234,14 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, CAmount> >& vecSend,
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
txNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second));
// BIP69 https://github.com/kristovatlas/bips/blob/master/bip-0069.mediawiki
sort(txNew.vin.begin(), txNew.vin.end());
sort(txNew.vout.begin(), txNew.vout.end());
// Sign
int nIn = 0;
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
if (!SignSignature(*this, *coin.first, txNew, nIn++))
BOOST_FOREACH(const CTxIn& vin, txNew.vin)
if (!SignSignature(*this, mapWallet[vin.prevout.hash], txNew, nIn++))
{
strFailReason = _("Signing transaction failed");
return false;
@ -2505,9 +2509,6 @@ string CWallet::PrepareDarksendDenominate(int minRounds, int maxRounds)
return "Error: can't make current denominated outputs";
}
// randomize the output order
std::random_shuffle (vOut.begin(), vOut.end());
// We also do not care about full amount as long as we have right denominations, just pass what we found
darkSendPool.SendDarksendDenominate(vCoinsResult, vOut, nValueIn - nValueLeft);