diff --git a/src/main.cpp b/src/main.cpp index ccdeee6ff..1350240b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2475,6 +2475,16 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // undo unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), hash, k), CAddressUnspentValue())); + } + else if (out.scriptPubKey.IsPayToCryptoCondition()) { + vector 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 { continue; @@ -2560,6 +2570,16 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // 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 if (prevout.scriptPubKey.IsPayToCryptoCondition()) { + vector 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 { continue; @@ -2843,6 +2863,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin hashBytes = Hash160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); addressType = 1; } + else if (prevout.scriptPubKey.IsPayToCryptoCondition()) { + hashBytes = Hash160(vector (prevout.scriptPubKey.begin(), prevout.scriptPubKey.end())); + addressType = 1; + } else { hashBytes.SetNull(); addressType = 0; @@ -2919,6 +2943,16 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // record unspent output addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); + } + else if (out.scriptPubKey.IsPayToCryptoCondition()) { + vector 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 { continue; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 7f8984c63..2e5ed0be8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -210,7 +210,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); 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; if (ExtractDestination(out.scriptPubKey, address)) { diff --git a/src/txmempool.cpp b/src/txmempool.cpp index e96f0d975..296c0eef5 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -152,7 +152,13 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC mapAddress.insert(make_pair(key, delta)); inserted.push_back(key); } - } + else if (prevout.scriptPubKey.IsPayToCryptoCondition()) { + vector 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++) { 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))); inserted.push_back(key); } + else if (out.scriptPubKey.IsPayToCryptoCondition()) { + vector hashBytes(out.scriptPubKey.begin(), out.scriptPubKey.end()); + std::pair 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)); @@ -237,6 +250,10 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac addressHash = Hash160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); addressType = 1; } + else if (prevout.scriptPubKey.IsPayToCryptoCondition()) { + addressHash = Hash160(vector (prevout.scriptPubKey.begin(), prevout.scriptPubKey.end())); + addressType = 1; + } else { addressHash.SetNull(); addressType = 0;