@@ -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+
668682bool 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