Support IsPayToCryptoCondition for -addressindex
This commit is contained in:
34
src/main.cpp
34
src/main.cpp
@@ -2475,6 +2475,16 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
|
|||||||
// undo unspent index
|
// undo unspent index
|
||||||
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), hash, k), CAddressUnspentValue()));
|
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), hash, k), CAddressUnspentValue()));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (out.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
|
vector<unsigned char> hashBytes(out.scriptPubKey.begin(), out.scriptPubKey.end());
|
||||||
|
|
||||||
|
// undo receiving activity
|
||||||
|
addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue));
|
||||||
|
|
||||||
|
// undo unspent index
|
||||||
|
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), hash, k), CAddressUnspentValue()));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
@@ -2560,6 +2570,16 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
|
|||||||
// restore unspent index
|
// restore unspent index
|
||||||
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight)));
|
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight)));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (prevout.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
|
vector<unsigned char> hashBytes(prevout.scriptPubKey.begin(), prevout.scriptPubKey.end());
|
||||||
|
|
||||||
|
// undo spending activity
|
||||||
|
addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1));
|
||||||
|
|
||||||
|
// restore unspent index
|
||||||
|
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight)));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
@@ -2843,6 +2863,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
hashBytes = Hash160(vector <unsigned char>(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34));
|
hashBytes = Hash160(vector <unsigned char>(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34));
|
||||||
addressType = 1;
|
addressType = 1;
|
||||||
}
|
}
|
||||||
|
else if (prevout.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
|
hashBytes = Hash160(vector <unsigned char>(prevout.scriptPubKey.begin(), prevout.scriptPubKey.end()));
|
||||||
|
addressType = 1;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
hashBytes.SetNull();
|
hashBytes.SetNull();
|
||||||
addressType = 0;
|
addressType = 0;
|
||||||
@@ -2919,6 +2943,16 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
// record unspent output
|
// record unspent output
|
||||||
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight)));
|
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight)));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (out.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
|
vector<unsigned char> hashBytes(out.scriptPubKey.begin(), out.scriptPubKey.end());
|
||||||
|
|
||||||
|
// record receiving activity
|
||||||
|
addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue));
|
||||||
|
|
||||||
|
// record unspent output
|
||||||
|
addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight)));
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
|
|||||||
vector<unsigned char> hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23);
|
vector<unsigned char> hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23);
|
||||||
delta.push_back(Pair("address", CBitcoinAddress(CKeyID(uint160(hashBytes))).ToString()));
|
delta.push_back(Pair("address", CBitcoinAddress(CKeyID(uint160(hashBytes))).ToString()));
|
||||||
}
|
}
|
||||||
else if (out.scriptPubKey.IsPayToPublicKey()) {
|
else if (out.scriptPubKey.IsPayToPublicKey() || out.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
CTxDestination address;
|
CTxDestination address;
|
||||||
if (ExtractDestination(out.scriptPubKey, address))
|
if (ExtractDestination(out.scriptPubKey, address))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -152,7 +152,13 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
|
|||||||
mapAddress.insert(make_pair(key, delta));
|
mapAddress.insert(make_pair(key, delta));
|
||||||
inserted.push_back(key);
|
inserted.push_back(key);
|
||||||
}
|
}
|
||||||
}
|
else if (prevout.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
|
vector<unsigned char> hashBytes(prevout.scriptPubKey.begin(), prevout.scriptPubKey.end());
|
||||||
|
CMempoolAddressDeltaKey key(1, Hash160(hashBytes), txhash, j, 1);
|
||||||
|
CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n);
|
||||||
|
mapAddress.insert(make_pair(key, delta));
|
||||||
|
inserted.push_back(key);
|
||||||
|
} }
|
||||||
|
|
||||||
for (unsigned int k = 0; k < tx.vout.size(); k++) {
|
for (unsigned int k = 0; k < tx.vout.size(); k++) {
|
||||||
const CTxOut &out = tx.vout[k];
|
const CTxOut &out = tx.vout[k];
|
||||||
@@ -176,6 +182,13 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
|
|||||||
mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue)));
|
mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue)));
|
||||||
inserted.push_back(key);
|
inserted.push_back(key);
|
||||||
}
|
}
|
||||||
|
else if (out.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
|
vector<unsigned char> hashBytes(out.scriptPubKey.begin(), out.scriptPubKey.end());
|
||||||
|
std::pair<addressDeltaMap::iterator,bool> ret;
|
||||||
|
CMempoolAddressDeltaKey key(1, Hash160(hashBytes), txhash, k, 0);
|
||||||
|
mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue)));
|
||||||
|
inserted.push_back(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mapAddressInserted.insert(make_pair(txhash, inserted));
|
mapAddressInserted.insert(make_pair(txhash, inserted));
|
||||||
@@ -237,6 +250,10 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac
|
|||||||
addressHash = Hash160(vector<unsigned char> (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34));
|
addressHash = Hash160(vector<unsigned char> (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34));
|
||||||
addressType = 1;
|
addressType = 1;
|
||||||
}
|
}
|
||||||
|
else if (prevout.scriptPubKey.IsPayToCryptoCondition()) {
|
||||||
|
addressHash = Hash160(vector<unsigned char> (prevout.scriptPubKey.begin(), prevout.scriptPubKey.end()));
|
||||||
|
addressType = 1;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
addressHash.SetNull();
|
addressHash.SetNull();
|
||||||
addressType = 0;
|
addressType = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user