mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 05:23:01 +01:00
main: add amount and address to spentindex value
This commit is contained in:
parent
87dfd13694
commit
16d35eb228
51
src/main.cpp
51
src/main.cpp
@ -2492,40 +2492,37 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
for (size_t j = 0; j < tx.vin.size(); j++) {
|
for (size_t j = 0; j < tx.vin.size(); j++) {
|
||||||
|
|
||||||
const CTxIn input = tx.vin[j];
|
const CTxIn input = tx.vin[j];
|
||||||
|
const CTxOut &prevout = view.GetOutputFor(tx.vin[j]);
|
||||||
|
uint160 hashBytes;
|
||||||
|
int addressType;
|
||||||
|
|
||||||
|
if (prevout.scriptPubKey.IsPayToScriptHash()) {
|
||||||
|
hashBytes = uint160(vector <unsigned char>(prevout.scriptPubKey.begin()+2, prevout.scriptPubKey.begin()+22));
|
||||||
|
addressType = 2;
|
||||||
|
} else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) {
|
||||||
|
hashBytes = uint160(vector <unsigned char>(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23));
|
||||||
|
addressType = 1;
|
||||||
|
} else {
|
||||||
|
hashBytes.SetNull();
|
||||||
|
addressType = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fAddressIndex && addressType > 0) {
|
||||||
|
// record spending activity
|
||||||
|
addressIndex.push_back(make_pair(CAddressIndexKey(addressType, hashBytes, pindex->nHeight, i, txhash, j, true), prevout.nValue * -1));
|
||||||
|
|
||||||
|
// remove address from unspent index
|
||||||
|
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(addressType, hashBytes, input.prevout.hash, input.prevout.n), CAddressUnspentValue()));
|
||||||
|
}
|
||||||
|
|
||||||
if (fSpentIndex) {
|
if (fSpentIndex) {
|
||||||
// add the spent index to determine the txid and input that spent an output
|
// add the spent index to determine the txid and input that spent an output
|
||||||
spentIndex.push_back(make_pair(CSpentIndexKey(input.prevout.hash, input.prevout.n), CSpentIndexValue(txhash, j, pindex->nHeight)));
|
// and to find the amount and address from an input
|
||||||
}
|
spentIndex.push_back(make_pair(CSpentIndexKey(input.prevout.hash, input.prevout.n), CSpentIndexValue(txhash, j, pindex->nHeight, prevout.nValue, addressType, hashBytes)));
|
||||||
|
|
||||||
if (fAddressIndex) {
|
|
||||||
|
|
||||||
const CTxOut &prevout = view.GetOutputFor(tx.vin[j]);
|
|
||||||
|
|
||||||
if (prevout.scriptPubKey.IsPayToScriptHash()) {
|
|
||||||
vector<unsigned char> hashBytes(prevout.scriptPubKey.begin()+2, prevout.scriptPubKey.begin()+22);
|
|
||||||
|
|
||||||
// record spending activity
|
|
||||||
addressIndex.push_back(make_pair(CAddressIndexKey(2, uint160(hashBytes), pindex->nHeight, i, txhash, j, true), prevout.nValue * -1));
|
|
||||||
|
|
||||||
// remove address from unspent index
|
|
||||||
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(2, uint160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue()));
|
|
||||||
} else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) {
|
|
||||||
vector<unsigned char> hashBytes(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23);
|
|
||||||
|
|
||||||
// record spending activity
|
|
||||||
addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, txhash, j, true), prevout.nValue * -1));
|
|
||||||
|
|
||||||
// remove address from unspent index
|
|
||||||
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, uint160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue()));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (fStrictPayToScriptHash)
|
if (fStrictPayToScriptHash)
|
||||||
{
|
{
|
||||||
|
14
src/main.h
14
src/main.h
@ -325,6 +325,9 @@ struct CSpentIndexValue {
|
|||||||
uint256 txid;
|
uint256 txid;
|
||||||
unsigned int inputIndex;
|
unsigned int inputIndex;
|
||||||
int blockHeight;
|
int blockHeight;
|
||||||
|
CAmount satoshis;
|
||||||
|
int addressType;
|
||||||
|
uint160 addressHash;
|
||||||
|
|
||||||
ADD_SERIALIZE_METHODS;
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
@ -333,12 +336,18 @@ struct CSpentIndexValue {
|
|||||||
READWRITE(txid);
|
READWRITE(txid);
|
||||||
READWRITE(inputIndex);
|
READWRITE(inputIndex);
|
||||||
READWRITE(blockHeight);
|
READWRITE(blockHeight);
|
||||||
|
READWRITE(satoshis);
|
||||||
|
READWRITE(addressType);
|
||||||
|
READWRITE(addressHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSpentIndexValue(uint256 t, unsigned int i, int h) {
|
CSpentIndexValue(uint256 t, unsigned int i, int h, CAmount s, int type, uint160 a) {
|
||||||
txid = t;
|
txid = t;
|
||||||
inputIndex = i;
|
inputIndex = i;
|
||||||
blockHeight = h;
|
blockHeight = h;
|
||||||
|
satoshis = s;
|
||||||
|
addressType = type;
|
||||||
|
addressHash = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSpentIndexValue() {
|
CSpentIndexValue() {
|
||||||
@ -349,6 +358,9 @@ struct CSpentIndexValue {
|
|||||||
txid.SetNull();
|
txid.SetNull();
|
||||||
inputIndex = 0;
|
inputIndex = 0;
|
||||||
blockHeight = 0;
|
blockHeight = 0;
|
||||||
|
satoshis = 0;
|
||||||
|
addressType = 0;
|
||||||
|
addressHash.SetNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsNull() const {
|
bool IsNull() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user