Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
"setlabel", | "setlabel", | ||||
"\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")}, | "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"tabby\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), wallet->chainParams); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
std::string old_label = pwallet->mapAddressBook[dest].name; | std::string old_label = pwallet->mapAddressBook[dest].name; | ||||
std::string label = LabelFromValue(request.params[1]); | std::string label = LabelFromValue(request.params[1]); | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | static UniValue sendtoaddress(const Config &config, | ||||
// Make sure the results are valid at least up to the most recent block | // 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 | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), wallet->chainParams); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | ||||
} | } | ||||
// Amount | // Amount | ||||
Amount nAmount = AmountFromValue(request.params[1]); | Amount nAmount = AmountFromValue(request.params[1]); | ||||
if (nAmount <= Amount::zero()) { | if (nAmount <= Amount::zero()) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | static UniValue signmessage(const Config &config, | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
EnsureWalletIsUnlocked(pwallet); | EnsureWalletIsUnlocked(pwallet); | ||||
std::string strAddress = request.params[0].get_str(); | std::string strAddress = request.params[0].get_str(); | ||||
std::string strMessage = request.params[1].get_str(); | std::string strMessage = request.params[1].get_str(); | ||||
CTxDestination dest = | CTxDestination dest = DecodeDestination(strAddress, wallet->chainParams); | ||||
DecodeDestination(strAddress, config.GetChainParams()); | |||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); | ||||
} | } | ||||
const PKHash *pkhash = boost::get<PKHash>(&dest); | const PKHash *pkhash = boost::get<PKHash>(&dest); | ||||
if (!pkhash) { | if (!pkhash) { | ||||
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaddress(const Config &config, | ||||
// the user could have gotten from another RPC command prior to now | // the user could have gotten from another RPC command prior to now | ||||
pwallet->BlockUntilSyncedToCurrentChain(); | pwallet->BlockUntilSyncedToCurrentChain(); | ||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
// Bitcoin address | // Bitcoin address | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), wallet->chainParams); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid Bitcoin address"); | "Invalid Bitcoin address"); | ||||
} | } | ||||
CScript scriptPubKey = GetScriptForDestination(dest); | CScript scriptPubKey = GetScriptForDestination(dest); | ||||
if (!pwallet->IsMine(scriptPubKey)) { | if (!pwallet->IsMine(scriptPubKey)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); | throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); | ||||
} | } | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
nMinDepth = request.params[1].get_int(); | nMinDepth = request.params[1].get_int(); | ||||
} | } | ||||
// Tally | // Tally | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
TxValidationState state; | TxValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!locked_chain->contextualCheckTransactionForCurrentBlock( | !locked_chain->contextualCheckTransactionForCurrentBlock( | ||||
config.GetChainParams().GetConsensus(), *wtx.tx, state)) { | wallet->chainParams.GetConsensus(), *wtx.tx, state)) { | ||||
continue; | continue; | ||||
} | } | ||||
for (const CTxOut &txout : wtx.tx->vout) { | for (const CTxOut &txout : wtx.tx->vout) { | ||||
if (txout.scriptPubKey == scriptPubKey) { | if (txout.scriptPubKey == scriptPubKey) { | ||||
if (wtx.GetDepthInMainChain() >= nMinDepth) { | if (wtx.GetDepthInMainChain() >= nMinDepth) { | ||||
nAmount += txout.nValue; | nAmount += txout.nValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static UniValue getreceivedbylabel(const Config &config, | ||||
// Tally | // Tally | ||||
Amount nAmount = Amount::zero(); | Amount nAmount = Amount::zero(); | ||||
for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
TxValidationState state; | TxValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!locked_chain->contextualCheckTransactionForCurrentBlock( | !locked_chain->contextualCheckTransactionForCurrentBlock( | ||||
config.GetChainParams().GetConsensus(), *wtx.tx, state)) { | wallet->chainParams.GetConsensus(), *wtx.tx, state)) { | ||||
continue; | continue; | ||||
} | } | ||||
for (const CTxOut &txout : wtx.tx->vout) { | for (const CTxOut &txout : wtx.tx->vout) { | ||||
CTxDestination address; | CTxDestination address; | ||||
if (ExtractDestination(txout.scriptPubKey, address) && | if (ExtractDestination(txout.scriptPubKey, address) && | ||||
pwallet->IsMine(address) && setAddress.count(address)) { | pwallet->IsMine(address) && setAddress.count(address)) { | ||||
if (wtx.GetDepthInMainChain() >= nMinDepth) { | if (wtx.GetDepthInMainChain() >= nMinDepth) { | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | if (!request.params[4].isNull()) { | ||||
subtractFeeFromAmount = request.params[4].get_array(); | subtractFeeFromAmount = request.params[4].get_array(); | ||||
} | } | ||||
std::set<CTxDestination> destinations; | std::set<CTxDestination> destinations; | ||||
std::vector<CRecipient> vecSend; | std::vector<CRecipient> vecSend; | ||||
std::vector<std::string> keys = sendTo.getKeys(); | std::vector<std::string> keys = sendTo.getKeys(); | ||||
for (const std::string &name_ : keys) { | for (const std::string &name_ : keys) { | ||||
CTxDestination dest = DecodeDestination(name_, config.GetChainParams()); | CTxDestination dest = DecodeDestination(name_, wallet->chainParams); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
std::string("Invalid Bitcoin address: ") + | std::string("Invalid Bitcoin address: ") + | ||||
name_); | name_); | ||||
} | } | ||||
if (destinations.count(dest)) { | if (destinations.count(dest)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | static UniValue addmultisigaddress(const Config &config, | ||||
const UniValue &keys_or_addrs = request.params[1].get_array(); | const UniValue &keys_or_addrs = request.params[1].get_array(); | ||||
std::vector<CPubKey> pubkeys; | std::vector<CPubKey> pubkeys; | ||||
for (size_t i = 0; i < keys_or_addrs.size(); ++i) { | for (size_t i = 0; i < keys_or_addrs.size(); ++i) { | ||||
if (IsHex(keys_or_addrs[i].get_str()) && | if (IsHex(keys_or_addrs[i].get_str()) && | ||||
(keys_or_addrs[i].get_str().length() == 66 || | (keys_or_addrs[i].get_str().length() == 66 || | ||||
keys_or_addrs[i].get_str().length() == 130)) { | keys_or_addrs[i].get_str().length() == 130)) { | ||||
pubkeys.push_back(HexToPubKey(keys_or_addrs[i].get_str())); | pubkeys.push_back(HexToPubKey(keys_or_addrs[i].get_str())); | ||||
} else { | } else { | ||||
pubkeys.push_back(AddrToPubKey(config.GetChainParams(), spk_man, | pubkeys.push_back(AddrToPubKey(wallet->chainParams, spk_man, | ||||
keys_or_addrs[i].get_str())); | keys_or_addrs[i].get_str())); | ||||
} | } | ||||
} | } | ||||
OutputType output_type = pwallet->m_default_address_type; | OutputType output_type = pwallet->m_default_address_type; | ||||
// Construct using pay-to-script-hash: | // Construct using pay-to-script-hash: | ||||
CScript inner; | CScript inner; | ||||
Show All 35 Lines | ListReceived(const Config &config, interfaces::Chain::Lock &locked_chain, | ||||
if (ParseIncludeWatchonly(params[2], *pwallet)) { | if (ParseIncludeWatchonly(params[2], *pwallet)) { | ||||
filter |= ISMINE_WATCH_ONLY; | filter |= ISMINE_WATCH_ONLY; | ||||
} | } | ||||
bool has_filtered_address = false; | bool has_filtered_address = false; | ||||
CTxDestination filtered_address = CNoDestination(); | CTxDestination filtered_address = CNoDestination(); | ||||
if (!by_label && params.size() > 3) { | if (!by_label && params.size() > 3) { | ||||
if (!IsValidDestinationString(params[3].get_str(), | if (!IsValidDestinationString(params[3].get_str(), | ||||
config.GetChainParams())) { | pwallet->chainParams)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"address_filter parameter was invalid"); | "address_filter parameter was invalid"); | ||||
} | } | ||||
filtered_address = | filtered_address = | ||||
DecodeDestination(params[3].get_str(), config.GetChainParams()); | DecodeDestination(params[3].get_str(), pwallet->chainParams); | ||||
has_filtered_address = true; | has_filtered_address = true; | ||||
} | } | ||||
// Tally | // Tally | ||||
std::map<CTxDestination, tallyitem> mapTally; | std::map<CTxDestination, tallyitem> mapTally; | ||||
for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
const CWalletTx &wtx = pairWtx.second; | const CWalletTx &wtx = pairWtx.second; | ||||
TxValidationState state; | TxValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!locked_chain.contextualCheckTransactionForCurrentBlock( | !locked_chain.contextualCheckTransactionForCurrentBlock( | ||||
config.GetChainParams().GetConsensus(), *wtx.tx, state)) { | pwallet->chainParams.GetConsensus(), *wtx.tx, state)) { | ||||
continue; | continue; | ||||
} | } | ||||
int nDepth = wtx.GetDepthInMainChain(); | int nDepth = wtx.GetDepthInMainChain(); | ||||
if (nDepth < nMinDepth) { | if (nDepth < nMinDepth) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,205 Lines • ▼ Show 20 Lines | static UniValue listunspent(const Config &config, | ||||
std::set<CTxDestination> destinations; | std::set<CTxDestination> destinations; | ||||
if (!request.params[2].isNull()) { | if (!request.params[2].isNull()) { | ||||
RPCTypeCheckArgument(request.params[2], UniValue::VARR); | RPCTypeCheckArgument(request.params[2], UniValue::VARR); | ||||
UniValue inputs = request.params[2].get_array(); | UniValue inputs = request.params[2].get_array(); | ||||
for (size_t idx = 0; idx < inputs.size(); idx++) { | for (size_t idx = 0; idx < inputs.size(); idx++) { | ||||
const UniValue &input = inputs[idx]; | const UniValue &input = inputs[idx]; | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(input.get_str(), config.GetChainParams()); | DecodeDestination(input.get_str(), wallet->chainParams); | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
std::string("Invalid Bitcoin address: ") + | std::string("Invalid Bitcoin address: ") + | ||||
input.get_str()); | input.get_str()); | ||||
} | } | ||||
if (!destinations.insert(dest).second) { | if (!destinations.insert(dest).second) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
▲ Show 20 Lines • Show All 796 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
HelpExampleRpc("getaddressinfo", example_address)}, | HelpExampleRpc("getaddressinfo", example_address)}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
CTxDestination dest = | CTxDestination dest = | ||||
DecodeDestination(request.params[0].get_str(), config.GetChainParams()); | DecodeDestination(request.params[0].get_str(), wallet->chainParams); | ||||
// Make sure the destination is valid | // Make sure the destination is valid | ||||
if (!IsValidDestination(dest)) { | if (!IsValidDestination(dest)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); | ||||
} | } | ||||
std::string currentAddress = EncodeDestination(dest, config); | std::string currentAddress = EncodeDestination(dest, config); | ||||
ret.pushKV("address", currentAddress); | ret.pushKV("address", currentAddress); | ||||
▲ Show 20 Lines • Show All 508 Lines • ▼ Show 20 Lines | RPCTypeCheck(request.params, | ||||
{UniValue::VARR, | {UniValue::VARR, | ||||
UniValueType(), // ARR or OBJ, checked later | UniValueType(), // ARR or OBJ, checked later | ||||
UniValue::VNUM, UniValue::VOBJ}, | UniValue::VNUM, UniValue::VOBJ}, | ||||
true); | true); | ||||
Amount fee; | Amount fee; | ||||
int change_position; | int change_position; | ||||
CMutableTransaction rawTx = | CMutableTransaction rawTx = | ||||
ConstructTransaction(config.GetChainParams(), request.params[0], | ConstructTransaction(wallet->chainParams, request.params[0], | ||||
request.params[1], request.params[2]); | request.params[1], request.params[2]); | ||||
FundTransaction(pwallet, rawTx, fee, change_position, request.params[3]); | FundTransaction(pwallet, rawTx, fee, change_position, request.params[3]); | ||||
// Make a blank psbt | // Make a blank psbt | ||||
PartiallySignedTransaction psbtx(rawTx); | PartiallySignedTransaction psbtx(rawTx); | ||||
// Fill transaction with out data but don't sign | // Fill transaction with out data but don't sign | ||||
bool bip32derivs = | bool bip32derivs = | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |