Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | if (pwallet->IsMine(dest)) { | ||||
pwallet->SetAddressBook(dest, label, "receive"); | pwallet->SetAddressBook(dest, label, "receive"); | ||||
} else { | } else { | ||||
pwallet->SetAddressBook(dest, label, "send"); | pwallet->SetAddressBook(dest, label, "send"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static CTransactionRef SendMoney(interfaces::Chain::Lock &locked_chain, | static CTransactionRef SendMoney(CWallet *const pwallet, | ||||
CWallet *const pwallet, | |||||
const CTxDestination &address, Amount nValue, | const CTxDestination &address, Amount nValue, | ||||
bool fSubtractFeeFromAmount, | bool fSubtractFeeFromAmount, | ||||
const CCoinControl &coin_control, | const CCoinControl &coin_control, | ||||
mapValue_t mapValue) { | mapValue_t mapValue) { | ||||
Amount curBalance = | Amount curBalance = | ||||
pwallet->GetBalance(0, coin_control.m_avoid_address_reuse) | pwallet->GetBalance(0, coin_control.m_avoid_address_reuse) | ||||
.m_mine_trusted; | .m_mine_trusted; | ||||
Show All 13 Lines | static CTransactionRef SendMoney(CWallet *const pwallet, | ||||
Amount nFeeRequired; | Amount nFeeRequired; | ||||
bilingual_str error; | 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); | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
if (!pwallet->CreateTransaction(locked_chain, vecSend, tx, nFeeRequired, | if (!pwallet->CreateTransaction(vecSend, tx, nFeeRequired, nChangePosRet, | ||||
nChangePosRet, error, coin_control)) { | error, coin_control)) { | ||||
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | ||||
error = strprintf(Untranslated("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, error.original); | throw JSONRPCError(RPC_WALLET_ERROR, error.original); | ||||
} | } | ||||
pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */); | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | static UniValue sendtoaddress(const Config &config, | ||||
coin_control.m_avoid_address_reuse = | coin_control.m_avoid_address_reuse = | ||||
GetAvoidReuseFlag(pwallet, request.params[5]); | GetAvoidReuseFlag(pwallet, request.params[5]); | ||||
// We also enable partial spend avoidance if reuse avoidance is set. | // We also enable partial spend avoidance if reuse avoidance is set. | ||||
coin_control.m_avoid_partial_spends |= coin_control.m_avoid_address_reuse; | coin_control.m_avoid_partial_spends |= coin_control.m_avoid_address_reuse; | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
CTransactionRef tx = | CTransactionRef tx = | ||||
SendMoney(*locked_chain, pwallet, dest, nAmount, fSubtractFeeFromAmount, | SendMoney(pwallet, dest, nAmount, fSubtractFeeFromAmount, coin_control, | ||||
coin_control, std::move(mapValue)); | std::move(mapValue)); | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
static UniValue listaddressgroupings(const Config &config, | static UniValue listaddressgroupings(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 539 Lines • ▼ Show 20 Lines | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
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; | ||||
bilingual_str error; | bilingual_str error; | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
CCoinControl coinControl; | CCoinControl coinControl; | ||||
bool fCreated = | bool fCreated = pwallet->CreateTransaction( | ||||
pwallet->CreateTransaction(*locked_chain, vecSend, tx, nFeeRequired, | vecSend, tx, nFeeRequired, nChangePosRet, error, coinControl); | ||||
nChangePosRet, error, coinControl); | |||||
if (!fCreated) { | if (!fCreated) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original); | 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, | ||||
▲ Show 20 Lines • Show All 3,851 Lines • Show Last 20 Lines |