fix address type

This commit is contained in:
blackjok3r
2019-04-12 17:35:40 +08:00
parent b33d2342a1
commit 8bb5f9abd5
5 changed files with 12 additions and 12 deletions

View File

@@ -296,13 +296,13 @@ CTxDestination CBitcoinAddress::Get() const
return CNoDestination();
}
bool CBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type) const
bool CBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const
{
if (!IsValid()) {
return false;
} else if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) {
memcpy(&hashBytes, &vchData[0], 20);
type = 1;
ccflag ? type = 3 : type = 1;
return true;
} else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) {
memcpy(&hashBytes, &vchData[0], 20);
@@ -392,13 +392,13 @@ CTxDestination CCustomBitcoinAddress::Get() const
return CNoDestination();
}
bool CCustomBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type) const
bool CCustomBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const
{
if (!IsValid()) {
return false;
} else if (vchVersion == base58Prefixes[0]) {
memcpy(&hashBytes, &vchData[0], 20);
type = 1;
ccflag ? type = 3 : type = 1;
return true;
} else if (vchVersion == base58Prefixes[1]) {
memcpy(&hashBytes, &vchData[0], 20);

View File

@@ -147,7 +147,7 @@ public:
CTxDestination Get() const;
bool GetKeyID(CKeyID &keyID) const;
bool GetKeyID_NoCheck(CKeyID& keyID) const;
bool GetIndexKey(uint160& hashBytes, int& type) const;
bool GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const;
bool IsScript() const;
};
@@ -172,7 +172,7 @@ public:
CTxDestination Get() const;
bool GetKeyID(CKeyID &keyID) const;
bool GetKeyID_NoCheck(CKeyID& keyID) const;
bool GetIndexKey(uint160& hashBytes, int& type) const;
bool GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const;
bool IsScript() const;
};

View File

@@ -315,7 +315,7 @@ void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValu
for (i=0; i<=n; i++)
ptr[i] = coinaddr[i];
CBitcoinAddress address(addrstr);
if ( address.GetIndexKey(hashBytes, type) == 0 )
if ( address.GetIndexKey(hashBytes, type, ccflag) == 0 )
return;
addresses.push_back(std::make_pair(hashBytes,type));
for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++)
@@ -334,7 +334,7 @@ void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex
for (i=0; i<=n; i++)
ptr[i] = coinaddr[i];
CBitcoinAddress address(addrstr);
if ( address.GetIndexKey(hashBytes, type) == 0 )
if ( address.GetIndexKey(hashBytes, type, ccflag) == 0 )
return;
addresses.push_back(std::make_pair(hashBytes,type));
for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++)

View File

@@ -867,7 +867,7 @@ bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint16
CBitcoinAddress address(params[0].get_str());
uint160 hashBytes;
int type = 0;
if (!address.GetIndexKey(hashBytes, type)) {
if (!address.GetIndexKey(hashBytes, type, 0)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}
addresses.push_back(std::make_pair(hashBytes, type));
@@ -885,7 +885,7 @@ bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint16
CBitcoinAddress address(it->get_str());
uint160 hashBytes;
int type = 0;
if (!address.GetIndexKey(hashBytes, type)) {
if (!address.GetIndexKey(hashBytes, type, 0)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid addresses");
}
addresses.push_back(std::make_pair(hashBytes, type));

View File

@@ -160,7 +160,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
if (vDest.which())
{
uint160 hashBytes;
if (CBitcoinAddress(vDest).GetIndexKey(hashBytes, keyType))
if (CBitcoinAddress(vDest).GetIndexKey(hashBytes, keyType, prevout.scriptPubKey.IsPayToCryptoCondition()))
{
vSols.push_back(vector<unsigned char>(hashBytes.begin(), hashBytes.end()));
}
@@ -192,7 +192,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
if (vDest.which())
{
uint160 hashBytes;
if (CBitcoinAddress(vDest).GetIndexKey(hashBytes, keyType))
if (CBitcoinAddress(vDest).GetIndexKey(hashBytes, keyType, out.scriptPubKey.IsPayToCryptoCondition()))
{
vSols.push_back(vector<unsigned char>(hashBytes.begin(), hashBytes.end()));
}