refactor: make AddressType a strong enum, remove uint8_t for address_type

Co-authored-by: Konstantin Akimov <knstqq@gmail.com>
This commit is contained in:
Kittywhiskers Van Gogh 2023-09-25 15:16:15 +07:00
parent c65a10f349
commit f011c31b1a
10 changed files with 56 additions and 55 deletions

View File

@ -24,7 +24,7 @@ inline std::vector<uint8_t> TrimScriptP2PK(const T1& input) {
return std::vector<uint8_t>(input.begin() + 1, input.end() - 1); return std::vector<uint8_t>(input.begin() + 1, input.end() - 1);
}; };
bool AddressBytesFromScript(const CScript& script, uint8_t& address_type, uint160& address_bytes) { bool AddressBytesFromScript(const CScript& script, AddressType& address_type, uint160& address_bytes) {
if (script.IsPayToScriptHash()) { if (script.IsPayToScriptHash()) {
address_type = AddressType::P2SH; address_type = AddressType::P2SH;
address_bytes = uint160(TrimScriptP2SH(script)); address_bytes = uint160(TrimScriptP2SH(script));

View File

@ -11,21 +11,21 @@
#include <amount.h> #include <amount.h>
#include <serialize.h> #include <serialize.h>
#include <uint256.h> #include <uint256.h>
#include <util/underlying.h>
#include <chrono> #include <chrono>
#include <tuple> #include <tuple>
class CScript; class CScript;
namespace AddressType { enum class AddressType : uint8_t {
enum AddressType {
P2PK = 1, P2PK = 1,
P2PKH = 1, P2PKH = 1,
P2SH = 2, P2SH = 2,
UNKNOWN = 0 UNKNOWN = 0
}; };
}; /* namespace AddressType */ template<> struct is_serializable_enum<AddressType> : std::true_type {};
struct CMempoolAddressDelta struct CMempoolAddressDelta
{ {
@ -46,21 +46,21 @@ public:
struct CMempoolAddressDeltaKey struct CMempoolAddressDeltaKey
{ {
public: public:
uint8_t m_address_type{AddressType::UNKNOWN}; AddressType m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes; uint160 m_address_bytes;
uint256 m_tx_hash; uint256 m_tx_hash;
uint32_t m_tx_index{0}; uint32_t m_tx_index{0};
bool m_tx_spent{false}; bool m_tx_spent{false};
public: public:
CMempoolAddressDeltaKey(uint8_t address_type, uint160 address_bytes, uint256 tx_hash, uint32_t tx_index, bool tx_spent) : CMempoolAddressDeltaKey(AddressType address_type, uint160 address_bytes, uint256 tx_hash, uint32_t tx_index, bool tx_spent) :
m_address_type{address_type}, m_address_type{address_type},
m_address_bytes{address_bytes}, m_address_bytes{address_bytes},
m_tx_hash{tx_hash}, m_tx_hash{tx_hash},
m_tx_index{tx_index}, m_tx_index{tx_index},
m_tx_spent{tx_spent} {}; m_tx_spent{tx_spent} {};
CMempoolAddressDeltaKey(uint8_t address_type, uint160 address_bytes) : CMempoolAddressDeltaKey(AddressType address_type, uint160 address_bytes) :
m_address_type{address_type}, m_address_type{address_type},
m_address_bytes{address_bytes} {}; m_address_bytes{address_bytes} {};
}; };
@ -77,7 +77,7 @@ struct CMempoolAddressDeltaKeyCompare
struct CAddressIndexKey { struct CAddressIndexKey {
public: public:
uint8_t m_address_type{AddressType::UNKNOWN}; AddressType m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes; uint160 m_address_bytes;
int32_t m_block_height{0}; int32_t m_block_height{0};
uint32_t m_block_tx_pos{0}; uint32_t m_block_tx_pos{0};
@ -90,7 +90,7 @@ public:
SetNull(); SetNull();
} }
CAddressIndexKey(uint8_t address_type, uint160 address_bytes, int32_t block_height, uint32_t block_tx_pos, uint256 tx_hash, CAddressIndexKey(AddressType address_type, uint160 address_bytes, int32_t block_height, uint32_t block_tx_pos, uint256 tx_hash,
uint32_t tx_index, bool tx_spent) : uint32_t tx_index, bool tx_spent) :
m_address_type{address_type}, m_address_type{address_type},
m_address_bytes{address_bytes}, m_address_bytes{address_bytes},
@ -117,7 +117,7 @@ public:
template<typename Stream> template<typename Stream>
void Serialize(Stream& s) const { void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type); ser_writedata8(s, ToUnderlying(m_address_type));
m_address_bytes.Serialize(s); m_address_bytes.Serialize(s);
// Heights are stored big-endian for key sorting in LevelDB // Heights are stored big-endian for key sorting in LevelDB
ser_writedata32be(s, m_block_height); ser_writedata32be(s, m_block_height);
@ -129,7 +129,7 @@ public:
template<typename Stream> template<typename Stream>
void Unserialize(Stream& s) { void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s); m_address_type = static_cast<AddressType>(ser_readdata8(s));
m_address_bytes.Unserialize(s); m_address_bytes.Unserialize(s);
m_block_height = ser_readdata32be(s); m_block_height = ser_readdata32be(s);
m_block_tx_pos = ser_readdata32be(s); m_block_tx_pos = ser_readdata32be(s);
@ -141,7 +141,7 @@ public:
struct CAddressIndexIteratorKey { struct CAddressIndexIteratorKey {
public: public:
uint8_t m_address_type{AddressType::UNKNOWN}; AddressType m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes; uint160 m_address_bytes;
public: public:
@ -149,7 +149,7 @@ public:
SetNull(); SetNull();
} }
CAddressIndexIteratorKey(uint8_t address_type, uint160 address_bytes) : CAddressIndexIteratorKey(AddressType address_type, uint160 address_bytes) :
m_address_type{address_type}, m_address_bytes{address_bytes} {}; m_address_type{address_type}, m_address_bytes{address_bytes} {};
void SetNull() { void SetNull() {
@ -164,20 +164,20 @@ public:
template<typename Stream> template<typename Stream>
void Serialize(Stream& s) const { void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type); ser_writedata8(s, ToUnderlying(m_address_type));
m_address_bytes.Serialize(s); m_address_bytes.Serialize(s);
} }
template<typename Stream> template<typename Stream>
void Unserialize(Stream& s) { void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s); m_address_type = static_cast<AddressType>(ser_readdata8(s));
m_address_bytes.Unserialize(s); m_address_bytes.Unserialize(s);
} }
}; };
struct CAddressIndexIteratorHeightKey { struct CAddressIndexIteratorHeightKey {
public: public:
uint8_t m_address_type{AddressType::UNKNOWN}; AddressType m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes; uint160 m_address_bytes;
int32_t m_block_height{0}; int32_t m_block_height{0};
@ -186,7 +186,7 @@ public:
SetNull(); SetNull();
} }
CAddressIndexIteratorHeightKey(uint8_t address_type, uint160 address_bytes, int32_t block_height) : CAddressIndexIteratorHeightKey(AddressType address_type, uint160 address_bytes, int32_t block_height) :
m_address_type{address_type}, m_address_bytes{address_bytes}, m_block_height{block_height} {}; m_address_type{address_type}, m_address_bytes{address_bytes}, m_block_height{block_height} {};
void SetNull() { void SetNull() {
@ -202,19 +202,19 @@ public:
template<typename Stream> template<typename Stream>
void Serialize(Stream& s) const { void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type); ser_writedata8(s, ToUnderlying(m_address_type));
m_address_bytes.Serialize(s); m_address_bytes.Serialize(s);
ser_writedata32be(s, m_block_height); ser_writedata32be(s, m_block_height);
} }
template<typename Stream> template<typename Stream>
void Unserialize(Stream& s) { void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s); m_address_type = static_cast<AddressType>(ser_readdata8(s));
m_address_bytes.Unserialize(s); m_address_bytes.Unserialize(s);
m_block_height = ser_readdata32be(s); m_block_height = ser_readdata32be(s);
} }
}; };
bool AddressBytesFromScript(const CScript& script, uint8_t& address_type, uint160& address_bytes); bool AddressBytesFromScript(const CScript& script, AddressType& address_type, uint160& address_bytes);
#endif // BITCOIN_ADDRESSINDEX_H #endif // BITCOIN_ADDRESSINDEX_H

View File

@ -4,6 +4,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <addressindex.h>
#include <chainparams.h> #include <chainparams.h>
#include <consensus/consensus.h> #include <consensus/consensus.h>
#include <evo/mnauth.h> #include <evo/mnauth.h>
@ -593,7 +594,7 @@ static UniValue mnauth(const JSONRPCRequest& request)
return fSuccess; return fSuccess;
} }
static bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address) static bool getAddressFromIndex(const AddressType& type, const uint160 &hash, std::string &address)
{ {
if (type == AddressType::P2SH) { if (type == AddressType::P2SH) {
address = EncodeDestination(ScriptHash(hash)); address = EncodeDestination(ScriptHash(hash));
@ -605,7 +606,7 @@ static bool getAddressFromIndex(const int &type, const uint160 &hash, std::strin
return true; return true;
} }
static bool getIndexKey(const std::string& str, uint160& hashBytes, int& type) static bool getIndexKey(const std::string& str, uint160& hashBytes, AddressType& type)
{ {
CTxDestination dest = DecodeDestination(str); CTxDestination dest = DecodeDestination(str);
if (!IsValidDestination(dest)) { if (!IsValidDestination(dest)) {
@ -619,11 +620,11 @@ static bool getIndexKey(const std::string& str, uint160& hashBytes, int& type)
return true; return true;
} }
static bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint160, int> > &addresses) static bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint160, AddressType> > &addresses)
{ {
if (params[0].isStr()) { if (params[0].isStr()) {
uint160 hashBytes; uint160 hashBytes;
int type{AddressType::UNKNOWN}; AddressType type{AddressType::UNKNOWN};
if (!getIndexKey(params[0].get_str(), hashBytes, type)) { if (!getIndexKey(params[0].get_str(), hashBytes, type)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
} }
@ -637,7 +638,7 @@ static bool getAddressesFromParams(const UniValue& params, std::vector<std::pair
for (const auto& address : addressValues.getValues()) { for (const auto& address : addressValues.getValues()) {
uint160 hashBytes; uint160 hashBytes;
int type{AddressType::UNKNOWN}; AddressType type{AddressType::UNKNOWN};
if (!getIndexKey(address.get_str(), hashBytes, type)) { if (!getIndexKey(address.get_str(), hashBytes, type)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
} }
@ -691,7 +692,7 @@ static UniValue getaddressmempool(const JSONRPCRequest& request)
}, },
}.Check(request); }.Check(request);
std::vector<std::pair<uint160, int> > addresses; std::vector<std::pair<uint160, AddressType> > addresses;
if (!getAddressesFromParams(request.params, addresses)) { if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
@ -760,7 +761,7 @@ static UniValue getaddressutxos(const JSONRPCRequest& request)
}, },
}.Check(request); }.Check(request);
std::vector<std::pair<uint160, int> > addresses; std::vector<std::pair<uint160, AddressType> > addresses;
if (!getAddressesFromParams(request.params, addresses)) { if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
@ -842,7 +843,7 @@ static UniValue getaddressdeltas(const JSONRPCRequest& request)
} }
} }
std::vector<std::pair<uint160, int> > addresses; std::vector<std::pair<uint160, AddressType> > addresses;
if (!getAddressesFromParams(request.params, addresses)) { if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
@ -908,7 +909,7 @@ static UniValue getaddressbalance(const JSONRPCRequest& request)
}, },
}.Check(request); }.Check(request);
std::vector<std::pair<uint160, int> > addresses; std::vector<std::pair<uint160, AddressType> > addresses;
if (!getAddressesFromParams(request.params, addresses)) { if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
@ -973,7 +974,7 @@ static UniValue getaddresstxids(const JSONRPCRequest& request)
}, },
}.Check(request); }.Check(request);
std::vector<std::pair<uint160, int> > addresses; std::vector<std::pair<uint160, AddressType> > addresses;
if (!getAddressesFromParams(request.params, addresses)) { if (!getAddressesFromParams(request.params, addresses)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");

View File

@ -47,7 +47,7 @@ public:
uint32_t m_tx_index{0}; uint32_t m_tx_index{0};
int32_t m_block_height{0}; int32_t m_block_height{0};
CAmount m_amount{0}; CAmount m_amount{0};
uint8_t m_address_type{AddressType::UNKNOWN}; AddressType m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes; uint160 m_address_bytes;
public: public:
@ -55,7 +55,7 @@ public:
SetNull(); SetNull();
} }
CSpentIndexValue(uint256 txin_hash, uint32_t txin_index, int32_t block_height, CAmount amount, uint8_t address_type, CSpentIndexValue(uint256 txin_hash, uint32_t txin_index, int32_t block_height, CAmount amount, AddressType address_type,
uint160 address_bytes) : uint160 address_bytes) :
m_tx_hash{txin_hash}, m_tx_hash{txin_hash},
m_tx_index{txin_index}, m_tx_index{txin_index},
@ -101,7 +101,7 @@ struct CSpentIndexTxInfo
struct CAddressUnspentKey { struct CAddressUnspentKey {
public: public:
uint8_t m_address_type{AddressType::UNKNOWN}; AddressType m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes; uint160 m_address_bytes;
uint256 m_tx_hash; uint256 m_tx_hash;
uint32_t m_tx_index{0}; uint32_t m_tx_index{0};
@ -111,7 +111,7 @@ public:
SetNull(); SetNull();
} }
CAddressUnspentKey(uint8_t address_type, uint160 address_bytes, uint256 tx_hash, uint32_t tx_index) : CAddressUnspentKey(AddressType address_type, uint160 address_bytes, uint256 tx_hash, uint32_t tx_index) :
m_address_type{address_type}, m_address_bytes{address_bytes}, m_tx_hash{tx_hash}, m_tx_index{tx_index} {}; m_address_type{address_type}, m_address_bytes{address_bytes}, m_tx_hash{tx_hash}, m_tx_index{tx_index} {};
void SetNull() { void SetNull() {
@ -128,7 +128,7 @@ public:
template<typename Stream> template<typename Stream>
void Serialize(Stream& s) const { void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type); ser_writedata8(s, ToUnderlying(m_address_type));
m_address_bytes.Serialize(s); m_address_bytes.Serialize(s);
m_tx_hash.Serialize(s); m_tx_hash.Serialize(s);
ser_writedata32(s, m_tx_index); ser_writedata32(s, m_tx_index);
@ -136,7 +136,7 @@ public:
template<typename Stream> template<typename Stream>
void Unserialize(Stream& s) { void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s); m_address_type = static_cast<AddressType>(ser_readdata8(s));
m_address_bytes.Unserialize(s); m_address_bytes.Unserialize(s);
m_tx_hash.Unserialize(s); m_tx_hash.Unserialize(s);
m_tx_index = ser_readdata32(s); m_tx_index = ser_readdata32(s);

View File

@ -266,7 +266,7 @@ bool CBlockTreeDB::UpdateAddressUnspentIndex(const std::vector<std::pair<CAddres
return WriteBatch(batch); return WriteBatch(batch);
} }
bool CBlockTreeDB::ReadAddressUnspentIndex(uint160 addressHash, int type, bool CBlockTreeDB::ReadAddressUnspentIndex(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs) { std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs) {
std::unique_ptr<CDBIterator> pcursor(NewIterator()); std::unique_ptr<CDBIterator> pcursor(NewIterator());
@ -305,7 +305,7 @@ bool CBlockTreeDB::EraseAddressIndex(const std::vector<std::pair<CAddressIndexKe
return WriteBatch(batch); return WriteBatch(batch);
} }
bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex, std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
int start, int end) { int start, int end) {

View File

@ -109,11 +109,11 @@ public:
bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value); bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
bool UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> >&vect); bool UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> >&vect);
bool UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue > >&vect); bool UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue > >&vect);
bool ReadAddressUnspentIndex(uint160 addressHash, int type, bool ReadAddressUnspentIndex(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &vect); std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &vect);
bool WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect); bool WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
bool EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect); bool EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
bool ReadAddressIndex(uint160 addressHash, int type, bool ReadAddressIndex(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex, std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
int start = 0, int end = 0); int start = 0, int end = 0);
bool WriteTimestampIndex(const CTimestampIndexKey &timestampIndex); bool WriteTimestampIndex(const CTimestampIndexKey &timestampIndex);

View File

@ -475,7 +475,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
const Coin& coin = view.AccessCoin(input.prevout); const Coin& coin = view.AccessCoin(input.prevout);
const CTxOut &prevout = coin.out; const CTxOut &prevout = coin.out;
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
if (!AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes)) { if (!AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes)) {
@ -491,7 +491,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
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];
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) { if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) {
@ -506,7 +506,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
mapAddressInserted.insert(std::make_pair(txhash, inserted)); mapAddressInserted.insert(std::make_pair(txhash, inserted));
} }
bool CTxMemPool::getAddressIndex(std::vector<std::pair<uint160, int> > &addresses, bool CTxMemPool::getAddressIndex(std::vector<std::pair<uint160, AddressType> > &addresses,
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results) std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results)
{ {
LOCK(cs); LOCK(cs);
@ -549,7 +549,7 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac
const Coin& coin = view.AccessCoin(input.prevout); const Coin& coin = view.AccessCoin(input.prevout);
const CTxOut &prevout = coin.out; const CTxOut &prevout = coin.out;
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
if (!AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes)) { if (!AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes)) {

View File

@ -603,7 +603,7 @@ public:
void addUnchecked(const CTxMemPoolEntry& entry, setEntries& setAncestors, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main); void addUnchecked(const CTxMemPoolEntry& entry, setEntries& setAncestors, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view); void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses, bool getAddressIndex(std::vector<std::pair<uint160, AddressType> > &addresses,
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results); std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
bool removeAddressIndex(const uint256 txhash); bool removeAddressIndex(const uint256 txhash);

View File

@ -1037,7 +1037,7 @@ bool GetSpentIndex(CTxMemPool& mempool, CSpentIndexKey &key, CSpentIndexValue &v
return true; return true;
} }
bool GetAddressIndex(uint160 addressHash, int type, bool GetAddressIndex(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex, int start, int end) std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex, int start, int end)
{ {
if (!fAddressIndex) if (!fAddressIndex)
@ -1049,7 +1049,7 @@ bool GetAddressIndex(uint160 addressHash, int type,
return true; return true;
} }
bool GetAddressUnspent(uint160 addressHash, int type, bool GetAddressUnspent(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs) std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs)
{ {
if (!fAddressIndex) if (!fAddressIndex)
@ -1706,7 +1706,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
for (unsigned int k = tx.vout.size(); k-- > 0;) { for (unsigned int k = tx.vout.size(); k-- > 0;) {
const CTxOut &out = tx.vout[k]; const CTxOut &out = tx.vout[k];
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) { if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) {
@ -1759,7 +1759,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
const Coin &coin = view.AccessCoin(tx.vin[j].prevout); const Coin &coin = view.AccessCoin(tx.vin[j].prevout);
const CTxOut &prevout = coin.out; const CTxOut &prevout = coin.out;
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
if (!AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes)) { if (!AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes)) {
@ -2224,7 +2224,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
const Coin& coin = view.AccessCoin(tx.vin[j].prevout); const Coin& coin = view.AccessCoin(tx.vin[j].prevout);
const CTxOut &prevout = coin.out; const CTxOut &prevout = coin.out;
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes); AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes);
@ -2278,7 +2278,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
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];
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) { if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) {
@ -4805,7 +4805,7 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
const Coin& coin = inputs.AccessCoin(tx->vin[j].prevout); const Coin& coin = inputs.AccessCoin(tx->vin[j].prevout);
const CTxOut& prevout = coin.out; const CTxOut& prevout = coin.out;
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes); AddressBytesFromScript(prevout.scriptPubKey, address_type, address_bytes);
@ -4830,7 +4830,7 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
for (size_t k = 0; k < tx->vout.size(); k++) { for (size_t k = 0; k < tx->vout.size(); k++) {
const CTxOut& out = tx->vout[k]; const CTxOut& out = tx->vout[k];
uint8_t address_type{0}; AddressType address_type{AddressType::UNKNOWN};
uint160 address_bytes; uint160 address_bytes;
if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) { if (!AddressBytesFromScript(out.scriptPubKey, address_type, address_bytes)) {

View File

@ -307,10 +307,10 @@ public:
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &hashes); bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &hashes);
bool GetSpentIndex(CTxMemPool& mempool, CSpentIndexKey &key, CSpentIndexValue &value); bool GetSpentIndex(CTxMemPool& mempool, CSpentIndexKey &key, CSpentIndexValue &value);
bool GetAddressIndex(uint160 addressHash, int type, bool GetAddressIndex(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex, std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
int start = 0, int end = 0); int start = 0, int end = 0);
bool GetAddressUnspent(uint160 addressHash, int type, bool GetAddressUnspent(uint160 addressHash, AddressType type,
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs); std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
/** Initializes the script-execution cache */ /** Initializes the script-execution cache */
void InitScriptExecutionCache(); void InitScriptExecutionCache();