From 8bb5f9abd52b1ceac1dbf231f68b13ee3d45f482 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 12 Apr 2019 17:35:40 +0800 Subject: [PATCH] fix address type --- src/base58.cpp | 8 ++++---- src/base58.h | 4 ++-- src/cc/CCtx.cpp | 4 ++-- src/rpc/misc.cpp | 4 ++-- src/txmempool.cpp | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/base58.cpp b/src/base58.cpp index 33b43d745..383666d82 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -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); diff --git a/src/base58.h b/src/base58.h index 52b3ac5f3..8be0247e0 100644 --- a/src/base58.h +++ b/src/base58.h @@ -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; }; diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5e8a05895..7435defbf 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -315,7 +315,7 @@ void SetCCunspents(std::vector >::iterator it = addresses.begin(); it != addresses.end(); it++) @@ -334,7 +334,7 @@ void SetCCtxids(std::vector > &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 >::iterator it = addresses.begin(); it != addresses.end(); it++) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index cf7c85417..a77788fd7 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -867,7 +867,7 @@ bool getAddressesFromParams(const UniValue& params, std::vectorget_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)); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index f57860c76..2b38d7153 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -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(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(hashBytes.begin(), hashBytes.end())); }