Automatically lock ProTx collaterals when TX is added/loaded to wallet
Avoid accidential spending of ProTx collaterals.
This commit is contained in:
parent
cdd723ede6
commit
76fd308947
@ -120,3 +120,18 @@ void CProRegTx::ToJson(UniValue& obj) const
|
||||
|
||||
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
|
||||
}
|
||||
|
||||
bool IsProTxCollateral(const CTransaction& tx, uint32_t n)
|
||||
{
|
||||
return GetProTxCollateralIndex(tx) == n;
|
||||
}
|
||||
|
||||
uint32_t GetProTxCollateralIndex(const CTransaction& tx)
|
||||
{
|
||||
if (tx.nVersion < 3 || tx.nType != TRANSACTION_PROVIDER_REGISTER)
|
||||
return (uint32_t) - 1;
|
||||
CProRegTx proTx;
|
||||
if (!GetTxPayload(tx, proTx))
|
||||
assert(false);
|
||||
return proTx.nCollateralIndex;
|
||||
}
|
||||
|
@ -59,4 +59,7 @@ public:
|
||||
|
||||
bool CheckProRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
|
||||
|
||||
bool IsProTxCollateral(const CTransaction& tx, uint32_t n);
|
||||
uint32_t GetProTxCollateralIndex(const CTransaction& tx);
|
||||
|
||||
#endif//DASH_PROVIDERTX_H
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include "privatesend-client.h"
|
||||
#include "spork.h"
|
||||
|
||||
#include "evo/providertx.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
@ -1116,9 +1118,14 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||
wtxIn.hashBlock.ToString());
|
||||
}
|
||||
AddToSpends(hash);
|
||||
|
||||
uint32_t proTxCollateralIdx = GetProTxCollateralIndex(*wtx.tx);
|
||||
for(unsigned int i = 0; i < wtx.tx->vout.size(); ++i) {
|
||||
if (IsMine(wtx.tx->vout[i]) && !IsSpent(hash, i)) {
|
||||
setWalletUTXO.insert(COutPoint(hash, i));
|
||||
if (i == proTxCollateralIdx) {
|
||||
LockCoin(COutPoint(hash, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3968,9 +3975,13 @@ DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
for (auto& pair : mapWallet) {
|
||||
uint32_t proTxCollateralIdx = GetProTxCollateralIndex(*pair.second.tx);
|
||||
for(unsigned int i = 0; i < pair.second.tx->vout.size(); ++i) {
|
||||
if (IsMine(pair.second.tx->vout[i]) && !IsSpent(pair.first, i)) {
|
||||
setWalletUTXO.insert(COutPoint(pair.first, i));
|
||||
if (i == proTxCollateralIdx) {
|
||||
LockCoin(COutPoint(pair.first, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user