|
19 | 19 | #include <stdint.h> |
20 | 20 |
|
21 | 21 | #include <boost/assign/list_of.hpp> |
| 22 | + |
22 | 23 | #include "json/json_spirit_utils.h" |
23 | 24 | #include "json/json_spirit_value.h" |
24 | 25 |
|
@@ -316,35 +317,29 @@ Value getaddressesbyaccount(const Array& params, bool fHelp) |
316 | 317 | return ret; |
317 | 318 | } |
318 | 319 |
|
319 | | -void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew) |
| 320 | +static void SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew) |
320 | 321 | { |
| 322 | + CAmount curBalance = pwalletMain->GetBalance(); |
| 323 | + |
321 | 324 | // Check amount |
322 | 325 | if (nValue <= 0) |
323 | 326 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); |
324 | 327 |
|
325 | | - if (nValue > pwalletMain->GetBalance()) |
| 328 | + if (nValue > curBalance) |
326 | 329 | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); |
327 | 330 |
|
328 | | - string strError; |
329 | | - if (pwalletMain->IsLocked()) |
330 | | - { |
331 | | - strError = "Error: Wallet locked, unable to create transaction!"; |
332 | | - LogPrintf("SendMoney(): %s", strError); |
333 | | - throw JSONRPCError(RPC_WALLET_ERROR, strError); |
334 | | - } |
335 | | - |
336 | 331 | // Parse Bitcoin address |
337 | 332 | CScript scriptPubKey = GetScriptForDestination(address); |
338 | 333 |
|
339 | 334 | // Create and send the transaction |
340 | 335 | CReserveKey reservekey(pwalletMain); |
341 | 336 | CAmount nFeeRequired; |
342 | | - if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError)) |
343 | | - { |
344 | | - if (nValue + nFeeRequired > pwalletMain->GetBalance()) |
345 | | - 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)); |
346 | | - LogPrintf("SendMoney(): %s\n", strError); |
347 | | - throw JSONRPCError(RPC_WALLET_ERROR, strError); |
| 337 | + std::string strError; |
| 338 | + if (!pwalletMain->CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError)) { |
| 339 | + if (nValue + nFeeRequired > curBalance) |
| 340 | + throw JSONRPCError(RPC_WALLET_ERROR, 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))); |
| 341 | + else |
| 342 | + throw JSONRPCError(RPC_WALLET_ERROR, strError); |
348 | 343 | } |
349 | 344 | if (!pwalletMain->CommitTransaction(wtxNew, reservekey)) |
350 | 345 | 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."); |
|
0 commit comments