31 class PendingWalletTxImpl :
public PendingWalletTx
42 std::string& reject_reason)
override 63 result.txin_is_mine.reserve(wtx.tx->vin.size());
64 for (
const auto& txin : wtx.tx->vin) {
65 result.txin_is_mine.emplace_back(wallet.IsMine(txin));
67 result.txout_is_mine.reserve(wtx.tx->vout.size());
68 result.txout_address.reserve(wtx.tx->vout.size());
69 result.txout_address_is_mine.reserve(wtx.tx->vout.size());
70 for (
const auto& txout : wtx.tx->vout) {
71 result.txout_is_mine.emplace_back(wallet.IsMine(txout));
72 result.txout_address.emplace_back();
73 result.txout_address_is_mine.emplace_back(
ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
74 IsMine(wallet, result.txout_address.back()) :
79 result.change = wtx.GetChange();
80 result.time = wtx.GetTxTime();
81 result.value_map = wtx.mapValue;
82 result.is_coinbase = wtx.IsCoinBase();
89 WalletTxStatus result;
92 result.block_height = (block ? block->
nHeight : std::numeric_limits<int>::max());
93 result.blocks_to_maturity = wtx.GetBlocksToMaturity();
94 result.depth_in_main_chain = wtx.GetDepthInMainChain();
95 result.time_received = wtx.nTimeReceived;
96 result.lock_time = wtx.tx->nLockTime;
98 result.is_trusted = wtx.IsTrusted();
99 result.is_abandoned = wtx.isAbandoned();
100 result.is_coinbase = wtx.IsCoinBase();
101 result.is_in_main_chain = wtx.IsInMainChain();
109 result.txout = wtx.tx->vout[n];
110 result.time = wtx.GetTxTime();
111 result.depth_in_main_chain = depth;
112 result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
116 class WalletImpl :
public Wallet
119 explicit WalletImpl(
const std::shared_ptr<CWallet>& wallet) :
m_shared_wallet(wallet),
m_wallet(*wallet.get()) {}
121 bool encryptWallet(
const SecureString& wallet_passphrase)
override 129 bool changeWalletPassphrase(
const SecureString& old_wallet_passphrase,
135 bool backupWallet(
const std::string& filename)
override {
return m_wallet.
BackupWallet(filename); }
137 bool getKeyFromPool(
bool internal,
CPubKey& pub_key)
override 145 bool setAddressBook(
const CTxDestination& dest,
const std::string&
name,
const std::string& purpose)
override 156 std::string* purpose)
override 164 *
name = it->second.name;
170 *purpose = it->second.purpose;
174 std::vector<WalletAddress> getAddresses()
override 177 std::vector<WalletAddress> result;
179 result.emplace_back(item.first,
IsMine(
m_wallet, item.first), item.second.name, item.second.purpose);
184 bool addDestData(
const CTxDestination& dest,
const std::string& key,
const std::string& value)
override 189 bool eraseDestData(
const CTxDestination& dest,
const std::string& key)
override 194 std::vector<std::string> getDestValues(
const std::string&
prefix)
override 198 void lockCoin(
const COutPoint& output)
override 203 void unlockCoin(
const COutPoint& output)
override 208 bool isLockedCoin(
const COutPoint& output)
override 213 void listLockedCoins(std::vector<COutPoint>& outputs)
override 218 std::unique_ptr<PendingWalletTx> createTransaction(
const std::vector<CRecipient>& recipients,
223 std::string& fail_reason)
override 226 auto pending = MakeUnique<PendingWalletTxImpl>(
m_wallet);
228 fail_reason, coin_control, sign)) {
231 return std::move(pending);
234 bool abandonTransaction(
const uint256& txid)
override 239 bool transactionCanBeBumped(
const uint256& txid)
override 243 bool createBumpTransaction(
const uint256& txid,
246 std::vector<std::string>& errors,
255 bool commitBumpTransaction(
const uint256& txid,
257 std::vector<std::string>& errors,
266 auto mi =
m_wallet.mapWallet.find(txid);
267 if (mi !=
m_wallet.mapWallet.end()) {
268 return mi->second.tx;
272 WalletTx getWalletTx(
const uint256& txid)
override 275 auto mi =
m_wallet.mapWallet.find(txid);
276 if (mi !=
m_wallet.mapWallet.end()) {
277 return MakeWalletTx(
m_wallet, mi->second);
281 std::vector<WalletTx> getWalletTxs()
override 284 std::vector<WalletTx> result;
285 result.reserve(
m_wallet.mapWallet.size());
286 for (
const auto& entry :
m_wallet.mapWallet) {
287 result.emplace_back(MakeWalletTx(
m_wallet, entry.second));
291 bool tryGetTxStatus(
const uint256& txid,
294 int64_t& adjusted_time)
override 301 if (!locked_wallet) {
304 auto mi =
m_wallet.mapWallet.find(txid);
305 if (mi ==
m_wallet.mapWallet.end()) {
310 tx_status = MakeWalletTxStatus(mi->second);
313 WalletTx getWalletTxDetails(
const uint256& txid,
314 WalletTxStatus& tx_status,
318 int64_t& adjusted_time)
override 321 auto mi =
m_wallet.mapWallet.find(txid);
322 if (mi !=
m_wallet.mapWallet.end()) {
325 in_mempool = mi->second.InMempool();
326 order_form = mi->second.vOrderForm;
327 tx_status = MakeWalletTxStatus(mi->second);
328 return MakeWalletTx(
m_wallet, mi->second);
332 WalletBalances getBalances()
override 334 WalletBalances result;
339 if (result.have_watch_only) {
346 bool tryGetBalances(WalletBalances& balances,
int& num_blocks)
override 349 if (!locked_chain)
return false;
351 if (!locked_wallet) {
354 balances = getBalances();
383 CoinsList listCoins()
override 388 auto& group = result[entry.first];
389 for (
const auto& coin : entry.second) {
391 COutPoint(coin.tx->GetHash(), coin.i), MakeWalletTxOut(
m_wallet, *coin.tx, coin.i, coin.nDepth));
396 std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
override 399 std::vector<WalletTxOut> result;
400 result.reserve(outputs.size());
401 for (
const auto& output : outputs) {
402 result.emplace_back();
404 if (it !=
m_wallet.mapWallet.end()) {
405 int depth = it->second.GetDepthInMainChain();
407 result.back() = MakeWalletTxOut(
m_wallet, it->second, output.
n, depth);
414 CAmount getMinimumFee(
unsigned int tx_bytes,
416 int* returned_target,
423 if (reason) *reason = fee_calc.
reason;
431 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override 435 std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
override 439 std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
override 443 std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
override 447 const std::string& purpose,
ChangeType status) { fn(address, label, is_mine, purpose, status); }));
449 std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
override 454 std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override 465 std::unique_ptr<Wallet>
MakeWallet(
const std::shared_ptr<CWallet>& wallet) {
return MakeUnique<WalletImpl>(wallet); }
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost)
Compute the virtual transaction size (weight reinterpreted as bytes).
CAmount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control, const CTxMemPool &pool, const CBlockPolicyEstimator &estimator, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
Result CreateTransaction(const CWallet *wallet, const uint256 &txid, const CCoinControl &coin_control, CAmount total_fee, std::vector< std::string > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction.
OutputType m_default_change_type
CAmount GetImmatureBalance() const
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
void UnlockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
#define TRY_LOCK(cs, name)
CAmount GetAvailableBalance(const CCoinControl *coinControl=nullptr) const
std::map< CTxDestination, CAddressBookData > mapAddressBook
std::vector< std::string > GetDestValues(const std::string &prefix) const
Get all destination values matching a prefix.
int Height() const
Return the maximal height in the chain.
bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector< std::pair< std::string, std::string >> orderForm, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
uint8_t isminefilter
used for bitflags of isminetype
bool IsWalletFlagSet(uint64_t flag)
check if a certain wallet flag is set
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
std::map< std::string, std::string > WalletValueMap
CAmount GetUnconfirmedWatchOnlyBalance() const
Keystore which keeps the private keys encrypted.
bool EncryptWallet(const SecureString &strWalletPassphrase)
std::shared_ptr< const CTransaction > CTransactionRef
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
int64_t CAmount
Amount in satoshis (Can be negative)
boost::signals2::signal< void()> NotifyUnload
Wallet is about to be unloaded.
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
CBlockPolicyEstimator feeEstimator
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
bool IsLockedCoin(uint256 hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool DelAddressBook(const CTxDestination &address)
bool SignTransaction(CWallet *wallet, CMutableTransaction &mtx)
Sign the new transaction,.
bool CheckFinalTx(const CTransaction &tx, int flags)
Transaction validation functions.
CAmount GetBalance(const isminefilter &filter=ISMINE_SPENDABLE, const int min_depth=0) const
bool AbandonTransaction(const uint256 &hashTx)
ChangeType
General change type (added, updated, removed).
isminetype
IsMine() return codes.
An input of a transaction.
boost::variant< CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
OutputType m_default_address_type
An encapsulated public key.
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
std::string GetRejectReason() const
CAmount GetUnconfirmedBalance() const
std::map< CTxDestination, std::vector< COutput > > ListCoins() const EXCLUSIVE_LOCKS_REQUIRED(cs_main
Return list of available coins and locked coins grouped by non-change output address.
CAmount GetImmatureWatchOnlyBalance() const
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
bool GetKey(const CKeyID &address, CKey &keyOut) const override
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
CCriticalSection cs_wallet
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
Return implementation of Wallet interface.
A transaction with a bunch of additional info that only the owner cares about.
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
void LockCoin(const COutPoint &output) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CTransactionRef &tx, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
bool TransactionCanBeBumped(const CWallet *wallet, const uint256 &txid)
Return whether transaction can be bumped.
Capture information about block/transaction validation.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
unsigned int m_confirm_target
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
CAmount GetDebit(const CTxIn &txin, const isminefilter &filter) const
Returns amount of debit if the input matches the filter, otherwise returns 0.
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
A key allocated from the key pool.
Result CommitTransaction(CWallet *wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< std::string > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
The block chain is a tree shaped structure starting with the genesis block at the root...
int64_t GetAdjustedTime()
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey)
A reference to a CKey: the Hash360 of its serialized public key.
void LearnRelatedScripts(const CPubKey &key, OutputType)
Explicitly make the wallet learn the related scripts for outputs to the given key.
std::shared_ptr< CWallet > m_shared_wallet
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
std::unique_ptr< CConnman > g_connman
std::vector< std::pair< std::string, std::string > > WalletOrderForm
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
bool GetKeyFromPool(CPubKey &key, bool internal=false)
A mutable version of CTransaction.
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
An encapsulated private key.
bool HaveWatchOnly(const CScript &dest) const override
The basic transaction that is broadcasted on the network and contained in blocks. ...
int nHeight
height of the entry in the chain. The genesis block has height 0
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, and saves it to disk.
CAmount GetCredit(const CTxOut &txout, const isminefilter &filter) const
isminetype IsMine(const CTxIn &txin) const
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).
bool BackupWallet(const std::string &strDest)
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Updated transaction status.
bool Unlock(const SecureString &strWalletPassphrase)