Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the unspent index for remints of 50 XZC #714

Merged
merged 3 commits into from
Oct 8, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,19 +487,19 @@ void handleInput(CTxIn const & input, size_t inputNo, uint256 const & txHash, in
spentIndex->push_back(make_pair(CSpentIndexKey(input.prevout.hash, input.prevout.n), CSpentIndexValue(txHash, inputNo, height, prevout.nValue, addrType.first, addrType.second)));
}

void handleRemint(CTxIn const & input, size_t inputNo, uint256 const & txHash, int height, int txNumber, CAmount nValue,
void handleRemint(CTxIn const & input, uint256 const & txHash, int height, int txNumber, CAmount nValue,
AddressIndexPtr & addressIndex, AddressUnspentIndexPtr & addressUnspentIndex, SpentIndexPtr & spentIndex)
{
if(!input.IsZerocoinRemint())
return;

if (addressIndex) {
addressIndex->push_back(make_pair(CAddressIndexKey(AddressType::zerocoinRemint, uint160(), height, txNumber, txHash, inputNo, true), nValue * -1));
addressIndex->push_back(make_pair(CAddressIndexKey(AddressType::zerocoinRemint, uint160(), height, txNumber, txHash, 0, true), nValue * -1));
addressUnspentIndex->push_back(make_pair(CAddressUnspentKey(AddressType::zerocoinRemint, uint160(), input.prevout.hash, input.prevout.n), CAddressUnspentValue()));
}

if (spentIndex)
spentIndex->push_back(make_pair(CSpentIndexKey(input.prevout.hash, input.prevout.n), CSpentIndexValue(txHash, inputNo, height, nValue, AddressType::zerocoinRemint, uint160())));
spentIndex->push_back(make_pair(CSpentIndexKey(input.prevout.hash, input.prevout.n), CSpentIndexValue(txHash, 0, height, nValue, AddressType::zerocoinRemint, uint160())));
}


Expand Down Expand Up @@ -559,13 +559,16 @@ void CDbIndexHelper::ConnectTransaction(CTransaction const & tx, int height, int
}
}

no = 0;
if(tx.IsZerocoinRemint()) {
for (std::vector<CTxIn>::const_iterator iter = tx.vin.begin(); iter != tx.vin.end(); ++iter) {
CTxIn const & input = *iter;
handleRemint(input, no, tx.GetHash(), height, txNumber, tx.vout[no].nValue, addressIndex, addressUnspentIndex, spentIndex);
++no;
CAmount remintValue = 0;
for (std::vector<CTxOut>::const_iterator iter_out = tx.vout.begin(); iter_out != tx.vout.end(); ++iter_out) {
a-bezrukov marked this conversation as resolved.
Show resolved Hide resolved
remintValue += iter_out->nValue;
}
if (tx.vin.size() != 1) {
error("A Zerocoin to Sigma remint tx shoud have just 1 input");
return;
}
handleRemint(tx.vin[0], tx.GetHash(), height, txNumber, remintValue, addressIndex, addressUnspentIndex, spentIndex);
}

if(tx.IsZerocoinSpend() || tx.IsSigmaSpend())
Expand All @@ -592,17 +595,20 @@ void CDbIndexHelper::DisconnectTransactionInputs(CTransaction const & tx, int he
if(spentIndex)
pSpentBegin = spentIndex->size();

size_t no = 0;

if(tx.IsZerocoinRemint()) {
for (std::vector<CTxIn>::const_iterator iter = tx.vin.begin(); iter != tx.vin.end(); ++iter) {
CTxIn const & input = *iter;
handleRemint(input, no, tx.GetHash(), height, txNumber, tx.vout[no].nValue, addressIndex, addressUnspentIndex, spentIndex);
++no;
CAmount remintValue = 0;
for (std::vector<CTxOut>::const_iterator iter_out = tx.vout.begin(); iter_out != tx.vout.end(); ++iter_out) {
remintValue += iter_out->nValue;
}
if (tx.vin.size() != 1) {
error("A Zerocoin to Sigma remint tx shoud have just 1 input");
return;
}
handleRemint(tx.vin[0], tx.GetHash(), height, txNumber, remintValue, addressIndex, addressUnspentIndex, spentIndex);
}

no = 0;
size_t no = 0;

if(!tx.IsCoinBase() && !tx.IsZerocoinSpend() && !tx.IsSigmaSpend() && !tx.IsZerocoinRemint())
for (std::vector<CTxIn>::const_iterator iter = tx.vin.begin(); iter != tx.vin.end(); ++iter) {
CTxIn const & input = *iter;
Expand Down