Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | for (const std::string &address : address_amounts.getKeys()) { | ||||
} | } | ||||
CRecipient recipient = {script_pub_key, amount, subtract_fee}; | CRecipient recipient = {script_pub_key, amount, subtract_fee}; | ||||
recipients.push_back(recipient); | recipients.push_back(recipient); | ||||
} | } | ||||
} | } | ||||
UniValue SendMoney(CWallet *const pwallet, const CCoinControl &coin_control, | UniValue SendMoney(CWallet *const pwallet, const CCoinControl &coin_control, | ||||
std::vector<CRecipient> &recipients, mapValue_t map_value) { | std::vector<CRecipient> &recipients, mapValue_t map_value, | ||||
bool broadcast = true) { | |||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
// Shuffle recipient list | // Shuffle recipient list | ||||
std::shuffle(recipients.begin(), recipients.end(), FastRandomContext()); | std::shuffle(recipients.begin(), recipients.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; | ||||
bool fCreated = CreateTransaction( | bool fCreated = CreateTransaction( | ||||
*pwallet, recipients, tx, nFeeRequired, nChangePosRet, error, | *pwallet, recipients, tx, nFeeRequired, nChangePosRet, error, | ||||
coin_control, | coin_control, | ||||
!pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | ||||
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(map_value), {} /* orderForm */); | pwallet->CommitTransaction(tx, std::move(map_value), {} /* orderForm */, | ||||
broadcast); | |||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
static RPCHelpMan sendtoaddress() { | static RPCHelpMan sendtoaddress() { | ||||
return RPCHelpMan{ | return RPCHelpMan{ | ||||
"sendtoaddress", | "sendtoaddress", | ||||
"Send an amount to a given address.\n" + HELP_REQUIRING_PASSPHRASE, | "Send an amount to a given address.\n" + HELP_REQUIRING_PASSPHRASE, | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 4,558 Lines • ▼ Show 20 Lines | return RPCHelpMan{ | ||||
} | } | ||||
return error.original; | return error.original; | ||||
}, | }, | ||||
}; | }; | ||||
} | } | ||||
RPCHelpMan signmessage(); | RPCHelpMan signmessage(); | ||||
static RPCHelpMan createwallettransaction() { | |||||
return RPCHelpMan{ | |||||
"createwallettransaction", | |||||
"Create a transaction sending an amount to a given address.\n" + | |||||
HELP_REQUIRING_PASSPHRASE, | |||||
{ | |||||
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, | |||||
"The bitcoin address to send to."}, | |||||
{"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, | |||||
"The amount in " + Currency::get().ticker + " to send. eg 0.1"}, | |||||
}, | |||||
RPCResult{RPCResult::Type::STR_HEX, "txid", "The transaction id."}, | |||||
RPCExamples{ | |||||
HelpExampleCli("createwallettransaction", | |||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 100000") + | |||||
HelpExampleRpc("createwallettransaction", | |||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 100000")}, | |||||
[&](const RPCHelpMan &self, const Config &config, | |||||
const JSONRPCRequest &request) -> UniValue { | |||||
std::shared_ptr<CWallet> const wallet = | |||||
GetWalletForJSONRPCRequest(request); | |||||
if (!wallet) { | |||||
return NullUniValue; | |||||
} | |||||
CWallet *const pwallet = wallet.get(); | |||||
// Make sure the results are valid at least up to the most recent | |||||
// block the user could have gotten from another RPC command prior | |||||
// to now | |||||
pwallet->BlockUntilSyncedToCurrentChain(); | |||||
LOCK(pwallet->cs_wallet); | |||||
EnsureWalletIsUnlocked(pwallet); | |||||
UniValue address_amounts(UniValue::VOBJ); | |||||
const std::string address = request.params[0].get_str(); | |||||
address_amounts.pushKV(address, request.params[1]); | |||||
UniValue subtractFeeFromAmount(UniValue::VARR); | |||||
std::vector<CRecipient> recipients; | |||||
ParseRecipients(address_amounts, subtractFeeFromAmount, recipients, | |||||
wallet->GetChainParams()); | |||||
CCoinControl coin_control; | |||||
return SendMoney(pwallet, coin_control, recipients, {}, false); | |||||
}, | |||||
}; | |||||
} | |||||
Span<const CRPCCommand> GetWalletRPCCommands() { | Span<const CRPCCommand> GetWalletRPCCommands() { | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category actor (function) | // category actor (function) | ||||
// ------------------ ---------------------- | // ------------------ ---------------------- | ||||
{ "rawtransactions", fundrawtransaction, }, | { "rawtransactions", fundrawtransaction, }, | ||||
{ "wallet", abandontransaction, }, | { "wallet", abandontransaction, }, | ||||
{ "wallet", addmultisigaddress, }, | { "wallet", addmultisigaddress, }, | ||||
Show All 31 Lines | static const CRPCCommand commands[] = { | ||||
{ "wallet", settxfee, }, | { "wallet", settxfee, }, | ||||
{ "wallet", setwalletflag, }, | { "wallet", setwalletflag, }, | ||||
{ "wallet", signmessage, }, | { "wallet", signmessage, }, | ||||
{ "wallet", signrawtransactionwithwallet, }, | { "wallet", signrawtransactionwithwallet, }, | ||||
{ "wallet", unloadwallet, }, | { "wallet", unloadwallet, }, | ||||
{ "wallet", upgradewallet, }, | { "wallet", upgradewallet, }, | ||||
{ "wallet", walletcreatefundedpsbt, }, | { "wallet", walletcreatefundedpsbt, }, | ||||
{ "wallet", walletprocesspsbt, }, | { "wallet", walletprocesspsbt, }, | ||||
// For testing purpose | |||||
{ "hidden", createwallettransaction, }, | |||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
return MakeSpan(commands); | return MakeSpan(commands); | ||||
} | } |