Skip to content

Commit

Permalink
Exchange address index (firoorg#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 authored Jan 18, 2024
1 parent 3c5ac14 commit f3fe49c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/addresstype.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum struct AddressType
, sparkMint = 11
, sparksMint = 12
, sparkSpend = 13
, payToExchangeAddress = 14
};

namespace zerocoin { namespace utils {
Expand Down
4 changes: 4 additions & 0 deletions src/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ bool CBitcoinAddress::GetIndexKey(uint160& hashBytes, AddressType & type) const
memcpy(&hashBytes, &vchData[0], 20);
type = AddressType::payToPubKeyHash;
return true;
} else if (vchVersion == Params().Base58Prefix(CChainParams::EXCHANGE_PUBKEY_ADDRESS)) {
memcpy(&hashBytes, &vchData[0], 20);
type = AddressType::payToExchangeAddress;
return true;
} else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) {
memcpy(&hashBytes, &vchData[0], 20);
type = AddressType::payToScriptHash;
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ bool getAddressFromIndex(AddressType const & type, const uint160 &hash, std::str
{
if (type == AddressType::payToScriptHash) {
address = CBitcoinAddress(CScriptID(hash)).ToString();
} else if (type == AddressType::payToPubKeyHash) {
} else if (type == AddressType::payToPubKeyHash || type == AddressType::payToExchangeAddress) {
address = CBitcoinAddress(CKeyID(hash)).ToString();
} else {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ std::pair<AddressType, uint160> classifyAddress(txnouttype type, std::vector<std
} else if(type == TX_PUBKEYHASH) {
result.first = AddressType::payToPubKeyHash;
result.second = uint160(std::vector<unsigned char>(addresses.front().begin(), addresses.front().end()));
} else if(type == TX_EXCHANGEADDRESS) {
result.first = AddressType::payToExchangeAddress;
result.second = uint160(std::vector<unsigned char>(addresses.front().begin(), addresses.front().end()));
}
return result;
}
Expand Down
15 changes: 15 additions & 0 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n);
mapAddress.insert(std::make_pair(key, delta));
inserted.push_back(key);
} else if (prevout.scriptPubKey.IsPayToExchangeAddress()) {
std::vector<unsigned char> hashBytes(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23);
CMempoolAddressDeltaKey key(AddressType::payToExchangeAddress, uint160(hashBytes), txhash, j, 1);
CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n);
mapAddress.insert(std::make_pair(key, delta));
inserted.push_back(key);
}
}

Expand All @@ -693,6 +699,12 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
CMempoolAddressDeltaKey key(AddressType::payToPubKeyHash, uint160(hashBytes), txhash, k, 0);
mapAddress.insert(std::make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue)));
inserted.push_back(key);
} else if (out.scriptPubKey.IsPayToExchangeAddress()) {
std::vector<unsigned char> hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23);
std::pair<addressDeltaMap::iterator,bool> ret;
CMempoolAddressDeltaKey key(AddressType::payToExchangeAddress, uint160(hashBytes), txhash, k, 0);
mapAddress.insert(std::make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue)));
inserted.push_back(key);
}
}

Expand Down Expand Up @@ -753,6 +765,9 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac
} else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) {
addressHash = uint160(std::vector<unsigned char> (prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23));
addressType = AddressType::payToPubKeyHash;
} else if (prevout.scriptPubKey.IsPayToExchangeAddress()) {
addressHash = uint160(std::vector<unsigned char> (prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23));
addressType = AddressType::payToExchangeAddress;
} else {
addressHash.SetNull();
addressType = AddressType::unknown;
Expand Down

0 comments on commit f3fe49c

Please sign in to comment.