mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Move SendMoney() to rpcwallet.cpp.
This commit is contained in:
parent
f0877f8b62
commit
b93173dee9
@ -12,6 +12,7 @@
|
|||||||
#include "netbase.h"
|
#include "netbase.h"
|
||||||
#include "timedata.h"
|
#include "timedata.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "utilmoneystr.h"
|
||||||
#include "wallet.h"
|
#include "wallet.h"
|
||||||
#include "walletdb.h"
|
#include "walletdb.h"
|
||||||
|
|
||||||
@ -309,6 +310,42 @@ Value getaddressesbyaccount(const Array& params, bool fHelp)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew)
|
||||||
|
{
|
||||||
|
// Check amount
|
||||||
|
if (nValue <= 0)
|
||||||
|
throw JSONRPCError(RPC_WALLET_ERROR, "Invalid amount");
|
||||||
|
|
||||||
|
if (nValue > pwalletMain->GetBalance())
|
||||||
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
|
||||||
|
|
||||||
|
string strError;
|
||||||
|
if (pwalletMain->IsLocked())
|
||||||
|
{
|
||||||
|
strError = "Error: Wallet locked, unable to create transaction!";
|
||||||
|
LogPrintf("SendMoney() : %s", strError);
|
||||||
|
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse Bitcoin address
|
||||||
|
CScript scriptPubKey = GetScriptForDestination(address);
|
||||||
|
|
||||||
|
// Create and send the transaction
|
||||||
|
CReserveKey reservekey(pwalletMain);
|
||||||
|
CAmount nFeeRequired;
|
||||||
|
if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError))
|
||||||
|
{
|
||||||
|
if (nValue + nFeeRequired > pwalletMain->GetBalance())
|
||||||
|
strError = strprintf("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!", FormatMoney(nFeeRequired));
|
||||||
|
LogPrintf("SendMoney() : %s\n", strError);
|
||||||
|
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
||||||
|
}
|
||||||
|
if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
|
||||||
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Value sendtoaddress(const Array& params, bool fHelp)
|
Value sendtoaddress(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() < 2 || params.size() > 4)
|
if (fHelp || params.size() < 2 || params.size() > 4)
|
||||||
@ -348,9 +385,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
EnsureWalletIsUnlocked();
|
EnsureWalletIsUnlocked();
|
||||||
|
|
||||||
string strError = pwalletMain->SendMoney(address.Get(), nAmount, wtx);
|
SendMoney(address.Get(), nAmount, wtx);
|
||||||
if (strError != "")
|
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
|
||||||
|
|
||||||
return wtx.GetHash().GetHex();
|
return wtx.GetHash().GetHex();
|
||||||
}
|
}
|
||||||
@ -791,10 +826,7 @@ Value sendfrom(const Array& params, bool fHelp)
|
|||||||
if (nAmount > nBalance)
|
if (nAmount > nBalance)
|
||||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
|
||||||
|
|
||||||
// Send
|
SendMoney(address.Get(), nAmount, wtx);
|
||||||
string strError = pwalletMain->SendMoney(address.Get(), nAmount, wtx);
|
|
||||||
if (strError != "")
|
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, strError);
|
|
||||||
|
|
||||||
return wtx.GetHash().GetHex();
|
return wtx.GetHash().GetHex();
|
||||||
}
|
}
|
||||||
|
@ -1587,46 +1587,6 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string CWallet::SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew)
|
|
||||||
{
|
|
||||||
// Check amount
|
|
||||||
if (nValue <= 0)
|
|
||||||
return _("Invalid amount");
|
|
||||||
if (nValue > GetBalance())
|
|
||||||
return _("Insufficient funds");
|
|
||||||
|
|
||||||
string strError;
|
|
||||||
if (IsLocked())
|
|
||||||
{
|
|
||||||
strError = _("Error: Wallet locked, unable to create transaction!");
|
|
||||||
LogPrintf("SendMoney() : %s", strError);
|
|
||||||
return strError;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse Bitcoin address
|
|
||||||
CScript scriptPubKey = GetScriptForDestination(address);
|
|
||||||
|
|
||||||
// Create and send the transaction
|
|
||||||
CReserveKey reservekey(this);
|
|
||||||
CAmount nFeeRequired;
|
|
||||||
if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError))
|
|
||||||
{
|
|
||||||
if (nValue + nFeeRequired > GetBalance())
|
|
||||||
strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds!"), FormatMoney(nFeeRequired));
|
|
||||||
LogPrintf("SendMoney() : %s\n", strError);
|
|
||||||
return strError;
|
|
||||||
}
|
|
||||||
if (!CommitTransaction(wtxNew, reservekey))
|
|
||||||
return _("Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
|
CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
|
||||||
{
|
{
|
||||||
// payTxFee is user-set "I want to pay this much"
|
// payTxFee is user-set "I want to pay this much"
|
||||||
|
@ -288,7 +288,6 @@ public:
|
|||||||
bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue,
|
bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue,
|
||||||
CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
|
CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
|
||||||
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
|
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
|
||||||
std::string SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew);
|
|
||||||
|
|
||||||
static CFeeRate minTxFee;
|
static CFeeRate minTxFee;
|
||||||
static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
|
static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
|
||||||
|
Loading…
Reference in New Issue
Block a user