diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index 59837f783..0ffbcffd7 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -145,7 +145,7 @@ class AddressIndexTest(BitcoinTestFramework): tx.vin = [CTxIn(COutPoint(int(spending_txid, 16), 0))] send_amount = 1 * 100000000 + 12840 change_amount = amount - send_amount - 10000 - tx.vout = [CTxOut(send_amount, scriptPubKey), CTxOut(change_amount, scriptPubKey2)] + tx.vout = [CTxOut(change_amount, scriptPubKey2), CTxOut(send_amount, scriptPubKey)] tx.rehash() signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8")) diff --git a/src/main.cpp b/src/main.cpp index 7a2619f6f..f7b2af8ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2527,10 +2527,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin const CTxOut &prevout = view.GetOutputFor(tx.vin[j]); if (prevout.scriptPubKey.IsPayToScriptHash()) { vector hashBytes(prevout.scriptPubKey.begin()+2, prevout.scriptPubKey.begin()+22); - addressIndex.push_back(make_pair(CAddressIndexKey(2, uint160(hashBytes), pindex->nHeight, i, txhash, j), prevout.nValue * -1)); + addressIndex.push_back(make_pair(CAddressIndexKey(2, uint160(hashBytes), pindex->nHeight, i, txhash, j, true), prevout.nValue * -1)); } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { vector hashBytes(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23); - addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, txhash, j), prevout.nValue * -1)); + addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, txhash, j, true), prevout.nValue * -1)); } else { continue; } @@ -2564,10 +2564,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (out.scriptPubKey.IsPayToScriptHash()) { vector hashBytes(out.scriptPubKey.begin()+2, out.scriptPubKey.begin()+22); - addressIndex.push_back(make_pair(CAddressIndexKey(2, uint160(hashBytes), pindex->nHeight, i, txhash, k), out.nValue)); + addressIndex.push_back(make_pair(CAddressIndexKey(2, uint160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); - addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, txhash, k), out.nValue)); + addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); } else { continue; } diff --git a/src/main.h b/src/main.h index 11f89b922..90fce90d3 100644 --- a/src/main.h +++ b/src/main.h @@ -338,6 +338,7 @@ struct CAddressIndexKey { unsigned int txindex; uint256 txhash; size_t outindex; + bool spending; size_t GetSerializeSize(int nType, int nVersion) const { return 65; @@ -351,6 +352,8 @@ struct CAddressIndexKey { ser_writedata32be(s, txindex); txhash.Serialize(s, nType, nVersion); ser_writedata32(s, outindex); + char f = spending; + ser_writedata8(s, f); } template void Unserialize(Stream& s, int nType, int nVersion) { @@ -360,16 +363,19 @@ struct CAddressIndexKey { txindex = ser_readdata32be(s); txhash.Unserialize(s, nType, nVersion); outindex = ser_readdata32(s); + char f = ser_readdata8(s); + spending = f; } CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex, - uint256 txid, size_t outputIndex) { + uint256 txid, size_t outputIndex, bool isSpending) { type = addressType; hashBytes = addressHash; blockHeight = height; txindex = blockindex; txhash = txid; outindex = outputIndex; + spending = isSpending; } CAddressIndexKey() { @@ -383,6 +389,7 @@ struct CAddressIndexKey { txindex = 0; txhash.SetNull(); outindex = 0; + spending = false; } };