diff --git a/src/Makefile.am b/src/Makefile.am index c89f3591cb..d63dff71cf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -480,7 +480,6 @@ libbitcoin_server_a_SOURCES = \ masternode/payments.cpp \ masternode/sync.cpp \ masternode/utils.cpp \ - messagesigner.cpp \ miner.cpp \ net.cpp \ netfulfilledman.cpp \ @@ -770,6 +769,7 @@ libbitcoin_util_a_SOURCES = \ fs.cpp \ interfaces/handler.cpp \ logging.cpp \ + messagesigner.cpp \ random.cpp \ randomenv.cpp \ rpc/request.cpp \ diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 8d7a8ca232..f94f7037e7 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -294,25 +294,13 @@ static void UpdateSpecialTxInputsHash(const CMutableTransaction& tx, SpecialTxPa } template -static void SignSpecialTxPayloadByHash(const CMutableTransaction& tx, SpecialTxPayload& payload, const CKey& key) +static void SignSpecialTxPayloadByHash(const CMutableTransaction& tx, SpecialTxPayload& payload, const CKeyID& keyID, const CWallet& wallet) { UpdateSpecialTxInputsHash(tx, payload); payload.vchSig.clear(); - uint256 hash = ::SerializeHash(payload); - if (!CHashSigner::SignHash(hash, key, payload.vchSig)) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to sign special tx"); - } -} - -template -static void SignSpecialTxPayloadByString(const CMutableTransaction& tx, SpecialTxPayload& payload, const CKey& key) -{ - UpdateSpecialTxInputsHash(tx, payload); - payload.vchSig.clear(); - - std::string m = payload.MakeSignString(); - if (!CMessageSigner::SignMessage(m, payload.vchSig, key)) { + const uint256 hash = ::SerializeHash(payload); + if (!wallet.SignSpecialTxPayload(hash, keyID, payload.vchSig)) { throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to sign special tx"); } } @@ -1111,14 +1099,12 @@ static UniValue protx_update_registrar_wrapper(const JSONRPCRequest& request, CC ptx.scriptPayout = GetScriptForDestination(payoutDest); } - LegacyScriptPubKeyMan* spk_man = wallet->GetLegacyScriptPubKeyMan(); - if (!spk_man) { - throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command"); - } - - CKey keyOwner; - if (!spk_man->GetKey(dmn->pdmnState->keyIDOwner, keyOwner)) { - throw std::runtime_error(strprintf("Private key for owner address %s not found in your wallet", EncodeDestination(PKHash(dmn->pdmnState->keyIDOwner)))); + { + const auto pkhash{PKHash(dmn->pdmnState->keyIDOwner)}; + LOCK(wallet->cs_wallet); + if (wallet->IsMine(GetScriptForDestination(pkhash)) != isminetype::ISMINE_SPENDABLE) { + throw std::runtime_error(strprintf("Private key for owner address %s not found in your wallet", EncodeDestination(pkhash))); + } } CMutableTransaction tx; @@ -1136,7 +1122,7 @@ static UniValue protx_update_registrar_wrapper(const JSONRPCRequest& request, CC } FundSpecialTx(wallet.get(), tx, ptx, feeSourceDest); - SignSpecialTxPayloadByHash(tx, ptx, keyOwner); + SignSpecialTxPayloadByHash(tx, ptx, dmn->pdmnState->keyIDOwner, *wallet); SetTxPayload(tx, ptx); return SignAndSendSpecialTx(request, chain_helper, chainman, tx); diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index d12474d63f..6e29f11b52 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include