Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show All 32 Lines | |||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <wallet/walletdb.h> | #include <wallet/walletdb.h> | ||||
#include <wallet/walletutil.h> | #include <wallet/walletutil.h> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <event2/http.h> | #include <event2/http.h> | ||||
using interfaces::FoundBlock; | |||||
static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; | static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; | ||||
static inline bool GetAvoidReuseFlag(CWallet *const pwallet, | static inline bool GetAvoidReuseFlag(CWallet *const pwallet, | ||||
const UniValue ¶m) { | const UniValue ¶m) { | ||||
bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | ||||
bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); | bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); | ||||
if (avoid_reuse && !can_avoid_reuse) { | if (avoid_reuse && !can_avoid_reuse) { | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | static void WalletTxToJSON(interfaces::Chain &chain, | ||||
if (wtx.IsCoinBase()) { | if (wtx.IsCoinBase()) { | ||||
entry.pushKV("generated", true); | entry.pushKV("generated", true); | ||||
} | } | ||||
if (confirms > 0) { | if (confirms > 0) { | ||||
entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex()); | entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex()); | ||||
entry.pushKV("blockheight", wtx.m_confirm.block_height); | entry.pushKV("blockheight", wtx.m_confirm.block_height); | ||||
entry.pushKV("blockindex", wtx.m_confirm.nIndex); | entry.pushKV("blockindex", wtx.m_confirm.nIndex); | ||||
int64_t block_time; | int64_t block_time; | ||||
bool found_block = chain.findBlock(wtx.m_confirm.hashBlock, | CHECK_NONFATAL(chain.findBlock(wtx.m_confirm.hashBlock, | ||||
nullptr /* block */, &block_time); | FoundBlock().time(block_time))); | ||||
CHECK_NONFATAL(found_block); | |||||
entry.pushKV("blocktime", block_time); | entry.pushKV("blocktime", block_time); | ||||
} else { | } else { | ||||
entry.pushKV("trusted", wtx.IsTrusted(locked_chain)); | entry.pushKV("trusted", wtx.IsTrusted(locked_chain)); | ||||
} | } | ||||
uint256 hash = wtx.GetId(); | uint256 hash = wtx.GetId(); | ||||
entry.pushKV("txid", hash.GetHex()); | entry.pushKV("txid", hash.GetHex()); | ||||
UniValue conflicts(UniValue::VARR); | UniValue conflicts(UniValue::VARR); | ||||
for (const uint256 &conflict : wtx.GetConflicts()) { | for (const uint256 &conflict : wtx.GetConflicts()) { | ||||
▲ Show 20 Lines • Show All 1,718 Lines • ▼ Show 20 Lines | for (const std::pair<const TxId, CWalletTx> &pairWtx : pwallet->mapWallet) { | ||||
} | } | ||||
} | } | ||||
// when a reorg'd block is requested, we also list any relevant transactions | // when a reorg'd block is requested, we also list any relevant transactions | ||||
// in the blocks of the chain that was detached | // in the blocks of the chain that was detached | ||||
UniValue removed(UniValue::VARR); | UniValue removed(UniValue::VARR); | ||||
while (include_removed && altheight && *altheight > *height) { | while (include_removed && altheight && *altheight > *height) { | ||||
CBlock block; | CBlock block; | ||||
if (!pwallet->chain().findBlock(blockId, &block) || block.IsNull()) { | if (!pwallet->chain().findBlock(blockId, FoundBlock().data(block)) || | ||||
block.IsNull()) { | |||||
throw JSONRPCError(RPC_INTERNAL_ERROR, | throw JSONRPCError(RPC_INTERNAL_ERROR, | ||||
"Can't read block from disk"); | "Can't read block from disk"); | ||||
} | } | ||||
for (const CTransactionRef &tx : block.vtx) { | for (const CTransactionRef &tx : block.vtx) { | ||||
auto it = pwallet->mapWallet.find(tx->GetId()); | auto it = pwallet->mapWallet.find(tx->GetId()); | ||||
if (it != pwallet->mapWallet.end()) { | if (it != pwallet->mapWallet.end()) { | ||||
// We want all transactions regardless of confirmation count to | // We want all transactions regardless of confirmation count to | ||||
// appear here, even negative confirmation ones, hence the big | // appear here, even negative confirmation ones, hence the big | ||||
▲ Show 20 Lines • Show All 2,970 Lines • Show Last 20 Lines |