Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 424 Lines • ▼ Show 20 Lines | static UniValue getaddressesbyaccount(const Config &config, | ||||
return ret; | return ret; | ||||
} | } | ||||
static CTransactionRef SendMoney(CWallet *const pwallet, | static CTransactionRef SendMoney(CWallet *const pwallet, | ||||
const CTxDestination &address, Amount nValue, | const CTxDestination &address, Amount nValue, | ||||
bool fSubtractFeeFromAmount, | bool fSubtractFeeFromAmount, | ||||
mapValue_t mapValue, std::string fromAccount) { | mapValue_t mapValue, std::string fromAccount) { | ||||
Amount curBalance = pwallet->GetBalance(); | |||||
// Check amount | // Check amount | ||||
if (nValue <= Amount::zero()) { | if (nValue <= Amount::zero()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); | ||||
} | } | ||||
if (nValue > curBalance) { | if (!pwallet->CheckBalance(nValue)) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); | ||||
} | } | ||||
if (pwallet->GetBroadcastTransactions() && !g_connman) { | if (pwallet->GetBroadcastTransactions() && !g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
Show All 9 Lines | static CTransactionRef SendMoney(CWallet *const pwallet, | ||||
int nChangePosRet = -1; | int nChangePosRet = -1; | ||||
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; | CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount}; | ||||
vecSend.push_back(recipient); | vecSend.push_back(recipient); | ||||
CCoinControl coinControl; | CCoinControl coinControl; | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
if (!pwallet->CreateTransaction(vecSend, tx, reservekey, nFeeRequired, | if (!pwallet->CreateTransaction(vecSend, tx, reservekey, nFeeRequired, | ||||
nChangePosRet, strError, coinControl)) { | nChangePosRet, strError, coinControl)) { | ||||
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | if (!fSubtractFeeFromAmount && | ||||
!pwallet->CheckBalance(nValue + nFeeRequired)) { | |||||
strError = strprintf("Error: This transaction requires a " | strError = strprintf("Error: This transaction requires a " | ||||
"transaction fee of at least %s", | "transaction fee of at least %s", | ||||
FormatMoney(nFeeRequired)); | FormatMoney(nFeeRequired)); | ||||
} | } | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strError); | throw JSONRPCError(RPC_WALLET_ERROR, strError); | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | ||||
▲ Show 20 Lines • Show All 3,519 Lines • Show Last 20 Lines |