43 result.txin_is_mine.reserve(wtx.
tx->vin.size());
44 for (
const auto& txin : wtx.
tx->vin) {
45 result.txin_is_mine.emplace_back(wallet.
IsMine(txin));
47 result.txout_is_mine.reserve(wtx.
tx->vout.size());
48 result.txout_address.reserve(wtx.
tx->vout.size());
49 result.txout_address_is_mine.reserve(wtx.
tx->vout.size());
50 for (
const auto& txout : wtx.
tx->vout) {
51 result.txout_is_mine.emplace_back(wallet.
IsMine(txout));
52 result.txout_address.emplace_back();
53 result.txout_address_is_mine.emplace_back(
ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
54 wallet.
IsMine(result.txout_address.back()) :
69 WalletTxStatus result;
74 result.lock_time = wtx.
tx->nLockTime;
84 WalletTxOut MakeWalletTxOut(
CWallet& wallet,
90 result.txout = wtx.
tx->vout[n];
92 result.depth_in_main_chain = depth;
97 class WalletImpl :
public Wallet
100 explicit WalletImpl(
const std::shared_ptr<CWallet>& wallet) :
m_wallet(wallet) {}
102 bool encryptWallet(
const SecureString& wallet_passphrase)
override 104 return m_wallet->EncryptWallet(wallet_passphrase);
106 bool isCrypted()
override {
return m_wallet->IsCrypted(); }
107 bool lock()
override {
return m_wallet->Lock(); }
108 bool unlock(
const SecureString& wallet_passphrase)
override {
return m_wallet->Unlock(wallet_passphrase); }
109 bool isLocked()
override {
return m_wallet->IsLocked(); }
110 bool changeWalletPassphrase(
const SecureString& old_wallet_passphrase,
113 return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
115 void abortRescan()
override {
m_wallet->AbortRescan(); }
116 bool backupWallet(
const std::string& filename)
override {
return m_wallet->BackupWallet(filename); }
117 std::string getWalletName()
override {
return m_wallet->GetName(); }
122 return m_wallet->GetNewDestination(type, label, dest, error);
126 std::unique_ptr<SigningProvider> provider =
m_wallet->GetSolvingProvider(script);
128 return provider->GetPubKey(address, pub_key);
132 SigningResult signMessage(
const std::string& message,
const PKHash& pkhash, std::string& str_sig)
override 134 return m_wallet->SignMessage(message, pkhash, str_sig);
141 bool haveWatchOnly()
override 143 auto spk_man =
m_wallet->GetLegacyScriptPubKeyMan();
145 return spk_man->HaveWatchOnly();
149 bool setAddressBook(
const CTxDestination& dest,
const std::string&
name,
const std::string& purpose)
override 151 return m_wallet->SetAddressBook(dest, name, purpose);
155 return m_wallet->DelAddressBook(dest);
160 std::string* purpose)
override 163 auto it =
m_wallet->m_address_book.find(dest);
164 if (
it ==
m_wallet->m_address_book.end() ||
it->second.IsChange()) {
168 *name =
it->second.GetLabel();
174 *purpose =
it->second.purpose;
178 std::vector<WalletAddress> getAddresses()
override 181 std::vector<WalletAddress> result;
182 for (
const auto& item :
m_wallet->m_address_book) {
183 if (item.second.IsChange())
continue;
184 result.emplace_back(item.first,
m_wallet->IsMine(item.first), item.second.GetLabel(), item.second.purpose);
188 bool addDestData(
const CTxDestination& dest,
const std::string& key,
const std::string& value)
override 192 return m_wallet->AddDestData(batch, dest, key, value);
194 bool eraseDestData(
const CTxDestination& dest,
const std::string& key)
override 198 return m_wallet->EraseDestData(batch, dest, key);
200 std::vector<std::string> getDestValues(
const std::string&
prefix)
override 203 return m_wallet->GetDestValues(prefix);
205 void lockCoin(
const COutPoint& output)
override 210 void unlockCoin(
const COutPoint& output)
override 213 return m_wallet->UnlockCoin(output);
215 bool isLockedCoin(
const COutPoint& output)
override 220 void listLockedCoins(std::vector<COutPoint>& outputs)
override 223 return m_wallet->ListLockedCoins(outputs);
225 CTransactionRef createTransaction(
const std::vector<CRecipient>& recipients,
235 if (!
m_wallet->CreateTransaction(recipients, tx, fee, change_pos,
236 fail_reason, coin_control, fee_calc_out, sign)) {
246 m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
248 bool transactionCanBeAbandoned(
const uint256& txid)
override {
return m_wallet->TransactionCanBeAbandoned(txid); }
249 bool abandonTransaction(
const uint256& txid)
override 252 return m_wallet->AbandonTransaction(txid);
254 bool transactionCanBeBumped(
const uint256& txid)
override 258 bool createBumpTransaction(
const uint256& txid,
260 std::vector<bilingual_str>& errors,
268 bool commitBumpTransaction(
const uint256& txid,
270 std::vector<bilingual_str>& errors,
279 auto mi =
m_wallet->mapWallet.find(txid);
280 if (mi !=
m_wallet->mapWallet.end()) {
281 return mi->second.tx;
285 WalletTx getWalletTx(
const uint256& txid)
override 288 auto mi =
m_wallet->mapWallet.find(txid);
289 if (mi !=
m_wallet->mapWallet.end()) {
290 return MakeWalletTx(*
m_wallet, mi->second);
294 std::vector<WalletTx> getWalletTxs()
override 297 std::vector<WalletTx> result;
298 result.reserve(
m_wallet->mapWallet.size());
299 for (
const auto& entry :
m_wallet->mapWallet) {
300 result.emplace_back(MakeWalletTx(*
m_wallet, entry.second));
304 bool tryGetTxStatus(
const uint256& txid,
307 int64_t& block_time)
override 310 if (!locked_wallet) {
313 auto mi =
m_wallet->mapWallet.find(txid);
314 if (mi ==
m_wallet->mapWallet.end()) {
317 num_blocks =
m_wallet->GetLastBlockHeight();
320 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
323 WalletTx getWalletTxDetails(
const uint256& txid,
324 WalletTxStatus& tx_status,
327 int& num_blocks)
override 330 auto mi =
m_wallet->mapWallet.find(txid);
331 if (mi !=
m_wallet->mapWallet.end()) {
332 num_blocks =
m_wallet->GetLastBlockHeight();
333 in_mempool = mi->second.InMempool();
334 order_form = mi->second.vOrderForm;
335 tx_status = MakeWalletTxStatus(*
m_wallet, mi->second);
336 return MakeWalletTx(*
m_wallet, mi->second);
345 size_t* n_signed)
override 347 return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
349 WalletBalances getBalances()
override 351 const auto bal =
m_wallet->GetBalance();
352 WalletBalances result;
353 result.balance = bal.m_mine_trusted;
354 result.unconfirmed_balance = bal.m_mine_untrusted_pending;
355 result.immature_balance = bal.m_mine_immature;
356 result.have_watch_only = haveWatchOnly();
357 if (result.have_watch_only) {
358 result.watch_only_balance = bal.m_watchonly_trusted;
359 result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending;
360 result.immature_watch_only_balance = bal.m_watchonly_immature;
364 bool tryGetBalances(WalletBalances& balances,
uint256& block_hash)
override 367 if (!locked_wallet) {
370 block_hash =
m_wallet->GetLastBlockHash();
371 balances = getBalances();
374 CAmount getBalance()
override {
return m_wallet->GetBalance().m_mine_trusted; }
377 return m_wallet->GetAvailableBalance(&coin_control);
392 return m_wallet->GetDebit(txin, filter);
397 return m_wallet->GetCredit(txout, filter);
399 CoinsList listCoins()
override 403 for (
const auto& entry :
m_wallet->ListCoins()) {
404 auto& group = result[entry.first];
405 for (
const auto& coin : entry.second) {
406 group.emplace_back(
COutPoint(coin.tx->GetHash(), coin.i),
407 MakeWalletTxOut(*
m_wallet, *coin.tx, coin.i, coin.nDepth));
412 std::vector<WalletTxOut> getCoins(
const std::vector<COutPoint>& outputs)
override 415 std::vector<WalletTxOut> result;
416 result.reserve(outputs.size());
417 for (
const auto& output : outputs) {
418 result.emplace_back();
421 int depth =
it->second.GetDepthInMainChain();
423 result.back() = MakeWalletTxOut(*
m_wallet,
it->second, output.
n, depth);
430 CAmount getMinimumFee(
unsigned int tx_bytes,
432 int* returned_target,
439 if (reason) *reason = fee_calc.
reason;
442 unsigned int getConfirmTarget()
override {
return m_wallet->m_confirm_target; }
443 bool hdEnabled()
override {
return m_wallet->IsHDEnabled(); }
444 bool canGetAddresses()
override {
return m_wallet->CanGetAddresses(); }
446 OutputType getDefaultAddressType()
override {
return m_wallet->m_default_address_type; }
447 CAmount getDefaultMaxTxFee()
override {
return m_wallet->m_default_max_tx_fee; }
448 void remove()
override 452 bool isLegacy()
override {
return m_wallet->IsLegacy(); }
453 std::unique_ptr<Handler> handleUnload(UnloadFn fn)
override 457 std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn)
override 461 std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn)
override 465 std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn)
override 469 const std::string& purpose,
ChangeType status) { fn(address, label, is_mine, purpose, status); }));
471 std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn)
override 476 std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn)
override 480 std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn)
override 489 class WalletClientImpl :
public WalletClient
500 void registerRpcs()
override 504 return command.actor({request, m_context}, result, last_handler);
505 }, command.argNames, command.unique_id);
514 void setMockTime(int64_t time)
override {
return SetMockTime(time); }
517 std::unique_ptr<Wallet> createWallet(
const std::string& name,
const SecureString& passphrase, uint64_t wallet_creation_flags,
bilingual_str& error, std::vector<bilingual_str>& warnings)
override 519 std::shared_ptr<CWallet> wallet;
527 std::unique_ptr<Wallet> loadWallet(
const std::string& name,
bilingual_str& error, std::vector<bilingual_str>& warnings)
override 534 std::string getWalletDir()
override 538 std::vector<std::string> listWalletDir()
override 540 std::vector<std::string> paths;
542 paths.push_back(path.string());
546 std::vector<std::unique_ptr<Wallet>> getWallets()
override 548 std::vector<std::unique_ptr<Wallet>> wallets;
554 std::unique_ptr<Handler> handleLoadWallet(
LoadWalletFn fn)
override 567 std::unique_ptr<Wallet>
MakeWallet(
const std::shared_ptr<CWallet>& wallet) {
return wallet ? MakeUnique<WalletImpl>(wallet) :
nullptr; }
571 return MakeUnique<WalletClientImpl>(chain, args);
std::shared_ptr< const CTransaction > CTransactionRef
std::shared_ptr< CWallet > m_wallet
std::deque< CInv >::iterator it
bool SignTransaction(CWallet &wallet, CMutableTransaction &mtx)
Sign the new transaction,.
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
bool LoadWallets(interfaces::Chain &chain)
Load wallet databases.
std::function< void(std::unique_ptr< interfaces::Wallet > wallet)> LoadWalletFn
#define TRY_LOCK(cs, name)
isminetype IsMine(const CTxDestination &dest) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
CAmount GetMinimumFee(const CWallet &wallet, unsigned int nTxBytes, const CCoinControl &coin_control, FeeCalculation *feeCalc)
Estimate the minimum fee considering user set parameters and the required fee.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool IsInMainChain() const
std::vector< std::shared_ptr< CWallet > > GetWallets()
A version of CTransaction with the PSBT format.
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
std::map< std::string, std::string > WalletValueMap
const std::vector< std::string > m_wallet_filenames
virtual bool checkFinalTx(const CTransaction &tx)=0
Check if transaction will be final given chain height current time.
Result CreateRateBumpTransaction(CWallet &wallet, const uint256 &txid, const CCoinControl &coin_control, std::vector< bilingual_str > &errors, CAmount &old_fee, CAmount &new_fee, CMutableTransaction &mtx)
Create bumpfee transaction based on feerate estimates.
Access to the wallet database.
mapValue_t mapValue
Key/value map with information about the transaction.
std::shared_ptr< CWallet > CreateWallet(interfaces::Chain &chain, const std::string &name, Optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
interfaces::Chain & chain() const
Interface for accessing chain state.
void StopWallets()
Stop all wallets. Wallets will be flushed first.
int64_t CAmount
Amount in satoshis (Can be negative)
void SetMockTime(int64_t nMockTimeIn)
For testing.
bool VerifyWallets(interfaces::Chain &chain)
Responsible for reading and validating the -wallet arguments and verifying the wallet database...
fs::path GetWalletDir()
Get the path of the wallet directory.
An input of a transaction.
bool TransactionCanBeBumped(const CWallet &wallet, const uint256 &txid)
Return whether transaction can be bumped.
An encapsulated public key.
int GetBlocksToMaturity() const
virtual std::unique_ptr< Handler > handleRpc(const CRPCCommand &command)=0
Register handler for RPC.
std::unique_ptr< interfaces::Handler > HandleLoadWallet(LoadWalletFn load_wallet)
isminetype
IsMine() return codes.
An output of a transaction.
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet, Optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
const uint256 & GetHash() const
An outpoint - a combination of a transaction hash and an index n into its vout.
std::unique_ptr< Wallet > MakeWallet(const std::shared_ptr< CWallet > &wallet)
Return implementation of Wallet interface.
void FlushWallets()
Flush all wallets in preparation for shutdown.
A transaction with a bunch of additional info that only the owner cares about.
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Span< const CRPCCommand > GetWalletRPCCommands()
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Result CommitTransaction(CWallet &wallet, const uint256 &txid, CMutableTransaction &&mtx, std::vector< bilingual_str > &errors, uint256 &bumped_txid)
Commit the bumpfee transaction.
interfaces::Chain * chain
CAmount GetCredit(const isminefilter &filter) const
int64_t GetTxTime() const
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
Serialized script, used inside transaction inputs and outputs.
A reference to a CKey: the Hash160 of its serialized public key.
int GetDepthInMainChain() const NO_THREAD_SAFETY_ANALYSIS
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
std::vector< std::pair< std::string, std::string > > WalletOrderForm
std::list< CRPCCommand > m_rpc_commands
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
A mutable version of CTransaction.
SecureString create_passphrase
std::vector< fs::path > ListWalletDir()
Get wallets in wallet directory.
CAmount GetRequiredFee(const CWallet &wallet, unsigned int nTxBytes)
Return the minimum required absolute fee for this size based on the required fee rate.
bool IsSpent(const uint256 &hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Outpoint is spent if any non-conflicted transaction spends it:
unsigned int nTimeReceived
time received by this node
std::shared_ptr< CWallet > LoadWallet(interfaces::Chain &chain, const std::string &name, Optional< bool > load_on_start, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
void UnloadWallets()
Close all wallets.
Simple class for background tasks that should be run periodically or once "after a while"...
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
ChangeType
General change type (added, updated, removed).
bool error(const char *fmt, const Args &... args)
Updated transaction status.
std::vector< std::unique_ptr< Handler > > m_rpc_handlers
#define Assert(val)
Identity function.
CAmount GetChange() const
void StartWallets(CScheduler &scheduler, const ArgsManager &args)
Complete startup of wallets.