mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
refactor/fix: use the shared_ptr<CWallet> where possible instead of getting the underlying pointer (#5052)
* refactor/fix: use the shared_ptr<CWallet> where possible instead of getting the underlying pointer This is also a fix in regards to the rpcevo.cpp file where the old code could result in a dangling pointer that could result in a crash as the shared_ptr we get back is discarded while the underlying ptr is still being used * refactor: remove unneeded line Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
parent
f4bb06985f
commit
ad660554aa
@ -34,7 +34,6 @@ static UniValue coinjoin(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
if (fMasternodeMode)
|
if (fMasternodeMode)
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Client-side mixing is not supported on masternodes");
|
||||||
@ -50,12 +49,12 @@ static UniValue coinjoin(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = coinJoinClientManagers.find(pwallet->GetName());
|
auto it = coinJoinClientManagers.find(wallet->GetName());
|
||||||
|
|
||||||
if (request.params[0].get_str() == "start") {
|
if (request.params[0].get_str() == "start") {
|
||||||
{
|
{
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
if (pwallet->IsLocked(true))
|
if (wallet->IsLocked(true))
|
||||||
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please unlock wallet for mixing with walletpassphrase first.");
|
throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please unlock wallet for mixing with walletpassphrase first.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,15 +155,14 @@ static UniValue getcoinjoininfo(const JSONRPCRequest& request)
|
|||||||
obj.pushKV("queue_size", coinJoinClientQueueManager->GetQueueSize());
|
obj.pushKV("queue_size", coinJoinClientQueueManager->GetQueueSize());
|
||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
CWallet* const pwallet = wallet.get();
|
if (!wallet) {
|
||||||
if (!pwallet) {
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
coinJoinClientManagers.at(pwallet->GetName())->GetJsonInfo(obj);
|
coinJoinClientManagers.at(wallet->GetName())->GetJsonInfo(obj);
|
||||||
|
|
||||||
obj.pushKV("keys_left", pwallet->nKeysLeftSinceAutoBackup);
|
obj.pushKV("keys_left", wallet->nKeysLeftSinceAutoBackup);
|
||||||
obj.pushKV("warnings", pwallet->nKeysLeftSinceAutoBackup < COINJOIN_KEYS_THRESHOLD_WARNING
|
obj.pushKV("warnings", wallet->nKeysLeftSinceAutoBackup < COINJOIN_KEYS_THRESHOLD_WARNING
|
||||||
? "WARNING: keypool is almost depleted!" : "");
|
? "WARNING: keypool is almost depleted!" : "");
|
||||||
#endif // ENABLE_WALLET
|
#endif // ENABLE_WALLET
|
||||||
|
|
||||||
|
@ -149,11 +149,10 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
|
|||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
gobject_prepare_help(request);
|
gobject_prepare_help(request);
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
// ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS
|
// ASSEMBLE NEW GOVERNANCE OBJECT FROM USER PARAMETERS
|
||||||
|
|
||||||
@ -200,7 +199,7 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
|
|||||||
g_txindex->BlockUntilSyncedToCurrentChain();
|
g_txindex->BlockUntilSyncedToCurrentChain();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
|
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
@ -225,7 +224,7 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
bool fork_active = WITH_LOCK(cs_main, return VersionBitsTipState(Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE);
|
bool fork_active = WITH_LOCK(cs_main, return VersionBitsTipState(Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024) == ThresholdState::ACTIVE);
|
||||||
|
|
||||||
if (!pwallet->GetBudgetSystemCollateralTX(tx, govobj.GetHash(), govobj.GetMinCollateralFee(fork_active), outpoint)) {
|
if (!wallet->GetBudgetSystemCollateralTX(tx, govobj.GetHash(), govobj.GetMinCollateralFee(fork_active), outpoint)) {
|
||||||
std::string err = "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked.";
|
std::string err = "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked.";
|
||||||
if (!request.params[5].isNull() && !request.params[6].isNull()) {
|
if (!request.params[5].isNull() && !request.params[6].isNull()) {
|
||||||
err += "Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee.";
|
err += "Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee.";
|
||||||
@ -233,14 +232,14 @@ static UniValue gobject_prepare(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, err);
|
throw JSONRPCError(RPC_INTERNAL_ERROR, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pwallet->WriteGovernanceObject({hashParent, nRevision, nTime, tx->GetHash(), strDataHex})) {
|
if (!wallet->WriteGovernanceObject({hashParent, nRevision, nTime, tx->GetHash(), strDataHex})) {
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "WriteGovernanceObject failed");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "WriteGovernanceObject failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- send the tx to the network
|
// -- send the tx to the network
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
pwallet->CommitTransaction(tx, {}, {});
|
wallet->CommitTransaction(tx, {}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrint(BCLog::GOBJECT, "gobject_prepare -- GetDataAsPlainString = %s, hash = %s, txid = %s\n",
|
LogPrint(BCLog::GOBJECT, "gobject_prepare -- GetDataAsPlainString = %s, hash = %s, txid = %s\n",
|
||||||
@ -268,17 +267,15 @@ static UniValue gobject_list_prepared(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
|
||||||
|
|
||||||
int64_t nCount = request.params.empty() ? 10 : ParseInt64V(request.params[0], "count");
|
int64_t nCount = request.params.empty() ? 10 : ParseInt64V(request.params[0], "count");
|
||||||
if (nCount < 0) {
|
if (nCount < 0) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count");
|
||||||
}
|
}
|
||||||
// Get a list of all prepared governance objects stored in the wallet
|
// Get a list of all prepared governance objects stored in the wallet
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
std::vector<const CGovernanceObject*> vecObjects = pwallet->GetGovernanceObjects();
|
std::vector<const CGovernanceObject*> vecObjects = wallet->GetGovernanceObjects();
|
||||||
// Sort the vector by the object creation time/hex data
|
// Sort the vector by the object creation time/hex data
|
||||||
std::sort(vecObjects.begin(), vecObjects.end(), [](const CGovernanceObject* a, const CGovernanceObject* b) {
|
std::sort(vecObjects.begin(), vecObjects.end(), [](const CGovernanceObject* a, const CGovernanceObject* b) {
|
||||||
bool fGreater = a->GetCreationTime() > b->GetCreationTime();
|
bool fGreater = a->GetCreationTime() > b->GetCreationTime();
|
||||||
@ -608,7 +605,6 @@ static UniValue gobject_vote_many(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
uint256 hash = ParseHashV(request.params[0], "Object hash");
|
uint256 hash = ParseHashV(request.params[0], "Object hash");
|
||||||
std::string strVoteSignal = request.params[1].get_str();
|
std::string strVoteSignal = request.params[1].get_str();
|
||||||
@ -626,9 +622,9 @@ static UniValue gobject_vote_many(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan();
|
LegacyScriptPubKeyMan* spk_man = wallet->GetLegacyScriptPubKeyMan();
|
||||||
if (!spk_man) {
|
if (!spk_man) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
||||||
}
|
}
|
||||||
@ -668,7 +664,6 @@ static UniValue gobject_vote_alias(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
uint256 hash = ParseHashV(request.params[0], "Object hash");
|
uint256 hash = ParseHashV(request.params[0], "Object hash");
|
||||||
std::string strVoteSignal = request.params[1].get_str();
|
std::string strVoteSignal = request.params[1].get_str();
|
||||||
@ -686,7 +681,7 @@ static UniValue gobject_vote_alias(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
|
||||||
}
|
}
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
uint256 proTxHash = ParseHashV(request.params[3], "protx-hash");
|
uint256 proTxHash = ParseHashV(request.params[3], "protx-hash");
|
||||||
auto dmn = deterministicMNManager->GetListAtChainTip().GetValidMN(proTxHash);
|
auto dmn = deterministicMNManager->GetListAtChainTip().GetValidMN(proTxHash);
|
||||||
@ -694,7 +689,7 @@ static UniValue gobject_vote_alias(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid or unknown proTxHash");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid or unknown proTxHash");
|
||||||
}
|
}
|
||||||
|
|
||||||
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan();
|
LegacyScriptPubKeyMan* spk_man = wallet->GetLegacyScriptPubKeyMan();
|
||||||
if (!spk_man) {
|
if (!spk_man) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
||||||
}
|
}
|
||||||
|
@ -196,15 +196,14 @@ static UniValue masternode_outputs(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
// Find possible candidates
|
// Find possible candidates
|
||||||
std::vector<COutput> vPossibleCoins;
|
std::vector<COutput> vPossibleCoins;
|
||||||
CCoinControl coin_control;
|
CCoinControl coin_control;
|
||||||
coin_control.nCoinType = CoinType::ONLY_MASTERNODE_COLLATERAL;
|
coin_control.nCoinType = CoinType::ONLY_MASTERNODE_COLLATERAL;
|
||||||
{
|
{
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
pwallet->AvailableCoins(vPossibleCoins, true, &coin_control);
|
wallet->AvailableCoins(vPossibleCoins, true, &coin_control);
|
||||||
}
|
}
|
||||||
UniValue outputsArr(UniValue::VARR);
|
UniValue outputsArr(UniValue::VARR);
|
||||||
for (const auto& out : vPossibleCoins) {
|
for (const auto& out : vPossibleCoins) {
|
||||||
|
@ -194,7 +194,7 @@ static void FundSpecialTx(CWallet* pwallet, CMutableTransaction& tx, const Speci
|
|||||||
ds << payload;
|
ds << payload;
|
||||||
tx.vExtraPayload.assign(ds.begin(), ds.end());
|
tx.vExtraPayload.assign(ds.begin(), ds.end());
|
||||||
|
|
||||||
static CTxOut dummyTxOut(0, CScript() << OP_RETURN);
|
static const CTxOut dummyTxOut(0, CScript() << OP_RETURN);
|
||||||
std::vector<CRecipient> vecSend;
|
std::vector<CRecipient> vecSend;
|
||||||
bool dummyTxOutAdded = false;
|
bool dummyTxOutAdded = false;
|
||||||
|
|
||||||
@ -446,10 +446,9 @@ static UniValue protx_register(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
if (isExternalRegister || isFundRegister) {
|
if (isExternalRegister || isFundRegister) {
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t paramIdx = 0;
|
size_t paramIdx = 0;
|
||||||
@ -485,8 +484,8 @@ static UniValue protx_register(const JSONRPCRequest& request)
|
|||||||
paramIdx += 2;
|
paramIdx += 2;
|
||||||
|
|
||||||
// TODO unlock on failure
|
// TODO unlock on failure
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
pwallet->LockCoin(ptx.collateralOutpoint);
|
wallet->LockCoin(ptx.collateralOutpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.params[paramIdx].get_str() != "") {
|
if (request.params[paramIdx].get_str() != "") {
|
||||||
@ -533,7 +532,7 @@ static UniValue protx_register(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[paramIdx + 6].get_str());
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[paramIdx + 6].get_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
FundSpecialTx(pwallet, tx, ptx, fundDest);
|
FundSpecialTx(wallet.get(), tx, ptx, fundDest);
|
||||||
UpdateSpecialTxInputsHash(tx, ptx);
|
UpdateSpecialTxInputsHash(tx, ptx);
|
||||||
|
|
||||||
bool fSubmit{true};
|
bool fSubmit{true};
|
||||||
@ -580,7 +579,7 @@ static UniValue protx_register(const JSONRPCRequest& request)
|
|||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
// lets prove we own the collateral
|
// lets prove we own the collateral
|
||||||
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan();
|
LegacyScriptPubKeyMan* spk_man = wallet->GetLegacyScriptPubKeyMan();
|
||||||
if (!spk_man) {
|
if (!spk_man) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
||||||
}
|
}
|
||||||
@ -602,9 +601,8 @@ static UniValue protx_register_submit(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
CMutableTransaction tx;
|
CMutableTransaction tx;
|
||||||
if (!DecodeHexTx(tx, request.params[0].get_str())) {
|
if (!DecodeHexTx(tx, request.params[0].get_str())) {
|
||||||
@ -656,9 +654,8 @@ static UniValue protx_update_service(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
CProUpServTx ptx;
|
CProUpServTx ptx;
|
||||||
ptx.nVersion = CProUpServTx::CURRENT_VERSION;
|
ptx.nVersion = CProUpServTx::CURRENT_VERSION;
|
||||||
@ -715,7 +712,7 @@ static UniValue protx_update_service(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FundSpecialTx(pwallet, tx, ptx, feeSource);
|
FundSpecialTx(wallet.get(), tx, ptx, feeSource);
|
||||||
|
|
||||||
SignSpecialTxPayloadByHash(tx, ptx, keyOperator);
|
SignSpecialTxPayloadByHash(tx, ptx, keyOperator);
|
||||||
SetTxPayload(tx, ptx);
|
SetTxPayload(tx, ptx);
|
||||||
@ -752,9 +749,8 @@ static UniValue protx_update_registrar(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
CProUpRegTx ptx;
|
CProUpRegTx ptx;
|
||||||
ptx.nVersion = CProUpRegTx::CURRENT_VERSION;
|
ptx.nVersion = CProUpRegTx::CURRENT_VERSION;
|
||||||
@ -785,7 +781,7 @@ static UniValue protx_update_registrar(const JSONRPCRequest& request)
|
|||||||
ptx.scriptPayout = GetScriptForDestination(payoutDest);
|
ptx.scriptPayout = GetScriptForDestination(payoutDest);
|
||||||
}
|
}
|
||||||
|
|
||||||
LegacyScriptPubKeyMan* spk_man = pwallet->GetLegacyScriptPubKeyMan();
|
LegacyScriptPubKeyMan* spk_man = wallet->GetLegacyScriptPubKeyMan();
|
||||||
if (!spk_man) {
|
if (!spk_man) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
|
||||||
}
|
}
|
||||||
@ -809,7 +805,7 @@ static UniValue protx_update_registrar(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[4].get_str());
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[4].get_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
FundSpecialTx(pwallet, tx, ptx, feeSourceDest);
|
FundSpecialTx(wallet.get(), tx, ptx, feeSourceDest);
|
||||||
SignSpecialTxPayloadByHash(tx, ptx, keyOwner);
|
SignSpecialTxPayloadByHash(tx, ptx, keyOwner);
|
||||||
SetTxPayload(tx, ptx);
|
SetTxPayload(tx, ptx);
|
||||||
|
|
||||||
@ -845,9 +841,8 @@ static UniValue protx_revoke(const JSONRPCRequest& request)
|
|||||||
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!wallet) return NullUniValue;
|
if (!wallet) return NullUniValue;
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(wallet.get());
|
||||||
|
|
||||||
CProUpRevTx ptx;
|
CProUpRevTx ptx;
|
||||||
ptx.nVersion = CProUpRevTx::CURRENT_VERSION;
|
ptx.nVersion = CProUpRevTx::CURRENT_VERSION;
|
||||||
@ -880,17 +875,17 @@ static UniValue protx_revoke(const JSONRPCRequest& request)
|
|||||||
CTxDestination feeSourceDest = DecodeDestination(request.params[3].get_str());
|
CTxDestination feeSourceDest = DecodeDestination(request.params[3].get_str());
|
||||||
if (!IsValidDestination(feeSourceDest))
|
if (!IsValidDestination(feeSourceDest))
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[3].get_str());
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Dash address: ") + request.params[3].get_str());
|
||||||
FundSpecialTx(pwallet, tx, ptx, feeSourceDest);
|
FundSpecialTx(wallet.get(), tx, ptx, feeSourceDest);
|
||||||
} else if (dmn->pdmnState->scriptOperatorPayout != CScript()) {
|
} else if (dmn->pdmnState->scriptOperatorPayout != CScript()) {
|
||||||
// Using funds from previousely specified operator payout address
|
// Using funds from previousely specified operator payout address
|
||||||
CTxDestination txDest;
|
CTxDestination txDest;
|
||||||
ExtractDestination(dmn->pdmnState->scriptOperatorPayout, txDest);
|
ExtractDestination(dmn->pdmnState->scriptOperatorPayout, txDest);
|
||||||
FundSpecialTx(pwallet, tx, ptx, txDest);
|
FundSpecialTx(wallet.get(), tx, ptx, txDest);
|
||||||
} else if (dmn->pdmnState->scriptPayout != CScript()) {
|
} else if (dmn->pdmnState->scriptPayout != CScript()) {
|
||||||
// Using funds from previousely specified masternode payout address
|
// Using funds from previousely specified masternode payout address
|
||||||
CTxDestination txDest;
|
CTxDestination txDest;
|
||||||
ExtractDestination(dmn->pdmnState->scriptPayout, txDest);
|
ExtractDestination(dmn->pdmnState->scriptPayout, txDest);
|
||||||
FundSpecialTx(pwallet, tx, ptx, txDest);
|
FundSpecialTx(wallet.get(), tx, ptx, txDest);
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "No payout or fee source addresses found, can't revoke");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "No payout or fee source addresses found, can't revoke");
|
||||||
}
|
}
|
||||||
@ -1002,16 +997,12 @@ static UniValue protx_list(const JSONRPCRequest& request)
|
|||||||
{
|
{
|
||||||
protx_list_help(request);
|
protx_list_help(request);
|
||||||
|
|
||||||
CWallet* pwallet;
|
std::shared_ptr<CWallet> wallet{nullptr};
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
try {
|
try {
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
wallet = GetWalletForJSONRPCRequest(request);
|
||||||
pwallet = wallet.get();
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
pwallet = nullptr;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
pwallet = nullptr;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string type = "registered";
|
std::string type = "registered";
|
||||||
@ -1026,11 +1017,11 @@ static UniValue protx_list(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type == "wallet") {
|
if (type == "wallet") {
|
||||||
if (!pwallet) {
|
if (!wallet) {
|
||||||
throw std::runtime_error("\"protx list wallet\" not supported when wallet is disabled");
|
throw std::runtime_error("\"protx list wallet\" not supported when wallet is disabled");
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
LOCK2(pwallet->cs_wallet, cs_main);
|
LOCK2(wallet->cs_wallet, cs_main);
|
||||||
|
|
||||||
if (request.params.size() > 4) {
|
if (request.params.size() > 4) {
|
||||||
protx_list_help(request);
|
protx_list_help(request);
|
||||||
@ -1044,7 +1035,7 @@ static UniValue protx_list(const JSONRPCRequest& request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<COutPoint> vOutpts;
|
std::vector<COutPoint> vOutpts;
|
||||||
pwallet->ListProTxCoins(vOutpts);
|
wallet->ListProTxCoins(vOutpts);
|
||||||
std::set<COutPoint> setOutpts;
|
std::set<COutPoint> setOutpts;
|
||||||
for (const auto& outpt : vOutpts) {
|
for (const auto& outpt : vOutpts) {
|
||||||
setOutpts.emplace(outpt);
|
setOutpts.emplace(outpt);
|
||||||
@ -1053,11 +1044,11 @@ static UniValue protx_list(const JSONRPCRequest& request)
|
|||||||
CDeterministicMNList mnList = deterministicMNManager->GetListForBlock(::ChainActive()[height]);
|
CDeterministicMNList mnList = deterministicMNManager->GetListForBlock(::ChainActive()[height]);
|
||||||
mnList.ForEachMN(false, [&](const auto& dmn) {
|
mnList.ForEachMN(false, [&](const auto& dmn) {
|
||||||
if (setOutpts.count(dmn.collateralOutpoint) ||
|
if (setOutpts.count(dmn.collateralOutpoint) ||
|
||||||
CheckWalletOwnsKey(pwallet, dmn.pdmnState->keyIDOwner) ||
|
CheckWalletOwnsKey(wallet.get(), dmn.pdmnState->keyIDOwner) ||
|
||||||
CheckWalletOwnsKey(pwallet, dmn.pdmnState->keyIDVoting) ||
|
CheckWalletOwnsKey(wallet.get(), dmn.pdmnState->keyIDVoting) ||
|
||||||
CheckWalletOwnsScript(pwallet, dmn.pdmnState->scriptPayout) ||
|
CheckWalletOwnsScript(wallet.get(), dmn.pdmnState->scriptPayout) ||
|
||||||
CheckWalletOwnsScript(pwallet, dmn.pdmnState->scriptOperatorPayout)) {
|
CheckWalletOwnsScript(wallet.get(), dmn.pdmnState->scriptOperatorPayout)) {
|
||||||
ret.push_back(BuildDMNListEntry(pwallet, dmn, detailed));
|
ret.push_back(BuildDMNListEntry(wallet.get(), dmn, detailed));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
@ -1078,7 +1069,7 @@ static UniValue protx_list(const JSONRPCRequest& request)
|
|||||||
CDeterministicMNList mnList = deterministicMNManager->GetListForBlock(::ChainActive()[height]);
|
CDeterministicMNList mnList = deterministicMNManager->GetListForBlock(::ChainActive()[height]);
|
||||||
bool onlyValid = type == "valid";
|
bool onlyValid = type == "valid";
|
||||||
mnList.ForEachMN(onlyValid, [&](const auto& dmn) {
|
mnList.ForEachMN(onlyValid, [&](const auto& dmn) {
|
||||||
ret.push_back(BuildDMNListEntry(pwallet, dmn, detailed));
|
ret.push_back(BuildDMNListEntry(wallet.get(), dmn, detailed));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid type specified");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid type specified");
|
||||||
@ -1110,16 +1101,12 @@ static UniValue protx_info(const JSONRPCRequest& request)
|
|||||||
{
|
{
|
||||||
protx_info_help(request);
|
protx_info_help(request);
|
||||||
|
|
||||||
CWallet* pwallet;
|
std::shared_ptr<CWallet> wallet{nullptr};
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
try {
|
try {
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
wallet = GetWalletForJSONRPCRequest(request);
|
||||||
pwallet = wallet.get();
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
pwallet = nullptr;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
pwallet = nullptr;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (g_txindex) {
|
if (g_txindex) {
|
||||||
@ -1132,7 +1119,7 @@ static UniValue protx_info(const JSONRPCRequest& request)
|
|||||||
if (!dmn) {
|
if (!dmn) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s not found", proTxHash.ToString()));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s not found", proTxHash.ToString()));
|
||||||
}
|
}
|
||||||
return BuildDMNListEntry(pwallet, *dmn, true);
|
return BuildDMNListEntry(wallet.get(), *dmn, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void protx_diff_help(const JSONRPCRequest& request)
|
static void protx_diff_help(const JSONRPCRequest& request)
|
||||||
|
Loading…
Reference in New Issue
Block a user