mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-18 03:27:41 +02:00
Move direct calls to MessageSign into new SignMessage functions in CWallet and ScriptPubKeyMan
Instead of getting a SigningProvider and then going to MessageSign, have ScriptPubKeyMan handle the message signing internally.
This commit is contained in:
@@ -565,22 +565,12 @@ static UniValue signmessage(const JSONRPCRequest& request)
|
||||
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;
|
||||
|
||||
if (!MessageSign(key, strMessage, signature)) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
|
||||
SigningResult err = pwallet->SignMessage(strMessage, *pkhash, signature);
|
||||
if (err == SigningResult::SIGNING_FAILED) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, SigningResultString(err));
|
||||
} else if (err != SigningResult::OK){
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, SigningResultString(err));
|
||||
}
|
||||
|
||||
return signature;
|
||||
|
||||
Reference in New Issue
Block a user