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,200 changes: 101 additions & 4,099 deletions src/masternodes/mn_rpc.cpp

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions src/masternodes/mn_rpc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#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);

// masternode rpcs
UniValue createmasternode(const JSONRPCRequest& request);
Mixa84 marked this conversation as resolved.
Show resolved Hide resolved
UniValue resignmasternode(const JSONRPCRequest& request);
UniValue listmasternodes(const JSONRPCRequest& request);
UniValue getmasternode(const JSONRPCRequest& request);
UniValue getmasternodeblocks(const JSONRPCRequest& request);
UniValue listcriminalproofs(const JSONRPCRequest& request);
UniValue getanchorteams(const JSONRPCRequest& request);
UniValue listanchors(const JSONRPCRequest& request);

// tokens rpcs
UniValue createtoken(const JSONRPCRequest& request);
UniValue updatetoken(const JSONRPCRequest& request);
UniValue listtokens(const JSONRPCRequest& request);
UniValue gettoken(const JSONRPCRequest& request);
UniValue getcustomtx(const JSONRPCRequest& request);
UniValue minttokens(const JSONRPCRequest& request);

// accounts rpcs
UniValue listaccounts(const JSONRPCRequest& request);
UniValue getaccount(const JSONRPCRequest& request);
UniValue gettokenbalances(const JSONRPCRequest& request);
UniValue utxostoaccount(const JSONRPCRequest& request);
UniValue accounttoaccount(const JSONRPCRequest& request);
UniValue accounttoutxos(const JSONRPCRequest& request);
UniValue listaccounthistory(const JSONRPCRequest& request);
UniValue accounthistorycount(const JSONRPCRequest& request);
UniValue listcommunitybalances(const JSONRPCRequest& request);
UniValue sendtokenstoaddress(const JSONRPCRequest& request);

// poolpair rpcs
UniValue listpoolpairs(const JSONRPCRequest& request);
UniValue getpoolpair(const JSONRPCRequest& request);
UniValue addpoolliquidity(const JSONRPCRequest& request);
UniValue removepoolliquidity(const JSONRPCRequest& request);
UniValue createpoolpair(const JSONRPCRequest& request);
UniValue updatepoolpair(const JSONRPCRequest& request);
UniValue poolswap(const JSONRPCRequest& request);
UniValue listpoolshares(const JSONRPCRequest& request);
UniValue testpoolswap(const JSONRPCRequest& request);

#endif // DEFI_MASTERNODES_MN_RPC_H
Loading