MCPcopy Create free account
hub / github.com/LUX-Core/lux / SendMoney

Function SendMoney

src/rpcdarksend.cpp:26–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#include <fstream>
25
26void SendMoney(const CTxDestination& address, CAmount nValue, CWalletTx& wtxNew, AvailableCoinsType coin_type) {
27 // Check amount
28 if (nValue <= 0)
29 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount");
30
31 if (nValue > pwalletMain->GetBalance())
32 throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
33
34 string strError;
35 if (pwalletMain->IsLocked()) {
36 strError = "Error: Wallet locked, unable to create transaction!";
37 LogPrintf("SendMoney() : %s", strError);
38 throw JSONRPCError(RPC_WALLET_ERROR, strError);
39 }
40
41 // Parse Lux address
42 CScript scriptPubKey = GetScriptForDestination(address);
43
44 // Create and send the transaction
45 CReserveKey reservekey(pwalletMain);
46 CAmount nFeeRequired;
47 std::vector<CRecipient> vecSend;
48 CRecipient recipient = {scriptPubKey, nValue, false};
49 vecSend.push_back(recipient);
50 int nChangePos;
51 if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePos, strError, NULL, coin_type)) {
52 if (nValue + nFeeRequired > pwalletMain->GetBalance())
53 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));
54 LogPrintf("SendMoney() : %s\n", strError);
55 throw JSONRPCError(RPC_WALLET_ERROR, strError);
56 }
57 if (!pwalletMain->CommitTransaction(wtxNew, reservekey))
58 throw JSONRPCError(RPC_WALLET_ERROR,
59 "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.");
60}
61
62UniValue darksend(const UniValue& params, bool fHelp) {
63 if (fHelp || params.size() == 0)

Callers 1

darksendFunction · 0.70

Calls 7

JSONRPCErrorFunction · 0.85
GetScriptForDestinationFunction · 0.85
FormatMoneyFunction · 0.85
IsLockedMethod · 0.80
CreateTransactionMethod · 0.80
CommitTransactionMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected