Skip to content

Commit 3eb825c

Browse files
committed
Move GetIndexKey into rpc/misc.cpp near getAddressesFromParams
No need to have it in base58.cpp anymore as this is only used in getAddressesFromParams
1 parent 5ff8d38 commit 3eb825c

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/base58.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,3 @@ bool IsValidDestinationString(const std::string& str)
359359
return CBitcoinAddress(str).IsValid();
360360
}
361361

362-
bool GetIndexKey(const std::string& str, uint160& hashBytes, int& type)
363-
{
364-
CTxDestination dest = DecodeDestination(str);
365-
if (!IsValidDestination(dest)) {
366-
type = 0;
367-
return false;
368-
}
369-
const CKeyID *keyID = boost::get<CKeyID>(&dest);
370-
const CScriptID *scriptID = boost::get<CScriptID>(&dest);
371-
type = keyID ? 1 : 2;
372-
hashBytes = keyID ? *keyID : *scriptID;
373-
return true;
374-
}

src/base58.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,4 @@ CTxDestination DecodeDestination(const std::string& str);
148148
bool IsValidDestinationString(const std::string& str);
149149
bool IsValidDestinationString(const std::string& str, const CChainParams& params);
150150

151-
bool GetIndexKey(const std::string& str, uint160& hashBytes, int& type);
152-
153151
#endif // BITCOIN_BASE58_H

src/rpc/misc.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,26 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr
665665
return true;
666666
}
667667

668+
bool getIndexKey(const std::string& str, uint160& hashBytes, int& type)
669+
{
670+
CTxDestination dest = DecodeDestination(str);
671+
if (!IsValidDestination(dest)) {
672+
type = 0;
673+
return false;
674+
}
675+
const CKeyID *keyID = boost::get<CKeyID>(&dest);
676+
const CScriptID *scriptID = boost::get<CScriptID>(&dest);
677+
type = keyID ? 1 : 2;
678+
hashBytes = keyID ? *keyID : *scriptID;
679+
return true;
680+
}
681+
668682
bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint160, int> > &addresses)
669683
{
670684
if (params[0].isStr()) {
671685
uint160 hashBytes;
672686
int type = 0;
673-
if (!GetIndexKey(params[0].get_str(), hashBytes, type)) {
687+
if (!getIndexKey(params[0].get_str(), hashBytes, type)) {
674688
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
675689
}
676690
addresses.push_back(std::make_pair(hashBytes, type));
@@ -687,7 +701,7 @@ bool getAddressesFromParams(const UniValue& params, std::vector<std::pair<uint16
687701

688702
uint160 hashBytes;
689703
int type = 0;
690-
if (!GetIndexKey(it->get_str(), hashBytes, type)) {
704+
if (!getIndexKey(it->get_str(), hashBytes, type)) {
691705
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
692706
}
693707
addresses.push_back(std::make_pair(hashBytes, type));

0 commit comments

Comments
 (0)