Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | if (nValue > curBalance) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); | ||||
} | } | ||||
// Parse Bitcoin address | // Parse Bitcoin address | ||||
CScript scriptPubKey = GetScriptForDestination(address); | CScript scriptPubKey = GetScriptForDestination(address); | ||||
// Create and send the transaction | // Create and send the transaction | ||||
Amount nFeeRequired; | Amount nFeeRequired; | ||||
std::string strError; | bilingual_str error; | ||||
std::vector<CRecipient> vecSend; | std::vector<CRecipient> vecSend; | ||||
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(locked_chain, vecSend, tx, nFeeRequired, | if (!pwallet->CreateTransaction(locked_chain, vecSend, tx, nFeeRequired, | ||||
nChangePosRet, strError, coinControl)) { | nChangePosRet, error, coinControl)) { | ||||
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | ||||
strError = strprintf("Error: This transaction requires a " | error = strprintf(Untranslated("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, error.original); | ||||
} | } | ||||
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | ||||
return tx; | return tx; | ||||
} | } | ||||
static UniValue sendtoaddress(const Config &config, | static UniValue sendtoaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
▲ Show 20 Lines • Show All 656 Lines • ▼ Show 20 Lines | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
// Shuffle recipient list | // Shuffle recipient list | ||||
std::shuffle(vecSend.begin(), vecSend.end(), FastRandomContext()); | std::shuffle(vecSend.begin(), vecSend.end(), FastRandomContext()); | ||||
// Send | // Send | ||||
Amount nFeeRequired = Amount::zero(); | Amount nFeeRequired = Amount::zero(); | ||||
int nChangePosRet = -1; | int nChangePosRet = -1; | ||||
std::string strFailReason; | bilingual_str error; | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
CCoinControl coinControl; | CCoinControl coinControl; | ||||
bool fCreated = | bool fCreated = | ||||
pwallet->CreateTransaction(*locked_chain, vecSend, tx, nFeeRequired, | pwallet->CreateTransaction(*locked_chain, vecSend, tx, nFeeRequired, | ||||
nChangePosRet, strFailReason, coinControl); | nChangePosRet, error, coinControl); | ||||
if (!fCreated) { | if (!fCreated) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original); | ||||
} | } | ||||
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
static UniValue addmultisigaddress(const Config &config, | static UniValue addmultisigaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
▲ Show 20 Lines • Show All 2,581 Lines • ▼ Show 20 Lines | for (size_t idx = 0; idx < subtractFeeFromOutputs.size(); idx++) { | ||||
if (pos >= int(tx.vout.size())) { | if (pos >= int(tx.vout.size())) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
strprintf("Invalid parameter, position too large: %d", pos)); | strprintf("Invalid parameter, position too large: %d", pos)); | ||||
} | } | ||||
setSubtractFeeFromOutputs.insert(pos); | setSubtractFeeFromOutputs.insert(pos); | ||||
} | } | ||||
std::string strFailReason; | bilingual_str error; | ||||
if (!pwallet->FundTransaction(tx, fee_out, change_position, strFailReason, | if (!pwallet->FundTransaction(tx, fee_out, change_position, error, | ||||
lockUnspents, setSubtractFeeFromOutputs, | lockUnspents, setSubtractFeeFromOutputs, | ||||
coinControl)) { | coinControl)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, error.original); | ||||
} | } | ||||
} | } | ||||
static UniValue fundrawtransaction(const Config &config, | static UniValue fundrawtransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
▲ Show 20 Lines • Show All 1,145 Lines • Show Last 20 Lines |