Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | void WalletTxToJSON(const CWalletTx &wtx, UniValue &entry) { | ||||
if (confirms > 0) { | if (confirms > 0) { | ||||
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); | entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); | ||||
entry.push_back(Pair("blockindex", wtx.nIndex)); | entry.push_back(Pair("blockindex", wtx.nIndex)); | ||||
entry.push_back( | entry.push_back( | ||||
Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime())); | Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime())); | ||||
} else { | } else { | ||||
entry.push_back(Pair("trusted", wtx.IsTrusted())); | entry.push_back(Pair("trusted", wtx.IsTrusted())); | ||||
} | } | ||||
uint256 hash = wtx.GetId(); | uint256 hash = wtx.GetHash(); | ||||
entry.push_back(Pair("txid", hash.GetHex())); | entry.push_back(Pair("txhash", hash.GetHex())); | ||||
UniValue conflicts(UniValue::VARR); | UniValue conflicts(UniValue::VARR); | ||||
for (const uint256 &conflict : wtx.GetConflicts()) { | for (const txhash_t &conflict : wtx.GetConflicts()) { | ||||
conflicts.push_back(conflict.GetHex()); | conflicts.push_back(conflict.GetHex()); | ||||
} | } | ||||
entry.push_back(Pair("walletconflicts", conflicts)); | entry.push_back(Pair("walletconflicts", conflicts)); | ||||
entry.push_back(Pair("time", wtx.GetTxTime())); | entry.push_back(Pair("time", wtx.GetTxTime())); | ||||
entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); | entry.push_back(Pair("timereceived", (int64_t)wtx.nTimeReceived)); | ||||
for (const std::pair<std::string, std::string> &item : wtx.mapValue) { | for (const std::pair<std::string, std::string> &item : wtx.mapValue) { | ||||
entry.push_back(Pair(item.first, item.second)); | entry.push_back(Pair(item.first, item.second)); | ||||
▲ Show 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
"transaction. This is not part of the \n" | "transaction. This is not part of the \n" | ||||
" transaction, just kept in your " | " transaction, just kept in your " | ||||
"wallet.\n" | "wallet.\n" | ||||
"5. subtractfeefromamount (boolean, optional, default=false) The " | "5. subtractfeefromamount (boolean, optional, default=false) The " | ||||
"fee will be deducted from the amount being sent.\n" | "fee will be deducted from the amount being sent.\n" | ||||
" The recipient will receive less " | " The recipient will receive less " | ||||
"bitcoins than you enter in the amount field.\n" | "bitcoins than you enter in the amount field.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"txid\" (string) The transaction id.\n" | "\"txhash\" (string) The transaction hash.\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("sendtoaddress", | HelpExampleCli("sendtoaddress", | ||||
"\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1") + | "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1") + | ||||
HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvay" | ||||
"dd\" 0.1 \"donation\" \"seans " | "dd\" 0.1 \"donation\" \"seans " | ||||
"outpost\"") + | "outpost\"") + | ||||
HelpExampleCli( | HelpExampleCli( | ||||
"sendtoaddress", | "sendtoaddress", | ||||
Show All 31 Lines | static UniValue sendtoaddress(const Config &config, | ||||
if (request.params.size() > 4) { | if (request.params.size() > 4) { | ||||
fSubtractFeeFromAmount = request.params[4].get_bool(); | fSubtractFeeFromAmount = request.params[4].get_bool(); | ||||
} | } | ||||
EnsureWalletIsUnlocked(); | EnsureWalletIsUnlocked(); | ||||
SendMoney(dest, nAmount, fSubtractFeeFromAmount, wtx); | SendMoney(dest, nAmount, fSubtractFeeFromAmount, wtx); | ||||
return wtx.GetId().GetHex(); | return wtx.GetHash().GetHex(); | ||||
} | } | ||||
static UniValue listaddressgroupings(const Config &config, | static UniValue listaddressgroupings(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaddress(const Config &config, | ||||
// Minimum confirmations | // Minimum confirmations | ||||
int nMinDepth = 1; | int nMinDepth = 1; | ||||
if (request.params.size() > 1) { | if (request.params.size() > 1) { | ||||
nMinDepth = request.params[1].get_int(); | nMinDepth = request.params[1].get_int(); | ||||
} | } | ||||
// Tally | // Tally | ||||
CAmount nAmount = 0; | CAmount nAmount = 0; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<txhash_t, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!ContextualCheckTransactionForCurrentBlock( | !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state, | config, *wtx.tx, state, | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | static UniValue getreceivedbyaccount(const Config &config, | ||||
// Get the set of pub keys assigned to account | // Get the set of pub keys assigned to account | ||||
std::string strAccount = AccountFromValue(request.params[0]); | std::string strAccount = AccountFromValue(request.params[0]); | ||||
std::set<CTxDestination> setAddress = | std::set<CTxDestination> setAddress = | ||||
pwalletMain->GetAccountAddresses(strAccount); | pwalletMain->GetAccountAddresses(strAccount); | ||||
// Tally | // Tally | ||||
CAmount nAmount = 0; | CAmount nAmount = 0; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<txhash_t, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!ContextualCheckTransactionForCurrentBlock( | !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state, | config, *wtx.tx, state, | ||||
config.GetChainParams().GetConsensus())) { | config.GetChainParams().GetConsensus())) { | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | static UniValue getbalance(const Config &config, | ||||
if (request.params[0].get_str() == "*") { | if (request.params[0].get_str() == "*") { | ||||
// Calculate total balance in a very different way from GetBalance(). | // Calculate total balance in a very different way from GetBalance(). | ||||
// The biggest difference is that GetBalance() sums up all unspent | // The biggest difference is that GetBalance() sums up all unspent | ||||
// TxOuts paying to the wallet, while this sums up both spent and | // TxOuts paying to the wallet, while this sums up both spent and | ||||
// unspent TxOuts paying to the wallet, and then subtracts the values of | // unspent TxOuts paying to the wallet, and then subtracts the values of | ||||
// TxIns spending from the wallet. This also has fewer restrictions on | // TxIns spending from the wallet. This also has fewer restrictions on | ||||
// which unconfirmed transactions are considered trusted. | // which unconfirmed transactions are considered trusted. | ||||
CAmount nBalance = 0; | CAmount nBalance = 0; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<txhash_t, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (!ContextualCheckTransactionForCurrentBlock( | if (!ContextualCheckTransactionForCurrentBlock( | ||||
config, wtx, state, | config, wtx, state, | ||||
config.GetChainParams().GetConsensus()) || | config.GetChainParams().GetConsensus()) || | ||||
wtx.GetBlocksToMaturity() > 0 || | wtx.GetBlocksToMaturity() > 0 || | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 3 || | ||||
"transaction, just kept in your wallet.\n" | "transaction, just kept in your wallet.\n" | ||||
"6. \"comment_to\" (string, optional) An optional comment " | "6. \"comment_to\" (string, optional) An optional comment " | ||||
"to store the name of the person or organization \n" | "to store the name of the person or organization \n" | ||||
" to which you're sending the " | " to which you're sending the " | ||||
"transaction. This is not part of the transaction, \n" | "transaction. This is not part of the transaction, \n" | ||||
" it is just kept in your " | " it is just kept in your " | ||||
"wallet.\n" | "wallet.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"txid\" (string) The transaction id.\n" | "\"txhash\" (string) The transaction hash.\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nSend 0.01 " + | "\nSend 0.01 " + | ||||
CURRENCY_UNIT + " from the default account to the address, must " | CURRENCY_UNIT + " from the default account to the address, must " | ||||
"have at least 1 confirmation\n" + | "have at least 1 confirmation\n" + | ||||
HelpExampleCli("sendfrom", | HelpExampleCli("sendfrom", | ||||
"\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") + | "\"\" \"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") + | ||||
"\nSend 0.01 from the tabby account to the given address, funds " | "\nSend 0.01 from the tabby account to the given address, funds " | ||||
"must have at least 6 confirmations\n" + | "must have at least 6 confirmations\n" + | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | CAmount nBalance = | ||||
pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); | pwalletMain->GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); | ||||
if (nAmount > nBalance) { | if (nAmount > nBalance) { | ||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, | ||||
"Account has insufficient funds"); | "Account has insufficient funds"); | ||||
} | } | ||||
SendMoney(dest, nAmount, false, wtx); | SendMoney(dest, nAmount, false, wtx); | ||||
return wtx.GetId().GetHex(); | return wtx.GetHash().GetHex(); | ||||
} | } | ||||
static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
Show All 30 Lines | if (request.fHelp || request.params.size() < 2 || | ||||
" If no addresses are specified here, " | " If no addresses are specified here, " | ||||
"the sender pays the fee.\n" | "the sender pays the fee.\n" | ||||
" [\n" | " [\n" | ||||
" \"address\" (string) Subtract fee from this " | " \"address\" (string) Subtract fee from this " | ||||
"address\n" | "address\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"txid\" (string) The transaction id for the " | "\"txhash\" (string) The transaction hash for the " | ||||
"send. Only 1 transaction is created regardless of \n" | "send. Only 1 transaction is created regardless of \n" | ||||
" the number of addresses.\n" | " the number of addresses.\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nSend two amounts to two different addresses:\n" + | "\nSend two amounts to two different addresses:\n" + | ||||
HelpExampleCli("sendmany", | HelpExampleCli("sendmany", | ||||
"\"\" " | "\"\" " | ||||
"\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," | ||||
"\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}" | "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}" | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { | ||||
CValidationState state; | CValidationState state; | ||||
if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get(), | if (!pwalletMain->CommitTransaction(wtx, keyChange, g_connman.get(), | ||||
state)) { | state)) { | ||||
strFailReason = strprintf("Transaction commit failed:: %s", | strFailReason = strprintf("Transaction commit failed:: %s", | ||||
state.GetRejectReason()); | state.GetRejectReason()); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); | ||||
} | } | ||||
return wtx.GetId().GetHex(); | return wtx.GetHash().GetHex(); | ||||
} | } | ||||
static UniValue addmultisigaddress(const Config &config, | static UniValue addmultisigaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static UniValue addmultisigaddress(const Config &config, | ||||
pwalletMain->SetAddressBook(innerID, strAccount, "send"); | pwalletMain->SetAddressBook(innerID, strAccount, "send"); | ||||
return EncodeDestination(innerID); | return EncodeDestination(innerID); | ||||
} | } | ||||
struct tallyitem { | struct tallyitem { | ||||
CAmount nAmount; | CAmount nAmount; | ||||
int nConf; | int nConf; | ||||
std::vector<uint256> txids; | std::vector<uint256> txhashes; | ||||
bool fIsWatchonly; | bool fIsWatchonly; | ||||
tallyitem() { | tallyitem() { | ||||
nAmount = 0; | nAmount = 0; | ||||
nConf = std::numeric_limits<int>::max(); | nConf = std::numeric_limits<int>::max(); | ||||
fIsWatchonly = false; | fIsWatchonly = false; | ||||
} | } | ||||
}; | }; | ||||
Show All 12 Lines | static UniValue ListReceived(const Config &config, const UniValue ¶ms, | ||||
} | } | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (params.size() > 2 && params[2].get_bool()) | if (params.size() > 2 && params[2].get_bool()) | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
// Tally | // Tally | ||||
std::map<CTxDestination, tallyitem> mapTally; | std::map<CTxDestination, tallyitem> mapTally; | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<txhash_t, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CValidationState state; | CValidationState state; | ||||
if (wtx.IsCoinBase() || | if (wtx.IsCoinBase() || | ||||
!ContextualCheckTransactionForCurrentBlock( | !ContextualCheckTransactionForCurrentBlock( | ||||
config, *wtx.tx, state, | config, *wtx.tx, state, | ||||
Show All 15 Lines | for (std::map<txhash_t, CWalletTx>::iterator it = | ||||
isminefilter mine = IsMine(*pwalletMain, address); | isminefilter mine = IsMine(*pwalletMain, address); | ||||
if (!(mine & filter)) { | if (!(mine & filter)) { | ||||
continue; | continue; | ||||
} | } | ||||
tallyitem &item = mapTally[address]; | tallyitem &item = mapTally[address]; | ||||
item.nAmount += txout.nValue.GetSatoshis(); | item.nAmount += txout.nValue.GetSatoshis(); | ||||
item.nConf = std::min(item.nConf, nDepth); | item.nConf = std::min(item.nConf, nDepth); | ||||
item.txids.push_back(wtx.GetId()); | item.txhashes.push_back(wtx.GetHash()); | ||||
if (mine & ISMINE_WATCH_ONLY) { | if (mine & ISMINE_WATCH_ONLY) { | ||||
item.fIsWatchonly = true; | item.fIsWatchonly = true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Reply | // Reply | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
Show All 32 Lines | for (const std::pair<CTxDestination, CAddressBookData> &item : | ||||
obj.push_back( | obj.push_back( | ||||
Pair("confirmations", | Pair("confirmations", | ||||
(nConf == std::numeric_limits<int>::max() ? 0 : nConf))); | (nConf == std::numeric_limits<int>::max() ? 0 : nConf))); | ||||
if (!fByAccounts) { | if (!fByAccounts) { | ||||
obj.push_back(Pair("label", strAccount)); | obj.push_back(Pair("label", strAccount)); | ||||
} | } | ||||
UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
if (it != mapTally.end()) { | if (it != mapTally.end()) { | ||||
for (const uint256 &_item : (*it).second.txids) { | for (const uint256 &_item : (*it).second.txhashes) { | ||||
transactions.push_back(_item.GetHex()); | transactions.push_back(_item.GetHex()); | ||||
} | } | ||||
} | } | ||||
obj.push_back(Pair("txids", transactions)); | obj.push_back(Pair("txhashes", transactions)); | ||||
ret.push_back(obj); | ret.push_back(obj); | ||||
} | } | ||||
} | } | ||||
if (fByAccounts) { | if (fByAccounts) { | ||||
for (std::map<std::string, tallyitem>::iterator it = | for (std::map<std::string, tallyitem>::iterator it = | ||||
mapAccountTally.begin(); | mapAccountTally.begin(); | ||||
it != mapAccountTally.end(); ++it) { | it != mapAccountTally.end(); ++it) { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 3) { | ||||
" \"amount\" : x.xxx, (numeric) The total " | " \"amount\" : x.xxx, (numeric) The total " | ||||
"amount in " + | "amount in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" received by the address\n" | " received by the address\n" | ||||
" \"confirmations\" : n, (numeric) The number of " | " \"confirmations\" : n, (numeric) The number of " | ||||
"confirmations of the most recent transaction included\n" | "confirmations of the most recent transaction included\n" | ||||
" \"label\" : \"label\", (string) A comment for " | " \"label\" : \"label\", (string) A comment for " | ||||
"the address/transaction, if any\n" | "the address/transaction, if any\n" | ||||
" \"txids\": [\n" | " \"txhashes\": [\n" | ||||
" n, (numeric) The ids of " | " n, (numeric) The ids of " | ||||
"transactions received with the address \n" | "transactions received with the address \n" | ||||
" ...\n" | " ...\n" | ||||
" ]\n" | " ]\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 4) { | ||||
"transactions.\n" | "transactions.\n" | ||||
" \"blockindex\": n, (numeric) The index of the " | " \"blockindex\": n, (numeric) The index of the " | ||||
"transaction in the block that includes it. Available for 'send' " | "transaction in the block that includes it. Available for 'send' " | ||||
"and 'receive'\n" | "and 'receive'\n" | ||||
" category of " | " category of " | ||||
"transactions.\n" | "transactions.\n" | ||||
" \"blocktime\": xxx, (numeric) The block time in " | " \"blocktime\": xxx, (numeric) The block time in " | ||||
"seconds since epoch (1 Jan 1970 GMT).\n" | "seconds since epoch (1 Jan 1970 GMT).\n" | ||||
" \"txid\": \"transactionid\", (string) The transaction id. " | " \"txhash\": \"transactionhash\", (string) The transaction " | ||||
"hash. " | |||||
"Available for 'send' and 'receive' category of transactions.\n" | "Available for 'send' and 'receive' category of transactions.\n" | ||||
" \"time\": xxx, (numeric) The transaction time in " | " \"time\": xxx, (numeric) The transaction time in " | ||||
"seconds since epoch (midnight Jan 1 1970 GMT).\n" | "seconds since epoch (midnight Jan 1 1970 GMT).\n" | ||||
" \"timereceived\": xxx, (numeric) The time received in " | " \"timereceived\": xxx, (numeric) The time received in " | ||||
"seconds since epoch (midnight Jan 1 1970 GMT). Available \n" | "seconds since epoch (midnight Jan 1 1970 GMT). Available \n" | ||||
" for 'send' and " | " for 'send' and " | ||||
"'receive' category of transactions.\n" | "'receive' category of transactions.\n" | ||||
" \"comment\": \"...\", (string) If a comment is " | " \"comment\": \"...\", (string) If a comment is " | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | static UniValue listaccounts(const Config &config, | ||||
for (const std::pair<CTxDestination, CAddressBookData> &entry : | for (const std::pair<CTxDestination, CAddressBookData> &entry : | ||||
pwalletMain->mapAddressBook) { | pwalletMain->mapAddressBook) { | ||||
// This address belongs to me | // This address belongs to me | ||||
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) { | if (IsMine(*pwalletMain, entry.first) & includeWatchonly) { | ||||
mapAccountBalances[entry.second.name] = 0; | mapAccountBalances[entry.second.name] = 0; | ||||
} | } | ||||
} | } | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<txhash_t, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); ++it) { | it != pwalletMain->mapWallet.end(); ++it) { | ||||
const CWalletTx &wtx = (*it).second; | const CWalletTx &wtx = (*it).second; | ||||
CAmount nFee; | CAmount nFee; | ||||
std::string strSentAccount; | std::string strSentAccount; | ||||
std::list<COutputEntry> listReceived; | std::list<COutputEntry> listReceived; | ||||
std::list<COutputEntry> listSent; | std::list<COutputEntry> listSent; | ||||
int nDepth = wtx.GetDepthInMainChain(); | int nDepth = wtx.GetDepthInMainChain(); | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | if (request.fHelp) { | ||||
" \"blockhash\": \"hashvalue\", (string) The block hash " | " \"blockhash\": \"hashvalue\", (string) The block hash " | ||||
"containing the transaction. Available for 'send' and 'receive' " | "containing the transaction. Available for 'send' and 'receive' " | ||||
"category of transactions.\n" | "category of transactions.\n" | ||||
" \"blockindex\": n, (numeric) The index of the " | " \"blockindex\": n, (numeric) The index of the " | ||||
"transaction in the block that includes it. Available for 'send' " | "transaction in the block that includes it. Available for 'send' " | ||||
"and 'receive' category of transactions.\n" | "and 'receive' category of transactions.\n" | ||||
" \"blocktime\": xxx, (numeric) The block time in " | " \"blocktime\": xxx, (numeric) The block time in " | ||||
"seconds since epoch (1 Jan 1970 GMT).\n" | "seconds since epoch (1 Jan 1970 GMT).\n" | ||||
" \"txid\": \"transactionid\", (string) The transaction id. " | " \"txhash\": \"transactionhash\", (string) The transaction " | ||||
"hash. " | |||||
"Available for 'send' and 'receive' category of transactions.\n" | "Available for 'send' and 'receive' category of transactions.\n" | ||||
" \"time\": xxx, (numeric) The transaction time in " | " \"time\": xxx, (numeric) The transaction time in " | ||||
"seconds since epoch (Jan 1 1970 GMT).\n" | "seconds since epoch (Jan 1 1970 GMT).\n" | ||||
" \"timereceived\": xxx, (numeric) The time received in " | " \"timereceived\": xxx, (numeric) The time received in " | ||||
"seconds since epoch (Jan 1 1970 GMT). Available for 'send' and " | "seconds since epoch (Jan 1 1970 GMT). Available for 'send' and " | ||||
"'receive' category of transactions.\n" | "'receive' category of transactions.\n" | ||||
" \"abandoned\": xxx, (bool) 'true' if the transaction " | " \"abandoned\": xxx, (bool) 'true' if the transaction " | ||||
"has been abandoned (inputs are respendable). Only available for " | "has been abandoned (inputs are respendable). Only available for " | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static UniValue listsinceblock(const Config &config, | ||||
if (request.params.size() > 2 && request.params[2].get_bool()) { | if (request.params.size() > 2 && request.params[2].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; | int depth = pindex ? (1 + chainActive.Height() - pindex->nHeight) : -1; | ||||
UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
for (std::map<uint256, CWalletTx>::iterator it = | for (std::map<txhash_t, CWalletTx>::iterator it = | ||||
pwalletMain->mapWallet.begin(); | pwalletMain->mapWallet.begin(); | ||||
it != pwalletMain->mapWallet.end(); it++) { | it != pwalletMain->mapWallet.end(); it++) { | ||||
CWalletTx tx = (*it).second; | CWalletTx &tx = (*it).second; | ||||
if (depth == -1 || tx.GetDepthInMainChain() < depth) { | if (depth == -1 || tx.GetDepthInMainChain() < depth) { | ||||
ListTransactions(tx, "*", 0, true, transactions, filter); | ListTransactions(tx, "*", 0, true, transactions, filter); | ||||
} | } | ||||
} | } | ||||
CBlockIndex *pblockLast = | CBlockIndex *pblockLast = | ||||
chainActive[chainActive.Height() + 1 - target_confirms]; | chainActive[chainActive.Height() + 1 - target_confirms]; | ||||
Show All 10 Lines | static UniValue gettransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"gettransaction \"txid\" ( include_watchonly )\n" | "gettransaction \"txhash\" ( include_watchonly )\n" | ||||
"\nGet detailed information about in-wallet transaction <txid>\n" | "\nGet detailed information about in-wallet transaction <txhash>\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction " | "1. \"txhash\" (string, required) The transaction " | ||||
"id\n" | "id\n" | ||||
"2. \"include_watchonly\" (bool, optional, default=false) " | "2. \"include_watchonly\" (bool, optional, default=false) " | ||||
"Whether to include watch-only addresses in balance calculation " | "Whether to include watch-only addresses in balance calculation " | ||||
"and details[]\n" | "and details[]\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{\n" | "{\n" | ||||
" \"amount\" : x.xxx, (numeric) The transaction amount " | " \"amount\" : x.xxx, (numeric) The transaction amount " | ||||
"in " + | "in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"fee\": x.xxx, (numeric) The amount of the fee in " + | " \"fee\": x.xxx, (numeric) The amount of the fee in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
". This is negative and only available for the \n" | ". This is negative and only available for the \n" | ||||
" 'send' category of transactions.\n" | " 'send' category of transactions.\n" | ||||
" \"confirmations\" : n, (numeric) The number of " | " \"confirmations\" : n, (numeric) The number of " | ||||
"confirmations\n" | "confirmations\n" | ||||
" \"blockhash\" : \"hash\", (string) The block hash\n" | " \"blockhash\" : \"hash\", (string) The block hash\n" | ||||
" \"blockindex\" : xx, (numeric) The index of the " | " \"blockindex\" : xx, (numeric) The index of the " | ||||
"transaction in the block that includes it\n" | "transaction in the block that includes it\n" | ||||
" \"blocktime\" : ttt, (numeric) The time in seconds since " | " \"blocktime\" : ttt, (numeric) The time in seconds since " | ||||
"epoch (1 Jan 1970 GMT)\n" | "epoch (1 Jan 1970 GMT)\n" | ||||
" \"txid\" : \"transactionid\", (string) The transaction id.\n" | " \"txhash\" : \"transactionhhash\", (string) The transaction " | ||||
"hash.\n" | |||||
" \"time\" : ttt, (numeric) The transaction time in " | " \"time\" : ttt, (numeric) The transaction time in " | ||||
"seconds since epoch (1 Jan 1970 GMT)\n" | "seconds since epoch (1 Jan 1970 GMT)\n" | ||||
" \"timereceived\" : ttt, (numeric) The time received in " | " \"timereceived\" : ttt, (numeric) The time received in " | ||||
"seconds since epoch (1 Jan 1970 GMT)\n" | "seconds since epoch (1 Jan 1970 GMT)\n" | ||||
" \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether " | " \"bip125-replaceable\": \"yes|no|unknown\", (string) Whether " | ||||
"this transaction could be replaced due to BIP125 " | "this transaction could be replaced due to BIP125 " | ||||
"(replace-by-fee);\n" | "(replace-by-fee);\n" | ||||
" may be unknown " | " may be unknown " | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"\" true") + | "\" true") + | ||||
HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e211" | HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e211" | ||||
"5b9345e16c5cf302fc80e9d5fbf5d48d" | "5b9345e16c5cf302fc80e9d5fbf5d48d" | ||||
"\"")); | "\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
uint256 hash; | txhash_t txhash; | ||||
hash.SetHex(request.params[0].get_str()); | txhash.SetHex(request.params[0].get_str()); | ||||
isminefilter filter = ISMINE_SPENDABLE; | isminefilter filter = ISMINE_SPENDABLE; | ||||
if (request.params.size() > 1 && request.params[1].get_bool()) { | if (request.params.size() > 1 && request.params[1].get_bool()) { | ||||
filter = filter | ISMINE_WATCH_ONLY; | filter = filter | ISMINE_WATCH_ONLY; | ||||
} | } | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
if (!pwalletMain->mapWallet.count(hash)) { | |||||
{ | const CWalletTx *wtx = pwalletMain->GetWalletTx(txhash); | ||||
if (!wtx) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid or non-wallet transaction id"); | "Invalid or non-wallet transaction id"); | ||||
} | } | ||||
} | |||||
const CWalletTx &wtx = pwalletMain->mapWallet[hash]; | CAmount nCredit = wtx->GetCredit(filter); | ||||
CAmount nDebit = wtx->GetDebit(filter); | |||||
CAmount nCredit = wtx.GetCredit(filter); | |||||
CAmount nDebit = wtx.GetDebit(filter); | |||||
CAmount nNet = nCredit - nDebit; | CAmount nNet = nCredit - nDebit; | ||||
CAmount nFee = | CAmount nFee = | ||||
(wtx.IsFromMe(filter) ? wtx.tx->GetValueOut() - nDebit : Amount(0)) | (wtx->IsFromMe(filter) ? wtx->tx->GetValueOut() - nDebit : Amount(0)) | ||||
.GetSatoshis(); | .GetSatoshis(); | ||||
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); | entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); | ||||
if (wtx.IsFromMe(filter)) { | if (wtx->IsFromMe(filter)) { | ||||
entry.push_back(Pair("fee", ValueFromAmount(nFee))); | entry.push_back(Pair("fee", ValueFromAmount(nFee))); | ||||
} | } | ||||
WalletTxToJSON(wtx, entry); | WalletTxToJSON(*wtx, entry); | ||||
UniValue details(UniValue::VARR); | UniValue details(UniValue::VARR); | ||||
ListTransactions(wtx, "*", 0, false, details, filter); | ListTransactions(*wtx, "*", 0, false, details, filter); | ||||
entry.push_back(Pair("details", details)); | entry.push_back(Pair("details", details)); | ||||
std::string strHex = | std::string strHex = | ||||
EncodeHexTx(static_cast<CTransaction>(wtx), RPCSerializationFlags()); | EncodeHexTx(static_cast<CTransaction>(*wtx), RPCSerializationFlags()); | ||||
entry.push_back(Pair("hex", strHex)); | entry.push_back(Pair("hex", strHex)); | ||||
return entry; | return entry; | ||||
} | } | ||||
static UniValue abandontransaction(const Config &config, | static UniValue abandontransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"abandontransaction \"txid\"\n" | "abandontransaction \"txhash\"\n" | ||||
"\nMark in-wallet transaction <txid> as abandoned\n" | "\nMark in-wallet transaction <txhash> as abandoned\n" | ||||
"This will mark this transaction and all its in-wallet descendants " | "This will mark this transaction and all its in-wallet descendants " | ||||
"as abandoned which will allow\n" | "as abandoned which will allow\n" | ||||
"for their inputs to be respent. It can be used to replace " | "for their inputs to be respent. It can be used to replace " | ||||
"\"stuck\" or evicted transactions.\n" | "\"stuck\" or evicted transactions.\n" | ||||
"It only works on transactions which are not included in a block " | "It only works on transactions which are not included in a block " | ||||
"and are not currently in the mempool.\n" | "and are not currently in the mempool.\n" | ||||
"It has no effect on transactions which are already conflicted or " | "It has no effect on transactions which are already conflicted or " | ||||
"abandoned.\n" | "abandoned.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id\n" | "1. \"txhash\" (string, required) The transaction hash\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084" | HelpExampleCli("abandontransaction", "\"1075db55d416d3ca199f55b6084" | ||||
"e2115b9345e16c5cf302fc80e9d5f" | "e2115b9345e16c5cf302fc80e9d5f" | ||||
"bf5d48d\"") + | "bf5d48d\"") + | ||||
HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084" | HelpExampleRpc("abandontransaction", "\"1075db55d416d3ca199f55b6084" | ||||
"e2115b9345e16c5cf302fc80e9d5f" | "e2115b9345e16c5cf302fc80e9d5f" | ||||
"bf5d48d\"")); | "bf5d48d\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
uint256 hash; | txhash_t txhash; | ||||
hash.SetHex(request.params[0].get_str()); | txhash.SetHex(request.params[0].get_str()); | ||||
if (!pwalletMain->mapWallet.count(hash)) { | if (!pwalletMain->GetWalletTx(txhash)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid or non-wallet transaction id"); | "Invalid or non-wallet transaction id"); | ||||
} | } | ||||
if (!pwalletMain->AbandonTransaction(txhash)) { | |||||
if (!pwalletMain->AbandonTransaction(hash)) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction not eligible for abandonment"); | "Transaction not eligible for abandonment"); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
static UniValue backupwallet(const Config &config, | static UniValue backupwallet(const Config &config, | ||||
▲ Show 20 Lines • Show All 338 Lines • ▼ Show 20 Lines | static UniValue lockunspent(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"lockunspent unlock ([{\"txid\":\"txid\",\"vout\":n},...])\n" | "lockunspent unlock " | ||||
"([{\"unspentid\":\"unspentid\",\"vout\":n},...])\n" | |||||
"\nUpdates list of temporarily unspendable outputs.\n" | "\nUpdates list of temporarily unspendable outputs.\n" | ||||
"Temporarily lock (unlock=false) or unlock (unlock=true) specified " | "Temporarily lock (unlock=false) or unlock (unlock=true) specified " | ||||
"transaction outputs.\n" | "transaction outputs.\n" | ||||
"If no transaction outputs are specified when unlocking then all " | "If no transaction outputs are specified when unlocking then all " | ||||
"current locked transaction outputs are unlocked.\n" | "current locked transaction outputs are unlocked.\n" | ||||
"A locked transaction output will not be chosen by automatic coin " | "A locked transaction output will not be chosen by automatic coin " | ||||
"selection, when spending bitcoins.\n" | "selection, when spending bitcoins.\n" | ||||
"Locks are stored in memory only. Nodes start with zero locked " | "Locks are stored in memory only. Nodes start with zero locked " | ||||
"outputs, and the locked output list\n" | "outputs, and the locked output list\n" | ||||
"is always cleared (by virtue of process exit) when a node stops " | "is always cleared (by virtue of process exit) when a node stops " | ||||
"or fails.\n" | "or fails.\n" | ||||
"Also see the listunspent call\n" | "Also see the listunspent call\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. unlock (boolean, required) Whether to unlock (true) " | "1. unlock (boolean, required) Whether to unlock (true) " | ||||
"or lock (false) the specified transactions\n" | "or lock (false) the specified transactions\n" | ||||
"2. \"transactions\" (string, optional) A json array of objects. " | "2. \"transactions\" (string, optional) A json array of objects. " | ||||
"Each object the txid (string) vout (numeric)\n" | "Each object the unspentid (string) vout (numeric)\n" | ||||
" [ (json array of json objects)\n" | " [ (json array of json objects)\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\":\"id\", (string) The transaction id\n" | " \"unspentid\":\"id\", (string) The unpent transaction " | ||||
"id\n" | |||||
" \"vout\": n (numeric) The output number\n" | " \"vout\": n (numeric) The output number\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ]\n" | " ]\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"true|false (boolean) Whether the command was successful or " | "true|false (boolean) Whether the command was successful or " | ||||
"not\n" | "not\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nList the unspent transactions\n" + | "\nList the unspent transactions\n" + | ||||
HelpExampleCli("listunspent", "") + | HelpExampleCli("listunspent", "") + | ||||
"\nLock an unspent transaction\n" + | "\nLock an unspent transaction\n" + | ||||
HelpExampleCli("lockunspent", "false " | HelpExampleCli("lockunspent", "false " | ||||
"\"[{\\\"txid\\\":" | "\"[{\\\"unspentid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nList the locked transactions\n" + | "\nList the locked transactions\n" + | ||||
HelpExampleCli("listlockunspent", "") + | HelpExampleCli("listlockunspent", "") + | ||||
"\nUnlock the transaction again\n" + | "\nUnlock the transaction again\n" + | ||||
HelpExampleCli("lockunspent", "true " | HelpExampleCli("lockunspent", "true " | ||||
"\"[{\\\"txid\\\":" | "\"[{\\\"unspentid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nAs a json rpc call\n" + | "\nAs a json rpc call\n" + | ||||
HelpExampleRpc("lockunspent", "false, " | HelpExampleRpc("lockunspent", "false, " | ||||
"\"[{\\\"txid\\\":" | "\"[{\\\"unspentid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"")); | ",\\\"vout\\\":1}]\"")); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
if (request.params.size() == 1) { | if (request.params.size() == 1) { | ||||
Show All 16 Lines | for (size_t idx = 0; idx < outputs.size(); idx++) { | ||||
const UniValue &output = outputs[idx]; | const UniValue &output = outputs[idx]; | ||||
if (!output.isObject()) { | if (!output.isObject()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, expected object"); | "Invalid parameter, expected object"); | ||||
} | } | ||||
const UniValue &o = output.get_obj(); | const UniValue &o = output.get_obj(); | ||||
RPCTypeCheckObj(o, { | RPCTypeCheckObj(o, { | ||||
{"txid", UniValueType(UniValue::VSTR)}, | {"unspentid", UniValueType(UniValue::VSTR)}, | ||||
{"vout", UniValueType(UniValue::VNUM)}, | {"vout", UniValueType(UniValue::VNUM)}, | ||||
}); | }); | ||||
std::string txid = find_value(o, "txid").get_str(); | std::string unspentid = find_value(o, "unspentid").get_str(); | ||||
if (!IsHex(txid)) { | if (!IsHex(unspentid)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, expected hex txid"); | "Invalid parameter, expected hex unspentid"); | ||||
} | } | ||||
int nOutput = find_value(o, "vout").get_int(); | int nOutput = find_value(o, "vout").get_int(); | ||||
if (nOutput < 0) { | if (nOutput < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, vout must be positive"); | "Invalid parameter, vout must be positive"); | ||||
} | } | ||||
COutPoint outpt(uint256S(txid), nOutput); | const CWalletTx *wtx = | ||||
pwalletMain->GetWalletTx(unspentid_t(uint256S(unspentid))); | |||||
if (!wtx) | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Invalid parameter, unspentid unknown"); | |||||
COutPoint outpt(wtx->tx->Getunspentid(), nOutput); | |||||
if (fUnlock) { | if (fUnlock) { | ||||
pwalletMain->UnlockCoin(outpt); | pwalletMain->UnlockCoin(outpt); | ||||
} else { | } else { | ||||
pwalletMain->LockCoin(outpt); | pwalletMain->LockCoin(outpt); | ||||
} | } | ||||
} | } | ||||
Show All 10 Lines | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"listlockunspent\n" | "listlockunspent\n" | ||||
"\nReturns list of temporarily unspendable outputs.\n" | "\nReturns list of temporarily unspendable outputs.\n" | ||||
"See the lockunspent call to lock and unlock transactions for " | "See the lockunspent call to lock and unlock transactions for " | ||||
"spending.\n" | "spending.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\" : \"transactionid\", (string) The transaction id " | " \"unspentid\" : \"transactionid\", (string) The unpend " | ||||
"locked\n" | "transaction " | ||||
"id locked\n" | |||||
" \"vout\" : n (numeric) The vout value\n" | " \"vout\" : n (numeric) The vout value\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" | "\nExamples:\n" | ||||
"\nList the unspent transactions\n" + | "\nList the unspent transactions\n" + | ||||
HelpExampleCli("listunspent", "") + | HelpExampleCli("listunspent", "") + | ||||
"\nLock an unspent transaction\n" + | "\nLock an unspent transaction\n" + | ||||
HelpExampleCli("lockunspent", "false " | HelpExampleCli("lockunspent", "false " | ||||
"\"[{\\\"txid\\\":" | "\"[{\\\"unspentid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nList the locked transactions\n" + | "\nList the locked transactions\n" + | ||||
HelpExampleCli("listlockunspent", "") + | HelpExampleCli("listlockunspent", "") + | ||||
"\nUnlock the transaction again\n" + | "\nUnlock the transaction again\n" + | ||||
HelpExampleCli("lockunspent", "true " | HelpExampleCli("lockunspent", "true " | ||||
"\"[{\\\"txid\\\":" | "\"[{\\\"unspentid\\\":" | ||||
"\\\"a08e6907dbbd3d809776dbfc5d82e371" | "\\\"a08e6907dbbd3d809776dbfc5d82e371" | ||||
"b764ed838b5655e72f463568df1aadf0\\\"" | "b764ed838b5655e72f463568df1aadf0\\\"" | ||||
",\\\"vout\\\":1}]\"") + | ",\\\"vout\\\":1}]\"") + | ||||
"\nAs a json rpc call\n" + HelpExampleRpc("listlockunspent", "")); | "\nAs a json rpc call\n" + HelpExampleRpc("listlockunspent", "")); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
std::vector<COutPoint> vOutpts; | std::vector<COutPoint> vOutpts; | ||||
pwalletMain->ListLockedCoins(vOutpts); | pwalletMain->ListLockedCoins(vOutpts); | ||||
UniValue ret(UniValue::VARR); | UniValue ret(UniValue::VARR); | ||||
for (COutPoint &outpt : vOutpts) { | for (COutPoint &outpt : vOutpts) { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
o.push_back(Pair("txid", outpt.hash.GetHex())); | o.push_back(Pair("unspentid", outpt.unspentid.GetHex())); | ||||
o.push_back(Pair("vout", (int)outpt.n)); | o.push_back(Pair("vout", (int)outpt.n)); | ||||
ret.push_back(o); | ret.push_back(o); | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue settxfee(const Config &config, const JSONRPCRequest &request) { | static UniValue settxfee(const Config &config, const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | static UniValue resendwallettransactions(const Config &config, | ||||
if (!g_connman) { | if (!g_connman) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_CLIENT_P2P_DISABLED, | RPC_CLIENT_P2P_DISABLED, | ||||
"Error: Peer-to-peer functionality missing or disabled"); | "Error: Peer-to-peer functionality missing or disabled"); | ||||
} | } | ||||
LOCK2(cs_main, pwalletMain->cs_wallet); | LOCK2(cs_main, pwalletMain->cs_wallet); | ||||
std::vector<uint256> txids = | std::vector<txhash_t> txhashes = | ||||
pwalletMain->ResendWalletTransactionsBefore(GetTime(), g_connman.get()); | pwalletMain->ResendWalletTransactionsBefore(GetTime(), g_connman.get()); | ||||
UniValue result(UniValue::VARR); | UniValue result(UniValue::VARR); | ||||
for (const uint256 &txid : txids) { | for (const txhash_t &txhash : txhashes) { | ||||
result.push_back(txid.ToString()); | result.push_back(txhash.ToString()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
static UniValue listunspent(const Config &config, | static UniValue listunspent(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (!EnsureWalletIsAvailable(request.fHelp)) { | if (!EnsureWalletIsAvailable(request.fHelp)) { | ||||
Show All 24 Lines | if (request.fHelp || request.params.size() > 4) { | ||||
" because they come from unconfirmed untrusted " | " because they come from unconfirmed untrusted " | ||||
"transactions or unconfirmed\n" | "transactions or unconfirmed\n" | ||||
" replacement transactions (cases where we are " | " replacement transactions (cases where we are " | ||||
"less sure that a conflicting\n" | "less sure that a conflicting\n" | ||||
" transaction won't be mined).\n" | " transaction won't be mined).\n" | ||||
"\nResult\n" | "\nResult\n" | ||||
"[ (array of json object)\n" | "[ (array of json object)\n" | ||||
" {\n" | " {\n" | ||||
" \"txid\" : \"txid\", (string) the transaction id \n" | " \"unspentid\" : \"unspentid\", (string) the unpent " | ||||
"transaction id \n" | |||||
" \"vout\" : n, (numeric) the vout value\n" | " \"vout\" : n, (numeric) the vout value\n" | ||||
" \"address\" : \"address\", (string) the bitcoin address\n" | " \"address\" : \"address\", (string) the bitcoin address\n" | ||||
" \"account\" : \"account\", (string) DEPRECATED. The " | " \"account\" : \"account\", (string) DEPRECATED. The " | ||||
"associated account, or \"\" for the default account\n" | "associated account, or \"\" for the default account\n" | ||||
" \"scriptPubKey\" : \"key\", (string) the script key\n" | " \"scriptPubKey\" : \"key\", (string) the script key\n" | ||||
" \"amount\" : x.xxx, (numeric) the transaction output " | " \"amount\" : x.xxx, (numeric) the transaction output " | ||||
"amount in " + | "amount in " + | ||||
CURRENCY_UNIT + "\n" | CURRENCY_UNIT + "\n" | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | for (const COutput &out : vecOutputs) { | ||||
const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey; | const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey; | ||||
bool fValidAddress = ExtractDestination(scriptPubKey, address); | bool fValidAddress = ExtractDestination(scriptPubKey, address); | ||||
if (destinations.size() && | if (destinations.size() && | ||||
(!fValidAddress || !destinations.count(address))) | (!fValidAddress || !destinations.count(address))) | ||||
continue; | continue; | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
entry.push_back(Pair("txid", out.tx->GetId().GetHex())); | entry.push_back(Pair("unspentid", out.tx->tx->Getunspentid().GetHex())); | ||||
entry.push_back(Pair("vout", out.i)); | entry.push_back(Pair("vout", out.i)); | ||||
if (fValidAddress) { | if (fValidAddress) { | ||||
entry.push_back(Pair("address", EncodeDestination(address))); | entry.push_back(Pair("address", EncodeDestination(address))); | ||||
if (pwalletMain->mapAddressBook.count(address)) { | if (pwalletMain->mapAddressBook.count(address)) { | ||||
entry.push_back( | entry.push_back( | ||||
Pair("account", pwalletMain->mapAddressBook[address].name)); | Pair("account", pwalletMain->mapAddressBook[address].name)); | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) okSafeMode | // category name actor (function) okSafeMode | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "rawtransactions", "fundrawtransaction", fundrawtransaction, false, {"hexstring","options"} }, | { "rawtransactions", "fundrawtransaction", fundrawtransaction, false, {"hexstring","options"} }, | ||||
{ "hidden", "resendwallettransactions", resendwallettransactions, true, {} }, | { "hidden", "resendwallettransactions", resendwallettransactions, true, {} }, | ||||
{ "wallet", "abandontransaction", abandontransaction, false, {"txid"} }, | { "wallet", "abandontransaction", abandontransaction, false, {"txhash"} }, | ||||
{ "wallet", "addmultisigaddress", addmultisigaddress, true, {"nrequired","keys","account"} }, | { "wallet", "addmultisigaddress", addmultisigaddress, true, {"nrequired","keys","account"} }, | ||||
{ "wallet", "backupwallet", backupwallet, true, {"destination"} }, | { "wallet", "backupwallet", backupwallet, true, {"destination"} }, | ||||
{ "wallet", "encryptwallet", encryptwallet, true, {"passphrase"} }, | { "wallet", "encryptwallet", encryptwallet, true, {"passphrase"} }, | ||||
{ "wallet", "getaccountaddress", getaccountaddress, true, {"account"} }, | { "wallet", "getaccountaddress", getaccountaddress, true, {"account"} }, | ||||
{ "wallet", "getaccount", getaccount, true, {"address"} }, | { "wallet", "getaccount", getaccount, true, {"address"} }, | ||||
{ "wallet", "getaddressesbyaccount", getaddressesbyaccount, true, {"account"} }, | { "wallet", "getaddressesbyaccount", getaddressesbyaccount, true, {"account"} }, | ||||
{ "wallet", "getbalance", getbalance, false, {"account","minconf","include_watchonly"} }, | { "wallet", "getbalance", getbalance, false, {"account","minconf","include_watchonly"} }, | ||||
{ "wallet", "getnewaddress", getnewaddress, true, {"account"} }, | { "wallet", "getnewaddress", getnewaddress, true, {"account"} }, | ||||
{ "wallet", "getrawchangeaddress", getrawchangeaddress, true, {} }, | { "wallet", "getrawchangeaddress", getrawchangeaddress, true, {} }, | ||||
{ "wallet", "getreceivedbyaccount", getreceivedbyaccount, false, {"account","minconf"} }, | { "wallet", "getreceivedbyaccount", getreceivedbyaccount, false, {"account","minconf"} }, | ||||
{ "wallet", "getreceivedbyaddress", getreceivedbyaddress, false, {"address","minconf"} }, | { "wallet", "getreceivedbyaddress", getreceivedbyaddress, false, {"address","minconf"} }, | ||||
{ "wallet", "gettransaction", gettransaction, false, {"txid","include_watchonly"} }, | { "wallet", "gettransaction", gettransaction, false, {"txhash","include_watchonly"} }, | ||||
{ "wallet", "getunconfirmedbalance", getunconfirmedbalance, false, {} }, | { "wallet", "getunconfirmedbalance", getunconfirmedbalance, false, {} }, | ||||
{ "wallet", "getwalletinfo", getwalletinfo, false, {} }, | { "wallet", "getwalletinfo", getwalletinfo, false, {} }, | ||||
{ "wallet", "keypoolrefill", keypoolrefill, true, {"newsize"} }, | { "wallet", "keypoolrefill", keypoolrefill, true, {"newsize"} }, | ||||
{ "wallet", "listaccounts", listaccounts, false, {"minconf","include_watchonly"} }, | { "wallet", "listaccounts", listaccounts, false, {"minconf","include_watchonly"} }, | ||||
{ "wallet", "listaddressgroupings", listaddressgroupings, false, {} }, | { "wallet", "listaddressgroupings", listaddressgroupings, false, {} }, | ||||
{ "wallet", "listlockunspent", listlockunspent, false, {} }, | { "wallet", "listlockunspent", listlockunspent, false, {} }, | ||||
{ "wallet", "listreceivedbyaccount", listreceivedbyaccount, false, {"minconf","include_empty","include_watchonly"} }, | { "wallet", "listreceivedbyaccount", listreceivedbyaccount, false, {"minconf","include_empty","include_watchonly"} }, | ||||
{ "wallet", "listreceivedbyaddress", listreceivedbyaddress, false, {"minconf","include_empty","include_watchonly"} }, | { "wallet", "listreceivedbyaddress", listreceivedbyaddress, false, {"minconf","include_empty","include_watchonly"} }, | ||||
Show All 26 Lines |