Line data Source code
1 : // Copyright (c) 2018-2020 The Bitcoin Core developers
2 : // Distributed under the MIT software license, see the accompanying
3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 :
5 : #include <interfaces/wallet.h>
6 :
7 : #include <amount.h>
8 : #include <interfaces/chain.h>
9 : #include <interfaces/handler.h>
10 : #include <policy/fees.h>
11 : #include <primitives/transaction.h>
12 : #include <rpc/server.h>
13 : #include <script/standard.h>
14 : #include <support/allocators/secure.h>
15 : #include <sync.h>
16 : #include <uint256.h>
17 : #include <util/check.h>
18 : #include <util/ref.h>
19 : #include <util/system.h>
20 : #include <util/ui_change_type.h>
21 : #include <wallet/context.h>
22 : #include <wallet/feebumper.h>
23 : #include <wallet/fees.h>
24 : #include <wallet/ismine.h>
25 : #include <wallet/load.h>
26 : #include <wallet/rpcwallet.h>
27 : #include <wallet/wallet.h>
28 :
29 : #include <memory>
30 : #include <string>
31 : #include <utility>
32 : #include <vector>
33 :
34 : namespace interfaces {
35 : namespace {
36 :
37 : //! Construct wallet tx struct.
38 0 : WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
39 : {
40 0 : LOCK(wallet.cs_wallet);
41 0 : WalletTx result;
42 0 : result.tx = wtx.tx;
43 0 : result.txin_is_mine.reserve(wtx.tx->vin.size());
44 0 : for (const auto& txin : wtx.tx->vin) {
45 0 : result.txin_is_mine.emplace_back(wallet.IsMine(txin));
46 : }
47 0 : result.txout_is_mine.reserve(wtx.tx->vout.size());
48 0 : result.txout_address.reserve(wtx.tx->vout.size());
49 0 : result.txout_address_is_mine.reserve(wtx.tx->vout.size());
50 0 : for (const auto& txout : wtx.tx->vout) {
51 0 : result.txout_is_mine.emplace_back(wallet.IsMine(txout));
52 0 : result.txout_address.emplace_back();
53 0 : result.txout_address_is_mine.emplace_back(ExtractDestination(txout.scriptPubKey, result.txout_address.back()) ?
54 0 : wallet.IsMine(result.txout_address.back()) :
55 : ISMINE_NO);
56 : }
57 0 : result.credit = wtx.GetCredit(ISMINE_ALL);
58 0 : result.debit = wtx.GetDebit(ISMINE_ALL);
59 0 : result.change = wtx.GetChange();
60 0 : result.time = wtx.GetTxTime();
61 0 : result.value_map = wtx.mapValue;
62 0 : result.is_coinbase = wtx.IsCoinBase();
63 : return result;
64 0 : }
65 :
66 : //! Construct wallet tx status struct.
67 0 : WalletTxStatus MakeWalletTxStatus(CWallet& wallet, const CWalletTx& wtx)
68 : {
69 : WalletTxStatus result;
70 0 : result.block_height = wtx.m_confirm.block_height > 0 ? wtx.m_confirm.block_height : std::numeric_limits<int>::max();
71 0 : result.blocks_to_maturity = wtx.GetBlocksToMaturity();
72 0 : result.depth_in_main_chain = wtx.GetDepthInMainChain();
73 0 : result.time_received = wtx.nTimeReceived;
74 0 : result.lock_time = wtx.tx->nLockTime;
75 0 : result.is_final = wallet.chain().checkFinalTx(*wtx.tx);
76 0 : result.is_trusted = wtx.IsTrusted();
77 0 : result.is_abandoned = wtx.isAbandoned();
78 0 : result.is_coinbase = wtx.IsCoinBase();
79 0 : result.is_in_main_chain = wtx.IsInMainChain();
80 0 : return result;
81 : }
82 :
83 : //! Construct wallet TxOut struct.
84 0 : WalletTxOut MakeWalletTxOut(CWallet& wallet,
85 : const CWalletTx& wtx,
86 : int n,
87 : int depth) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
88 : {
89 0 : WalletTxOut result;
90 0 : result.txout = wtx.tx->vout[n];
91 0 : result.time = wtx.GetTxTime();
92 0 : result.depth_in_main_chain = depth;
93 0 : result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
94 : return result;
95 0 : }
96 :
97 3 : class WalletImpl : public Wallet
98 : {
99 : public:
100 2 : explicit WalletImpl(const std::shared_ptr<CWallet>& wallet) : m_wallet(wallet) {}
101 :
102 0 : bool encryptWallet(const SecureString& wallet_passphrase) override
103 : {
104 0 : return m_wallet->EncryptWallet(wallet_passphrase);
105 : }
106 0 : bool isCrypted() override { return m_wallet->IsCrypted(); }
107 0 : bool lock() override { return m_wallet->Lock(); }
108 0 : bool unlock(const SecureString& wallet_passphrase) override { return m_wallet->Unlock(wallet_passphrase); }
109 0 : bool isLocked() override { return m_wallet->IsLocked(); }
110 0 : bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
111 : const SecureString& new_wallet_passphrase) override
112 : {
113 0 : return m_wallet->ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
114 : }
115 0 : void abortRescan() override { m_wallet->AbortRescan(); }
116 0 : bool backupWallet(const std::string& filename) override { return m_wallet->BackupWallet(filename); }
117 0 : std::string getWalletName() override { return m_wallet->GetName(); }
118 0 : bool getNewDestination(const OutputType type, const std::string label, CTxDestination& dest) override
119 : {
120 0 : LOCK(m_wallet->cs_wallet);
121 0 : std::string error;
122 0 : return m_wallet->GetNewDestination(type, label, dest, error);
123 0 : }
124 0 : bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
125 : {
126 0 : std::unique_ptr<SigningProvider> provider = m_wallet->GetSolvingProvider(script);
127 0 : if (provider) {
128 0 : return provider->GetPubKey(address, pub_key);
129 : }
130 0 : return false;
131 0 : }
132 0 : SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override
133 : {
134 0 : return m_wallet->SignMessage(message, pkhash, str_sig);
135 : }
136 0 : bool isSpendable(const CTxDestination& dest) override
137 : {
138 0 : LOCK(m_wallet->cs_wallet);
139 0 : return m_wallet->IsMine(dest) & ISMINE_SPENDABLE;
140 0 : }
141 0 : bool haveWatchOnly() override
142 : {
143 0 : auto spk_man = m_wallet->GetLegacyScriptPubKeyMan();
144 0 : if (spk_man) {
145 0 : return spk_man->HaveWatchOnly();
146 : }
147 0 : return false;
148 0 : };
149 0 : bool setAddressBook(const CTxDestination& dest, const std::string& name, const std::string& purpose) override
150 : {
151 0 : return m_wallet->SetAddressBook(dest, name, purpose);
152 : }
153 0 : bool delAddressBook(const CTxDestination& dest) override
154 : {
155 0 : return m_wallet->DelAddressBook(dest);
156 : }
157 0 : bool getAddress(const CTxDestination& dest,
158 : std::string* name,
159 : isminetype* is_mine,
160 : std::string* purpose) override
161 : {
162 0 : LOCK(m_wallet->cs_wallet);
163 0 : auto it = m_wallet->m_address_book.find(dest);
164 0 : if (it == m_wallet->m_address_book.end() || it->second.IsChange()) {
165 0 : return false;
166 : }
167 0 : if (name) {
168 0 : *name = it->second.GetLabel();
169 : }
170 0 : if (is_mine) {
171 0 : *is_mine = m_wallet->IsMine(dest);
172 0 : }
173 0 : if (purpose) {
174 0 : *purpose = it->second.purpose;
175 : }
176 0 : return true;
177 0 : }
178 0 : std::vector<WalletAddress> getAddresses() override
179 : {
180 0 : LOCK(m_wallet->cs_wallet);
181 0 : std::vector<WalletAddress> result;
182 0 : for (const auto& item : m_wallet->m_address_book) {
183 0 : if (item.second.IsChange()) continue;
184 0 : result.emplace_back(item.first, m_wallet->IsMine(item.first), item.second.GetLabel(), item.second.purpose);
185 0 : }
186 : return result;
187 0 : }
188 0 : bool addDestData(const CTxDestination& dest, const std::string& key, const std::string& value) override
189 : {
190 0 : LOCK(m_wallet->cs_wallet);
191 0 : WalletBatch batch{m_wallet->GetDatabase()};
192 0 : return m_wallet->AddDestData(batch, dest, key, value);
193 0 : }
194 0 : bool eraseDestData(const CTxDestination& dest, const std::string& key) override
195 : {
196 0 : LOCK(m_wallet->cs_wallet);
197 0 : WalletBatch batch{m_wallet->GetDatabase()};
198 0 : return m_wallet->EraseDestData(batch, dest, key);
199 0 : }
200 0 : std::vector<std::string> getDestValues(const std::string& prefix) override
201 : {
202 0 : LOCK(m_wallet->cs_wallet);
203 0 : return m_wallet->GetDestValues(prefix);
204 0 : }
205 0 : void lockCoin(const COutPoint& output) override
206 : {
207 0 : LOCK(m_wallet->cs_wallet);
208 0 : return m_wallet->LockCoin(output);
209 0 : }
210 0 : void unlockCoin(const COutPoint& output) override
211 : {
212 0 : LOCK(m_wallet->cs_wallet);
213 0 : return m_wallet->UnlockCoin(output);
214 0 : }
215 0 : bool isLockedCoin(const COutPoint& output) override
216 : {
217 0 : LOCK(m_wallet->cs_wallet);
218 0 : return m_wallet->IsLockedCoin(output.hash, output.n);
219 0 : }
220 0 : void listLockedCoins(std::vector<COutPoint>& outputs) override
221 : {
222 0 : LOCK(m_wallet->cs_wallet);
223 0 : return m_wallet->ListLockedCoins(outputs);
224 0 : }
225 0 : CTransactionRef createTransaction(const std::vector<CRecipient>& recipients,
226 : const CCoinControl& coin_control,
227 : bool sign,
228 : int& change_pos,
229 : CAmount& fee,
230 : bilingual_str& fail_reason) override
231 : {
232 0 : LOCK(m_wallet->cs_wallet);
233 0 : CTransactionRef tx;
234 0 : if (!m_wallet->CreateTransaction(recipients, tx, fee, change_pos,
235 : fail_reason, coin_control, sign)) {
236 0 : return {};
237 : }
238 0 : return tx;
239 0 : }
240 0 : void commitTransaction(CTransactionRef tx,
241 : WalletValueMap value_map,
242 : WalletOrderForm order_form) override
243 : {
244 0 : LOCK(m_wallet->cs_wallet);
245 0 : m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
246 0 : }
247 0 : bool transactionCanBeAbandoned(const uint256& txid) override { return m_wallet->TransactionCanBeAbandoned(txid); }
248 0 : bool abandonTransaction(const uint256& txid) override
249 : {
250 0 : LOCK(m_wallet->cs_wallet);
251 0 : return m_wallet->AbandonTransaction(txid);
252 0 : }
253 0 : bool transactionCanBeBumped(const uint256& txid) override
254 : {
255 0 : return feebumper::TransactionCanBeBumped(*m_wallet.get(), txid);
256 : }
257 0 : bool createBumpTransaction(const uint256& txid,
258 : const CCoinControl& coin_control,
259 : std::vector<bilingual_str>& errors,
260 : CAmount& old_fee,
261 : CAmount& new_fee,
262 : CMutableTransaction& mtx) override
263 : {
264 0 : return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx) == feebumper::Result::OK;
265 : }
266 0 : bool signBumpTransaction(CMutableTransaction& mtx) override { return feebumper::SignTransaction(*m_wallet.get(), mtx); }
267 0 : bool commitBumpTransaction(const uint256& txid,
268 : CMutableTransaction&& mtx,
269 : std::vector<bilingual_str>& errors,
270 : uint256& bumped_txid) override
271 : {
272 0 : return feebumper::CommitTransaction(*m_wallet.get(), txid, std::move(mtx), errors, bumped_txid) ==
273 : feebumper::Result::OK;
274 : }
275 0 : CTransactionRef getTx(const uint256& txid) override
276 : {
277 0 : LOCK(m_wallet->cs_wallet);
278 0 : auto mi = m_wallet->mapWallet.find(txid);
279 0 : if (mi != m_wallet->mapWallet.end()) {
280 0 : return mi->second.tx;
281 : }
282 0 : return {};
283 0 : }
284 0 : WalletTx getWalletTx(const uint256& txid) override
285 : {
286 0 : LOCK(m_wallet->cs_wallet);
287 0 : auto mi = m_wallet->mapWallet.find(txid);
288 0 : if (mi != m_wallet->mapWallet.end()) {
289 0 : return MakeWalletTx(*m_wallet, mi->second);
290 : }
291 0 : return {};
292 0 : }
293 0 : std::vector<WalletTx> getWalletTxs() override
294 : {
295 0 : LOCK(m_wallet->cs_wallet);
296 0 : std::vector<WalletTx> result;
297 0 : result.reserve(m_wallet->mapWallet.size());
298 0 : for (const auto& entry : m_wallet->mapWallet) {
299 0 : result.emplace_back(MakeWalletTx(*m_wallet, entry.second));
300 0 : }
301 : return result;
302 0 : }
303 0 : bool tryGetTxStatus(const uint256& txid,
304 : interfaces::WalletTxStatus& tx_status,
305 : int& num_blocks,
306 : int64_t& block_time) override
307 : {
308 0 : TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
309 0 : if (!locked_wallet) {
310 0 : return false;
311 : }
312 0 : auto mi = m_wallet->mapWallet.find(txid);
313 0 : if (mi == m_wallet->mapWallet.end()) {
314 0 : return false;
315 : }
316 0 : num_blocks = m_wallet->GetLastBlockHeight();
317 0 : block_time = -1;
318 0 : CHECK_NONFATAL(m_wallet->chain().findBlock(m_wallet->GetLastBlockHash(), FoundBlock().time(block_time)));
319 0 : tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
320 0 : return true;
321 0 : }
322 0 : WalletTx getWalletTxDetails(const uint256& txid,
323 : WalletTxStatus& tx_status,
324 : WalletOrderForm& order_form,
325 : bool& in_mempool,
326 : int& num_blocks) override
327 : {
328 0 : LOCK(m_wallet->cs_wallet);
329 0 : auto mi = m_wallet->mapWallet.find(txid);
330 0 : if (mi != m_wallet->mapWallet.end()) {
331 0 : num_blocks = m_wallet->GetLastBlockHeight();
332 0 : in_mempool = mi->second.InMempool();
333 0 : order_form = mi->second.vOrderForm;
334 0 : tx_status = MakeWalletTxStatus(*m_wallet, mi->second);
335 0 : return MakeWalletTx(*m_wallet, mi->second);
336 : }
337 0 : return {};
338 0 : }
339 0 : TransactionError fillPSBT(int sighash_type,
340 : bool sign,
341 : bool bip32derivs,
342 : PartiallySignedTransaction& psbtx,
343 : bool& complete,
344 : size_t* n_signed) override
345 : {
346 0 : return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
347 : }
348 0 : WalletBalances getBalances() override
349 : {
350 0 : const auto bal = m_wallet->GetBalance();
351 0 : WalletBalances result;
352 0 : result.balance = bal.m_mine_trusted;
353 0 : result.unconfirmed_balance = bal.m_mine_untrusted_pending;
354 0 : result.immature_balance = bal.m_mine_immature;
355 0 : result.have_watch_only = haveWatchOnly();
356 0 : if (result.have_watch_only) {
357 0 : result.watch_only_balance = bal.m_watchonly_trusted;
358 0 : result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending;
359 0 : result.immature_watch_only_balance = bal.m_watchonly_immature;
360 0 : }
361 : return result;
362 0 : }
363 0 : bool tryGetBalances(WalletBalances& balances, uint256& block_hash) override
364 : {
365 0 : TRY_LOCK(m_wallet->cs_wallet, locked_wallet);
366 0 : if (!locked_wallet) {
367 0 : return false;
368 : }
369 0 : block_hash = m_wallet->GetLastBlockHash();
370 0 : balances = getBalances();
371 0 : return true;
372 0 : }
373 0 : CAmount getBalance() override { return m_wallet->GetBalance().m_mine_trusted; }
374 0 : CAmount getAvailableBalance(const CCoinControl& coin_control) override
375 : {
376 0 : return m_wallet->GetAvailableBalance(&coin_control);
377 : }
378 0 : isminetype txinIsMine(const CTxIn& txin) override
379 : {
380 0 : LOCK(m_wallet->cs_wallet);
381 0 : return m_wallet->IsMine(txin);
382 0 : }
383 0 : isminetype txoutIsMine(const CTxOut& txout) override
384 : {
385 0 : LOCK(m_wallet->cs_wallet);
386 0 : return m_wallet->IsMine(txout);
387 0 : }
388 0 : CAmount getDebit(const CTxIn& txin, isminefilter filter) override
389 : {
390 0 : LOCK(m_wallet->cs_wallet);
391 0 : return m_wallet->GetDebit(txin, filter);
392 0 : }
393 0 : CAmount getCredit(const CTxOut& txout, isminefilter filter) override
394 : {
395 0 : LOCK(m_wallet->cs_wallet);
396 0 : return m_wallet->GetCredit(txout, filter);
397 0 : }
398 0 : CoinsList listCoins() override
399 : {
400 0 : LOCK(m_wallet->cs_wallet);
401 0 : CoinsList result;
402 0 : for (const auto& entry : m_wallet->ListCoins()) {
403 0 : auto& group = result[entry.first];
404 0 : for (const auto& coin : entry.second) {
405 0 : group.emplace_back(COutPoint(coin.tx->GetHash(), coin.i),
406 0 : MakeWalletTxOut(*m_wallet, *coin.tx, coin.i, coin.nDepth));
407 : }
408 0 : }
409 : return result;
410 0 : }
411 0 : std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) override
412 : {
413 0 : LOCK(m_wallet->cs_wallet);
414 0 : std::vector<WalletTxOut> result;
415 0 : result.reserve(outputs.size());
416 0 : for (const auto& output : outputs) {
417 0 : result.emplace_back();
418 0 : auto it = m_wallet->mapWallet.find(output.hash);
419 0 : if (it != m_wallet->mapWallet.end()) {
420 0 : int depth = it->second.GetDepthInMainChain();
421 0 : if (depth >= 0) {
422 0 : result.back() = MakeWalletTxOut(*m_wallet, it->second, output.n, depth);
423 0 : }
424 0 : }
425 0 : }
426 : return result;
427 0 : }
428 0 : CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(*m_wallet, tx_bytes); }
429 0 : CAmount getMinimumFee(unsigned int tx_bytes,
430 : const CCoinControl& coin_control,
431 : int* returned_target,
432 : FeeReason* reason) override
433 : {
434 0 : FeeCalculation fee_calc;
435 : CAmount result;
436 0 : result = GetMinimumFee(*m_wallet, tx_bytes, coin_control, &fee_calc);
437 0 : if (returned_target) *returned_target = fee_calc.returnedTarget;
438 0 : if (reason) *reason = fee_calc.reason;
439 0 : return result;
440 0 : }
441 0 : unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
442 0 : bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
443 0 : bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
444 0 : bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); }
445 0 : OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
446 0 : CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
447 0 : void remove() override
448 : {
449 0 : RemoveWallet(m_wallet, false /* load_on_start */);
450 0 : }
451 0 : bool isLegacy() override { return m_wallet->IsLegacy(); }
452 0 : std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
453 : {
454 0 : return MakeHandler(m_wallet->NotifyUnload.connect(fn));
455 0 : }
456 0 : std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
457 : {
458 0 : return MakeHandler(m_wallet->ShowProgress.connect(fn));
459 0 : }
460 0 : std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
461 : {
462 0 : return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); }));
463 0 : }
464 0 : std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
465 : {
466 0 : return MakeHandler(m_wallet->NotifyAddressBookChanged.connect(
467 0 : [fn](CWallet*, const CTxDestination& address, const std::string& label, bool is_mine,
468 0 : const std::string& purpose, ChangeType status) { fn(address, label, is_mine, purpose, status); }));
469 0 : }
470 0 : std::unique_ptr<Handler> handleTransactionChanged(TransactionChangedFn fn) override
471 : {
472 0 : return MakeHandler(m_wallet->NotifyTransactionChanged.connect(
473 0 : [fn](CWallet*, const uint256& txid, ChangeType status) { fn(txid, status); }));
474 0 : }
475 0 : std::unique_ptr<Handler> handleWatchOnlyChanged(WatchOnlyChangedFn fn) override
476 : {
477 0 : return MakeHandler(m_wallet->NotifyWatchonlyChanged.connect(fn));
478 0 : }
479 0 : std::unique_ptr<Handler> handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) override
480 : {
481 0 : return MakeHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn));
482 0 : }
483 3 : CWallet* wallet() override { return m_wallet.get(); }
484 :
485 : std::shared_ptr<CWallet> m_wallet;
486 : };
487 :
488 : class WalletClientImpl : public WalletClient
489 : {
490 : public:
491 2002 : WalletClientImpl(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
492 1001 : : m_wallet_filenames(std::move(wallet_filenames))
493 2002 : {
494 1001 : m_context.chain = &chain;
495 1001 : m_context.args = &args;
496 2002 : }
497 3000 : ~WalletClientImpl() override { UnloadWallets(); }
498 :
499 : //! ChainClient methods
500 531 : void registerRpcs() override
501 : {
502 32391 : for (const CRPCCommand& command : GetWalletRPCCommands()) {
503 82252 : m_rpc_commands.emplace_back(command.category, command.name, [this, &command](const JSONRPCRequest& request, UniValue& result, bool last_handler) {
504 18532 : return command.actor({request, m_context}, result, last_handler);
505 32446 : }, command.argNames, command.unique_id);
506 31860 : m_rpc_handlers.emplace_back(m_context.chain->handleRpc(m_rpc_commands.back()));
507 : }
508 531 : }
509 528 : bool verify() override { return VerifyWallets(*m_context.chain, m_wallet_filenames); }
510 492 : bool load() override { return LoadWallets(*m_context.chain, m_wallet_filenames); }
511 974 : void start(CScheduler& scheduler) override { return StartWallets(scheduler, *Assert(m_context.args)); }
512 524 : void flush() override { return FlushWallets(); }
513 524 : void stop() override { return StopWallets(); }
514 479 : void setMockTime(int64_t time) override { return SetMockTime(time); }
515 :
516 : //! WalletClient methods
517 0 : 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
518 : {
519 0 : std::shared_ptr<CWallet> wallet;
520 0 : DatabaseOptions options;
521 0 : DatabaseStatus status;
522 0 : options.require_create = true;
523 0 : options.create_flags = wallet_creation_flags;
524 0 : options.create_passphrase = passphrase;
525 0 : return MakeWallet(CreateWallet(*m_context.chain, name, true /* load_on_start */, options, status, error, warnings));
526 0 : }
527 0 : std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
528 : {
529 0 : DatabaseOptions options;
530 0 : DatabaseStatus status;
531 0 : options.require_existing = true;
532 0 : return MakeWallet(LoadWallet(*m_context.chain, name, true /* load_on_start */, options, status, error, warnings));
533 0 : }
534 0 : std::string getWalletDir() override
535 : {
536 0 : return GetWalletDir().string();
537 0 : }
538 0 : std::vector<std::string> listWalletDir() override
539 : {
540 0 : std::vector<std::string> paths;
541 0 : for (auto& path : ListWalletDir()) {
542 0 : paths.push_back(path.string());
543 : }
544 : return paths;
545 0 : }
546 0 : std::vector<std::unique_ptr<Wallet>> getWallets() override
547 : {
548 0 : std::vector<std::unique_ptr<Wallet>> wallets;
549 0 : for (const auto& wallet : GetWallets()) {
550 0 : wallets.emplace_back(MakeWallet(wallet));
551 : }
552 : return wallets;
553 0 : }
554 0 : std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
555 : {
556 0 : return HandleLoadWallet(std::move(fn));
557 0 : }
558 :
559 : WalletContext m_context;
560 : const std::vector<std::string> m_wallet_filenames;
561 : std::vector<std::unique_ptr<Handler>> m_rpc_handlers;
562 : std::list<CRPCCommand> m_rpc_commands;
563 : };
564 :
565 : } // namespace
566 :
567 1 : std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet>& wallet) { return wallet ? MakeUnique<WalletImpl>(wallet) : nullptr; }
568 :
569 1001 : std::unique_ptr<WalletClient> MakeWalletClient(Chain& chain, ArgsManager& args, std::vector<std::string> wallet_filenames)
570 : {
571 1001 : return MakeUnique<WalletClientImpl>(chain, args, std::move(wallet_filenames));
572 : }
573 :
574 : } // namespace interfaces
|