Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | static UniValue getrawchangeaddress(const Config &config, | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
if (!ParseOutputType(request.params[0].get_str(), output_type)) { | if (!ParseOutputType(request.params[0].get_str(), output_type)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
strprintf("Unknown address type '%s'", | strprintf("Unknown address type '%s'", | ||||
request.params[0].get_str())); | request.params[0].get_str())); | ||||
} | } | ||||
} | } | ||||
CReserveKey reservekey(pwallet); | ReserveDestination reservedest(pwallet); | ||||
CPubKey vchPubKey; | CTxDestination dest; | ||||
if (!reservekey.GetReservedKey(vchPubKey, true)) { | if (!reservedest.GetReservedDestination(output_type, dest, true)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_KEYPOOL_RAN_OUT, | RPC_WALLET_KEYPOOL_RAN_OUT, | ||||
"Error: Keypool ran out, please call keypoolrefill first"); | "Error: Keypool ran out, please call keypoolrefill first"); | ||||
} | } | ||||
reservekey.KeepKey(); | reservedest.KeepDestination(); | ||||
pwallet->LearnRelatedScripts(vchPubKey, output_type); | |||||
CTxDestination dest = GetDestinationForKey(vchPubKey, output_type); | |||||
return EncodeDestination(dest, config); | return EncodeDestination(dest, config); | ||||
} | } | ||||
static UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | static UniValue setlabel(const Config &config, 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(); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | if (pwallet->GetBroadcastTransactions() && !pwallet->chain().p2pEnabled()) { | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
// Parse Bitcoin address | // Parse Bitcoin address | ||||
CScript scriptPubKey = GetScriptForDestination(address); | CScript scriptPubKey = GetScriptForDestination(address); | ||||
// Create and send the transaction | // Create and send the transaction | ||||
CReserveKey reservekey(pwallet); | ReserveDestination reservedest(pwallet); | ||||
Amount nFeeRequired; | Amount nFeeRequired; | ||||
std::string strError; | std::string strError; | ||||
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, reservekey, | if (!pwallet->CreateTransaction(locked_chain, vecSend, tx, reservedest, | ||||
nFeeRequired, nChangePosRet, strError, | nFeeRequired, nChangePosRet, strError, | ||||
coinControl)) { | coinControl)) { | ||||
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance) { | ||||
strError = strprintf("Error: This transaction requires a " | strError = strprintf("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, strError); | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | ||||
reservekey, state)) { | reservedest, state)) { | ||||
strError = | strError = | ||||
strprintf("Error: The transaction was rejected! Reason given: %s", | strprintf("Error: The transaction was rejected! Reason given: %s", | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strError); | throw JSONRPCError(RPC_WALLET_ERROR, strError); | ||||
} | } | ||||
return tx; | return tx; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 659 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 | ||||
CReserveKey keyChange(pwallet); | ReserveDestination changedest(pwallet); | ||||
Amount nFeeRequired = Amount::zero(); | Amount nFeeRequired = Amount::zero(); | ||||
int nChangePosRet = -1; | int nChangePosRet = -1; | ||||
std::string strFailReason; | std::string strFailReason; | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
CCoinControl coinControl; | CCoinControl coinControl; | ||||
bool fCreated = pwallet->CreateTransaction( | bool fCreated = pwallet->CreateTransaction( | ||||
*locked_chain, vecSend, tx, keyChange, nFeeRequired, nChangePosRet, | *locked_chain, vecSend, tx, changedest, nFeeRequired, nChangePosRet, | ||||
strFailReason, coinControl); | strFailReason, coinControl); | ||||
if (!fCreated) { | if (!fCreated) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason); | ||||
} | } | ||||
CValidationState state; | CValidationState state; | ||||
if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, | ||||
keyChange, state)) { | changedest, state)) { | ||||
strFailReason = strprintf("Transaction commit failed:: %s", | strFailReason = strprintf("Transaction commit failed:: %s", | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
} | } | ||||
return tx->GetId().GetHex(); | return tx->GetId().GetHex(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 3,654 Lines • Show Last 20 Lines |