7#include <chainparams.h>
54 for (
const auto &
txin : wtx.
tx->vin) {
60 for (
const auto &txout : wtx.
tx->vout) {
87 : std::numeric_limits<int>::max();
106 result.
txout = wtx.
tx->vout[n];
113 class WalletImpl :
public Wallet {
115 explicit WalletImpl(
const std::shared_ptr<CWallet> &
wallet)
121 bool isCrypted()
override {
return m_wallet->IsCrypted(); }
122 bool lock()
override {
return m_wallet->Lock(); }
126 bool isLocked()
override {
return m_wallet->IsLocked(); }
127 bool changeWalletPassphrase(
133 void abortRescan()
override {
m_wallet->AbortRescan(); }
134 bool backupWallet(
const std::string &filename)
override {
135 return m_wallet->BackupWallet(filename);
137 std::string getWalletName()
override {
return m_wallet->GetName(); }
138 bool getNewDestination(
const OutputType type,
const std::string label,
142 return m_wallet->GetNewDestination(type, label, dest,
error);
147 bool getPubKey(
const CScript &script,
const CKeyID &address,
149 std::unique_ptr<SigningProvider> provider =
150 m_wallet->GetSolvingProvider(script);
152 return provider->GetPubKey(address,
pub_key);
158 std::string &
str_sig)
override {
165 bool haveWatchOnly()
override {
168 return spk_man->HaveWatchOnly();
173 const std::string &purpose)
override {
177 return m_wallet->DelAddressBook(dest);
180 isminetype *is_mine, std::string *purpose)
override {
182 auto it =
m_wallet->m_address_book.find(dest);
183 if (it ==
m_wallet->m_address_book.end() || it->second.IsChange()) {
187 *
name = it->second.GetLabel();
193 *purpose = it->second.purpose;
197 std::vector<WalletAddress> getAddresses()
override {
199 std::vector<WalletAddress> result;
200 for (
const auto &item :
m_wallet->m_address_book) {
201 if (item.second.IsChange()) {
204 result.emplace_back(item.first,
m_wallet->IsMine(item.first),
205 item.second.GetLabel(),
206 item.second.purpose);
210 bool addDestData(
const CTxDestination &dest,
const std::string &key,
211 const std::string &value)
override {
214 return m_wallet->AddDestData(batch, dest, key, value);
217 const std::string &key)
override {
220 return m_wallet->EraseDestData(batch, dest, key);
222 std::vector<std::string>
223 getDestValues(
const std::string &
prefix)
override {
227 void lockCoin(
const COutPoint &output)
override {
231 void unlockCoin(
const COutPoint &output)
override {
233 return m_wallet->UnlockCoin(output);
235 bool isLockedCoin(
const COutPoint &output)
override {
237 return m_wallet->IsLockedCoin(output);
239 void listLockedCoins(std::vector<COutPoint> &outputs)
override {
241 return m_wallet->ListLockedCoins(outputs);
244 createTransaction(
const std::vector<CRecipient> &recipients,
259 m_wallet->CommitTransaction(std::move(tx), std::move(value_map),
262 bool transactionCanBeAbandoned(
const TxId &txid)
override {
263 return m_wallet->TransactionCanBeAbandoned(txid);
265 bool abandonTransaction(
const TxId &txid)
override {
267 return m_wallet->AbandonTransaction(txid);
273 return mi->second.tx;
285 std::vector<WalletTx> getWalletTxs()
override {
287 std::vector<WalletTx> result;
288 result.reserve(
m_wallet->mapWallet.size());
289 for (
const auto &entry :
m_wallet->mapWallet) {
294 bool tryGetTxStatus(
const TxId &txid,
330 bool &complete)
const override {
331 return m_wallet->FillPSBT(
psbtx, complete, sighash_type, sign,
344 bal.m_watchonly_untrusted_pending;
355 block_hash =
m_wallet->GetLastBlockHash();
359 Amount getBalance()
override {
381 CoinsList listCoins()
override {
385 auto &
group = result[entry.first];
386 for (
const auto &coin : entry.second) {
387 group.emplace_back(COutPoint(coin.tx->GetId(), coin.i),
389 coin.i, coin.nDepth));
394 std::vector<WalletTxOut>
395 getCoins(
const std::vector<COutPoint> &outputs)
override {
397 std::vector<WalletTxOut> result;
398 result.reserve(outputs.size());
399 for (
const auto &output : outputs) {
400 result.emplace_back();
401 auto it =
m_wallet->mapWallet.find(output.GetTxId());
402 if (it !=
m_wallet->mapWallet.end()) {
403 int depth =
m_wallet->GetTxDepthInMainChain(it->second);
406 output.GetN(), depth);
412 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
414 return m_wallet->m_default_address_type;
416 bool canGetAddresses()
const override {
419 bool privateKeysDisabled()
override {
422 Amount getDefaultMaxTxFee()
override {
423 return m_wallet->m_default_max_tx_fee;
425 void remove()
override {
428 bool isLegacy()
override {
return m_wallet->IsLegacy(); }
429 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override {
430 return MakeHandler(
m_wallet->NotifyUnload.connect(fn));
432 std::unique_ptr<Handler>
433 handleShowProgress(ShowProgressFn fn)
override {
434 return MakeHandler(
m_wallet->ShowProgress.connect(fn));
436 std::unique_ptr<Handler>
437 handleStatusChanged(StatusChangedFn fn)
override {
438 return MakeHandler(
m_wallet->NotifyStatusChanged.connect(
441 std::unique_ptr<Handler>
442 handleAddressBookChanged(AddressBookChangedFn fn)
override {
443 return MakeHandler(
m_wallet->NotifyAddressBookChanged.connect(
445 const std::string &label,
bool is_mine,
446 const std::string &purpose,
ChangeType status) {
447 fn(address, label, is_mine, purpose, status);
450 std::unique_ptr<Handler>
451 handleTransactionChanged(TransactionChangedFn fn)
override {
452 return MakeHandler(
m_wallet->NotifyTransactionChanged.connect(
457 std::unique_ptr<Handler>
458 handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override {
459 return MakeHandler(
m_wallet->NotifyWatchonlyChanged.connect(fn));
461 std::unique_ptr<Handler>
462 handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override {
464 m_wallet->NotifyCanGetAddressesChanged.connect(fn));
494 JSONRPCRequest wallet_request = request;
495 wallet_request.context = &m_context;
496 return command.actor(config, wallet_request, result,
505 void registerRpcs()
override {
520 std::unique_ptr<Wallet>
523 std::vector<bilingual_str> &
warnings)
override {
524 std::shared_ptr<CWallet>
wallet;
535 std::unique_ptr<Wallet>
537 std::vector<bilingual_str> &
warnings)
override {
545 std::string getWalletDir()
override {
548 std::vector<std::string> listWalletDir()
override {
549 std::vector<std::string>
paths;
556 std::vector<std::unique_ptr<Wallet>> getWallets()
override {
557 std::vector<std::unique_ptr<Wallet>>
wallets;
564 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override {
578 return wallet ? std::make_unique<wallet::WalletImpl>(
wallet) :
nullptr;
583 return std::make_unique<wallet::WalletClientImpl>(chain, args);
Span< const CRPCCommand > GetWalletDumpRPCCommands()
#define CHECK_NONFATAL(condition)
Identity function.
#define Assert(val)
Identity function.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
A reference to a CKey: the Hash160 of its serialized public key.
An encapsulated public key.
Simple class for background tasks that should be run periodically or once "after a while".
An output of a transaction.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
A transaction with a bunch of additional info that only the owner cares about.
mapValue_t mapValue
Key/value map with information about the transaction.
int64_t GetTxTime() const
unsigned int nTimeReceived
time received by this node
Signature hash type wrapper class.
A Span is an object that can refer to a contiguous sequence of objects.
Access to the wallet database.
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Helper for findBlock to selectively return pieces of block data.
Generic interface for managing an event handler or callback function registered with another interfac...
Wallet chain client that in addition to having chain client methods for starting up,...
Interface for accessing a wallet.
Span< const CRPCCommand > GetWalletEncryptRPCCommands()
isminetype
IsMine() return codes.
void StartWallets(CScheduler &scheduler, const ArgsManager &args)
Complete startup of wallets.
bool VerifyWallets(interfaces::Chain &chain)
Responsible for reading and validating the -wallet arguments and verifying the wallet database.
void UnloadWallets()
Close all wallets.
void FlushWallets()
Flush all wallets in preparation for shutdown.
void StopWallets()
Stop all wallets. Wallets will be flushed first.
bool LoadWallets(interfaces::Chain &chain)
Load wallet databases.
bool error(const char *fmt, const Args &...args)
static std::string PathToString(const path &path)
Convert path object to byte string.
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
Return implementation of Wallet interface.
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
std::vector< std::pair< std::string, std::string > > WalletOrderForm
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
std::map< std::string, std::string > WalletValueMap
std::shared_ptr< const CTransaction > CTransactionRef
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Amount CachedTxGetChange(const CWallet &wallet, const CWalletTx &wtx)
Amount CachedTxGetDebit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
filter decides which addresses will count towards the debit
Amount OutputGetCredit(const CWallet &wallet, const CTxOut &txout, const isminefilter &filter)
Amount CachedTxGetCredit(const CWallet &wallet, const CWalletTx &wtx, const isminefilter &filter)
bool CachedTxIsTrusted(const CWallet &wallet, const CWalletTx &wtx, std::set< TxId > &trusted_parents)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
isminetype InputIsMine(const CWallet &wallet, const CTxIn &txin)
Span< const CRPCCommand > GetWalletRPCCommands()
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
std::map< CTxDestination, std::vector< COutput > > ListCoins(const CWallet &wallet)
Return list of available coins and locked coins grouped by non-change output address.
bool CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, CTransactionRef &tx, Amount &nFeeRet, int &nChangePosInOut, bilingual_str &error, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Amount GetAvailableBalance(const CWallet &wallet, const CCoinControl *coinControl)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
Amount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
A BlockHash is a unqiue identifier for a block.
SecureString create_passphrase
A version of CTransaction with the PSBT format.
A TxId is the identifier of a transaction.
WalletContext struct containing references to state shared between CWallet instances,...
Information about one wallet address.
Collection of wallet balances.
Amount immature_watch_only_balance
Amount unconfirmed_watch_only_balance
Amount unconfirmed_balance
Amount watch_only_balance
std::vector< CTxDestination > txout_address
std::vector< isminetype > txout_is_mine
std::map< std::string, std::string > value_map
std::vector< isminetype > txout_address_is_mine
std::vector< isminetype > txin_is_mine
Wallet transaction output.
Updated transaction status.
unsigned int time_received
#define TRY_LOCK(cs, name)
#define AssertLockHeld(cs)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
ChangeType
General change type (added, updated, removed).
Amount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
Amount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control)
Estimate the minimum fee considering user set parameters and the required fee.
std::list< CRPCCommand > m_rpc_commands
std::shared_ptr< CWallet > m_wallet
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
const std::vector< std::string > m_wallet_filenames
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
std::vector< std::shared_ptr< CWallet > > GetWallets()
std::shared_ptr< CWallet > LoadWallet(interfaces::Chain &chain, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, const std::string &name, std::optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
fs::path GetWalletDir()
Get the path of the wallet directory.
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS