Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor mn_rpc file and split into different categories based on RPC types #234

Merged
merged 10 commits into from
Feb 24, 2021
5 changes: 5 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ DEFI_CORE_H = \
masternodes/incentivefunding.h \
masternodes/masternodes.h \
masternodes/mn_checks.h \
masternodes/mn_rpc.h \
masternodes/res.h \
masternodes/rewardhistoryold.h \
masternodes/tokens.h \
Expand Down Expand Up @@ -373,6 +374,10 @@ libdefi_server_a_SOURCES = \
masternodes/masternodes.cpp \
masternodes/mn_checks.cpp \
masternodes/mn_rpc.cpp \
masternodes/rpc_masternodes.cpp \
masternodes/rpc_accounts.cpp \
masternodes/rpc_tokens.cpp \
masternodes/rpc_poolpair.cpp \
masternodes/tokens.cpp \
masternodes/poolpairs.cpp \
masternodes/undos.cpp \
Expand Down
4,217 changes: 93 additions & 4,124 deletions src/masternodes/mn_rpc.cpp

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions src/masternodes/mn_rpc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifndef DEFI_MASTERNODES_MN_RPC_H
#define DEFI_MASTERNODES_MN_RPC_H

#include <arith_uint256.h>
#include <univalue.h>

#include <chainparams.h>
#include <core_io.h>
#include <validation.h>

#include <masternodes/criminals.h>
#include <masternodes/masternodes.h>
#include <masternodes/mn_checks.h>

#include <rpc/rawtransaction_util.h>
#include <rpc/server.h>
#include <rpc/util.h>

//#ifdef ENABLE_WALLET
#include <wallet/coincontrol.h>
#include <wallet/fees.h>
#include <wallet/rpcwallet.h>
//#endif

typedef enum {
// selecting accounts without sorting
SelectionForward,
// selecting accounts by ascending of sum token amounts
// it means that we select first accounts with min sum of
// neccessary token amounts
SelectionCrumbs,
// selecting accounts by descending of sum token amounts
// it means that we select first accounts with max sum of
// neccessary token amounts
SelectionPie,
} AccountSelectionMode;

// Special guarding object. Should be created before the first use of funding (straight or by GetAuthInputsSmart())
struct LockedCoinsScopedGuard {
CWallet* const pwallet;
std::set<COutPoint> lockedCoinsBackup;

LockedCoinsScopedGuard(CWallet* const pwl) : pwallet(pwl)
{
LOCK(pwallet->cs_wallet);
lockedCoinsBackup = pwallet->setLockedCoins;
}

~LockedCoinsScopedGuard()
{
LOCK(pwallet->cs_wallet);
if (lockedCoinsBackup.empty()) {
pwallet->UnlockAllCoins();
} else {
std::vector<COutPoint> diff;
std::set_difference(pwallet->setLockedCoins.begin(), pwallet->setLockedCoins.end(), lockedCoinsBackup.begin(), lockedCoinsBackup.end(), std::back_inserter(diff));
for (auto const& coin : diff) {
pwallet->UnlockCoin(coin);
}
}
}
};

// common functions
int chainHeight(interfaces::Chain::Lock& locked_chain);
std::vector<CTxIn> GetInputs(UniValue const& inputs);
CMutableTransaction fund(CMutableTransaction& mtx, CWallet* const pwallet, CTransactionRef optAuthTx, CCoinControl* coin_control = nullptr, bool lockUnspents = false);
CTransactionRef sign(CMutableTransaction& mtx, CWallet* const pwallet, CTransactionRef optAuthTx);
CTransactionRef send(CTransactionRef tx, CTransactionRef optAuthTx);
CTransactionRef signsend(CMutableTransaction& mtx, CWallet* const pwallet, CTransactionRef optAuthTx /* = {}*/);
CWallet* GetWallet(const JSONRPCRequest& request);
std::vector<CTxIn> GetAuthInputsSmart(CWallet* const pwallet, int32_t txVersion, std::set<CScript>& auths, bool needFounderAuth, CTransactionRef& optAuthTx, UniValue const& explicitInputs);
std::string ScriptToString(CScript const& script);
CAccounts GetAllMineAccounts(CWallet* const pwallet);
CAccounts SelectAccountsByTargetBalances(const CAccounts& accounts, const CBalances& targetBalances, AccountSelectionMode selectionMode);

#endif // DEFI_MASTERNODES_MN_RPC_H
Loading