Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 614 Lines • ▼ Show 20 Lines | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); | ||||
} | } | ||||
const PKHash *pkhash = boost::get<PKHash>(&dest); | const PKHash *pkhash = boost::get<PKHash>(&dest); | ||||
if (!pkhash) { | if (!pkhash) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | ||||
} | } | ||||
CScript script_pub_key = GetScriptForDestination(*pkhash); | |||||
std::unique_ptr<SigningProvider> provider = | |||||
pwallet->GetSigningProvider(script_pub_key); | |||||
if (!provider) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available"); | |||||
} | |||||
CKey key; | |||||
CKeyID keyID(*pkhash); | |||||
if (!provider->GetKey(keyID, key)) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available"); | |||||
} | |||||
std::string signature; | std::string signature; | ||||
SigningResult err = pwallet->SignMessage(strMessage, *pkhash, signature); | |||||
if (!MessageSign(key, strMessage, signature)) { | if (err == SigningResult::SIGNING_FAILED) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
SigningResultString(err)); | |||||
} else if (err != SigningResult::OK) { | |||||
throw JSONRPCError(RPC_WALLET_ERROR, SigningResultString(err)); | |||||
} | } | ||||
return signature; | return signature; | ||||
} | } | ||||
static Amount GetReceived(const CWallet &wallet, const UniValue ¶ms, | static Amount GetReceived(const CWallet &wallet, const UniValue ¶ms, | ||||
bool by_label) | bool by_label) | ||||
EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) { | EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) { | ||||
▲ Show 20 Lines • Show All 4,224 Lines • Show Last 20 Lines |