Debian Codegraph @

monero/src/wallet/api/wallet2_api.h

raw symbols SCIP
1 // Copyright (c) 2014-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31 #pragma once
32
33
34 #include <string>
35 #include <vector>
36 #include <list>
37 #include <set>
38 #include <ctime>
39 #include <iostream>
40 #include <stdexcept>
41 #include <cstdint>
42 #include <optional>
43
44 namespace tools {
45 class wallet2;
46 }
47
48 // Public interface for libwallet library
49 namespace Monero {
50
51 enum NetworkType : uint8_t {
52 MAINNET = 0,
53 TESTNET,
54 STAGENET
55 };
56
57 namespace Utils {
58 bool isAddressLocal(const std::string &hostaddr);
59 void onStartup();
60 }
61
62 /*
63 * @brief Transaction construction data
64 */
65 struct TransactionConstructionInfo
66 {
67 struct Input {
68 Input(uint64_t _amount, const std::string &_pubkey);
69 const uint64_t amount;
70 const std::string pubkey;
71 };
72
73 struct Output {
74 Output(uint64_t _amount, const std::string &_address);
75 const uint64_t amount;
76 const std::string address;
77 };
78
79 virtual ~TransactionConstructionInfo() = 0;
80 virtual uint64_t unlockTime() const = 0;
81 virtual std::set<std::uint32_t> subaddressIndices() const = 0;
82 virtual std::vector<std::string> subaddresses() const = 0;
83 virtual uint64_t minMixinCount() const = 0;
84 virtual std::vector<Input> inputs() const = 0;
85 virtual std::vector<Output> outputs() const = 0;
86 };
87
88
89 /*
90 * @brief Detailed pending transaction information
91 */
92 struct PendingTransactionInfo
93 {
94 virtual ~PendingTransactionInfo() = 0;
95 virtual uint64_t fee() const = 0;
96 virtual uint64_t dust() const = 0;
97 virtual bool dustAddedToFee() const = 0;
98 virtual std::string txKey() const = 0;
99 virtual TransactionConstructionInfo * constructionData() const = 0;
100 };
101
102
103 /**
104 * @brief Transaction-like interface for sending money
105 */
106 struct PendingTransaction
107 {
108 enum Status {
109 Status_Ok,
110 Status_Error,
111 Status_Critical
112 };
113
114 enum Priority {
115 Priority_Default = 0,
116 Priority_Low = 1,
117 Priority_Medium = 2,
118 Priority_High = 3,
119 Priority_Last
120 };
121
122 virtual ~PendingTransaction() = 0;
123 virtual int status() const = 0;
124 virtual std::string errorString() const = 0;
125 virtual const std::exception_ptr getException() const = 0;
126 // commit transaction or save to file if filename is provided.
127 virtual bool commit(const std::string &filename = "", bool overwrite = false) = 0;
128 virtual uint64_t amount() const = 0;
129 virtual uint64_t dust() const = 0;
130 virtual uint64_t fee() const = 0;
131 virtual uint64_t weight(int index) const = 0;
132 virtual std::vector<std::string> txid() const = 0;
133 /*!
134 * \brief txCount - number of transactions current transaction will be splitted to
135 * \return
136 */
137 virtual uint64_t txCount() const = 0;
138 virtual std::vector<uint32_t> subaddrAccount() const = 0;
139 virtual std::vector<std::set<uint32_t>> subaddrIndices() const = 0;
140 virtual std::string unsignedTxToBin() const = 0;
141 virtual std::string unsignedTxToBase64() const = 0;
142 virtual std::string signedTxToHex(int index) const = 0;
143 virtual size_t signedTxSize(int index) const = 0;
144 virtual PendingTransactionInfo * transaction(int index) const = 0;
145 virtual void refresh() = 0;
146 virtual std::vector<PendingTransactionInfo*> getAll() const = 0;
147
148 /**
149 * @brief multisigSignData
150 * @return encoded multisig transaction with signers' keys.
151 * Transfer this data to another wallet participant to sign it.
152 * Assumed use case is:
153 * 1. Initiator:
154 * auto data = pendingTransaction->multisigSignData();
155 * 2. Signer1:
156 * pendingTransaction = wallet->restoreMultisigTransaction(data);
157 * pendingTransaction->signMultisigTx();
158 * auto signed = pendingTransaction->multisigSignData();
159 * 3. Signer2:
160 * pendingTransaction = wallet->restoreMultisigTransaction(signed);
161 * pendingTransaction->signMultisigTx();
162 * pendingTransaction->commit();
163 */
164 virtual std::string multisigSignData() = 0;
165 virtual void signMultisigTx() = 0;
166 /**
167 * @brief signersKeys
168 * @return vector of base58-encoded signers' public keys
169 */
170 virtual std::vector<std::string> signersKeys() const = 0;
171 };
172
173 /**
174 * @brief Transaction-like interface for sending money
175 */
176 struct UnsignedTransaction
177 {
178 enum Status {
179 Status_Ok,
180 Status_Error,
181 Status_Critical
182 };
183
184 virtual ~UnsignedTransaction() = 0;
185 virtual int status() const = 0;
186 virtual std::string errorString() const = 0;
187 virtual std::vector<uint64_t> amount() const = 0;
188 virtual std::vector<uint64_t> fee() const = 0;
189 virtual std::vector<uint64_t> mixin() const = 0;
190 // returns a string with information about all transactions.
191 virtual std::string confirmationMessage() const = 0;
192 virtual std::vector<std::string> paymentId() const = 0;
193 virtual std::vector<std::string> recipientAddress() const = 0;
194 virtual uint64_t minMixinCount() const = 0;
195 /*!
196 * \brief txCount - number of transactions current transaction will be splitted to
197 * \return
198 */
199 virtual uint64_t txCount() const = 0;
200 /*!
201 * @brief sign - Sign txs and saves to file
202 * @param signedFileName
203 * return - true on success
204 */
205 virtual bool sign(const std::string &signedFileName) = 0;
206 virtual bool signToStr(std::string &data) = 0;
207 virtual void refresh() = 0;
208 virtual std::vector<TransactionConstructionInfo*> getAll() const = 0;
209 virtual TransactionConstructionInfo * transaction(int index) const = 0;
210 };
211
212 struct MultisigState {
213 MultisigState() : isMultisig(false), isReady(false), threshold(0), total(0) {}
214
215 bool isMultisig;
216 bool isReady;
217 uint32_t threshold;
218 uint32_t total;
219 };
220
221 struct DeviceProgress {
222 DeviceProgress(): m_progress(0), m_indeterminate(false) {}
223 DeviceProgress(double progress, bool indeterminate=false): m_progress(progress), m_indeterminate(indeterminate) {}
224
225 virtual double progress() const { return m_progress; }
226 virtual bool indeterminate() const { return m_indeterminate; }
227
228 protected:
229 double m_progress;
230 bool m_indeterminate;
231 };
232
233 struct Wallet;
234 struct WalletListener
235 {
236 virtual ~WalletListener() = 0;
237 /**
238 * @brief moneySpent - called when money spent
239 * @param txId - transaction id
240 * @param amount - amount
241 */
242 virtual void moneySpent(const std::string &txId, uint64_t amount) = 0;
243
244 /**
245 * @brief moneyReceived - called when money received
246 * @param txId - transaction id
247 * @param amount - amount
248 */
249 virtual void moneyReceived(const std::string &txId, uint64_t amount, bool coinbase) = 0;
250
251 /**
252 * @brief unconfirmedMoneyReceived - called when payment arrived in tx pool
253 * @param txId - transaction id
254 * @param amount - amount
255 */
256 virtual void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) = 0;
257
258 /**
259 * @brief newBlock - called when new block received
260 * @param height - block height
261 */
262 virtual void newBlock(uint64_t height) = 0;
263
264 /**
265 * @brief updated - generic callback, called when any event (sent/received/block reveived/etc) happened with the wallet;
266 */
267 virtual void updated() = 0;
268
269
270 /**
271 * @brief refreshed - called when wallet refreshed by background thread or explicitly refreshed by calling "refresh" synchronously
272 */
273 virtual void refreshed(bool success) = 0;
274
275 /**
276 * @brief called by device if the action is required
277 */
278 virtual void onDeviceButtonRequest(uint64_t code) { (void)code; }
279
280 /**
281 * @brief called by device if the button was pressed
282 */
283 virtual void onDeviceButtonPressed() { }
284
285 /**
286 * @brief called by device if an error occurred
287 */
288 virtual void onDeviceError(const std::string &msg, unsigned int errorCode) {};
289
290 /**
291 * @brief called by device when PIN is needed
292 */
293 virtual std::optional<std::string> onDevicePinRequest() {
294 throw std::runtime_error("Not supported");
295 }
296
297 /**
298 * @brief called by device when passphrase entry is needed
299 */
300 virtual std::optional<std::string> onDevicePassphraseRequest(bool & on_device) {
301 on_device = true;
302 return std::optional<std::string>();
303 }
304
305 /**
306 * @brief Signalizes device operation progress
307 */
308 virtual void onDeviceProgress(const DeviceProgress & event) { (void)event; };
309
310 /**
311 * @brief If the listener is created before the wallet this enables to set created wallet object
312 */
313 virtual void onSetWallet(Wallet * wallet) { (void)wallet; };
314 };
315
316
317 /**
318 * @brief Interface for wallet operations.
319 */
320 struct Wallet
321 {
322 enum Device {
323 Device_Software = 0,
324 Device_Ledger = 1,
325 Device_Trezor = 2
326 };
327
328 enum Status {
329 Status_Ok,
330 Status_Error,
331 Status_Critical,
332 Status_BadPassword
333 };
334
335 enum ConnectionStatus {
336 ConnectionStatus_Disconnected,
337 ConnectionStatus_Connected,
338 ConnectionStatus_WrongVersion
339 };
340
341 enum BackgroundSyncType {
342 BackgroundSync_Off = 0,
343 BackgroundSync_ReusePassword = 1,
344 BackgroundSync_CustomPassword = 2
345 };
346
347 virtual ~Wallet() = 0;
348 virtual std::string seed(const std::string& seed_offset = "") const = 0;
349 virtual std::string getSeedLanguage() const = 0;
350 virtual void setSeedLanguage(const std::string &arg) = 0;
351 //! returns wallet status (Status_Ok | Status_Error)
352 virtual int status() const = 0; //deprecated: use safe alternative statusWithErrorString
353 //! in case error status, returns error string
354 virtual std::string errorString() const = 0; //deprecated: use safe alternative statusWithErrorString
355 //! returns both error and error string atomically. suggested to use in instead of status() and errorString()
356 virtual void statusWithErrorString(int& status, std::string& errorString) const = 0;
357 virtual bool setPassword(const std::string &old_password, const std::string &new_password) = 0;
358 virtual bool verifyPassword(const std::string &password) const = 0;
359 virtual bool setDevicePin(const std::string &pin) { (void)pin; return false; };
360 virtual bool setDevicePassphrase(const std::string &passphrase) { (void)passphrase; return false; };
361 virtual std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const = 0;
362 virtual bool subaddressIndex(std::string address, std::pair<uint32_t, uint32_t> &index) const = 0;
363 std::string mainAddress() const { return address(0, 0); }
364 virtual std::string path() const = 0;
365 virtual NetworkType nettype() const = 0;
366 bool mainnet() const { return nettype() == MAINNET; }
367 bool testnet() const { return nettype() == TESTNET; }
368 bool stagenet() const { return nettype() == STAGENET; }
369 //! returns current hard fork info
370 virtual void hardForkInfo(uint8_t &version, uint64_t &earliest_height) const = 0;
371 //! check if hard fork rules should be used
372 virtual bool useForkRules(uint8_t version, int64_t early_blocks) const = 0;
373 /*!
374 * \brief integratedAddress - returns integrated address for current wallet address and given payment_id.
375 * if passed "payment_id" param is an empty string or not-valid payment id string
376 * (16 characters hexadecimal string) - random payment_id will be generated
377 *
378 * \param payment_id - 16 characters hexadecimal string or empty string if new random payment id needs to be
379 * generated
380 * \return - 106 characters string representing integrated address
381 */
382 virtual std::string integratedAddress(const std::string &payment_id) const = 0;
383
384 /*!
385 * \brief secretViewKey - returns secret view key
386 * \return - secret view key
387 */
388 virtual std::string secretViewKey() const = 0;
389
390 /*!
391 * \brief publicViewKey - returns public view key
392 * \return - public view key
393 */
394 virtual std::string publicViewKey() const = 0;
395
396 /*!
397 * \brief secretSpendKey - returns secret spend key
398 * \return - secret spend key
399 */
400 virtual std::string secretSpendKey() const = 0;
401
402 /*!
403 * \brief publicSpendKey - returns public spend key
404 * \return - public spend key
405 */
406 virtual std::string publicSpendKey() const = 0;
407
408 /*!
409 * \brief publicMultisigSignerKey - returns public signer key
410 * \return - public multisignature signer key or empty string if wallet is not multisig
411 */
412 virtual std::string publicMultisigSignerKey() const = 0;
413
414 /*!
415 * \brief stop - interrupts wallet refresh() loop once (doesn't stop background refresh thread)
416 */
417 virtual void stop() = 0;
418
419 /*!
420 * \brief store - stores wallet to file.
421 * \return
422 */
423 virtual bool store() = 0;
424 /*!
425 * \brief filename - returns wallet filename
426 * \return
427 */
428 virtual std::string filename() const = 0;
429 /*!
430 * \brief keysFilename - returns keys filename. usually this formed as "wallet_filename".keys
431 * \return
432 */
433 virtual std::string keysFilename() const = 0;
434 /*!
435 * \brief init - initializes wallet with daemon connection params.
436 * if daemon_address is local address, "trusted daemon" will be set to true forcibly
437 * startRefresh() should be called when wallet is initialized.
438 *
439 * \param daemon_address - daemon address in "hostname:port" format
440 * \param upper_transaction_size_limit
441 * \param daemon_username
442 * \param daemon_password
443 * \param lightWallet - start wallet in light mode, connect to a openmonero compatible server.
444 * \param proxy_address - set proxy address, empty string to disable
445 * \return - true on success
446 */
447 virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false, const std::string &proxy_address = "", bool use_dns = false) = 0;
448
449
450 virtual bool setDaemon(const std::string &daemon_address, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false) const = 0;
451
452 /*!
453 * \brief createWatchOnly - Creates a watch only wallet
454 * \param path - where to store the wallet
455 * \param password
456 * \param language
457 * \return - true if created successfully
458 */
459 virtual bool createWatchOnly(const std::string &path, const std::string &password, const std::string &language) const = 0;
460
461 /*!
462 * \brief setRefreshFromBlockHeight - start refresh from block height on recover
463 *
464 * \param refresh_from_block_height - blockchain start height
465 */
466 virtual void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) = 0;
467
468 /*!
469 * \brief getRestoreHeight - get wallet creation height
470 *
471 */
472 virtual uint64_t getRefreshFromBlockHeight() const = 0;
473
474 /*!
475 * \brief setRecoveringFromSeed - set state recover form seed
476 *
477 * \param recoveringFromSeed - true/false
478 */
479 virtual void setRecoveringFromSeed(bool recoveringFromSeed) = 0;
480
481 /*!
482 * \brief setRecoveringFromDevice - set state to recovering from device
483 *
484 * \param recoveringFromDevice - true/false
485 */
486 virtual void setRecoveringFromDevice(bool recoveringFromDevice) = 0;
487
488 /*!
489 * \brief setSubaddressLookahead - set size of subaddress lookahead
490 *
491 * \param major - size fot the major index
492 * \param minor - size fot the minor index
493 */
494 virtual void setSubaddressLookahead(uint32_t major, uint32_t minor) = 0;
495
496 /**
497 * @brief getSubaddressLookahead - get the current subaddress lookahead
498 * @return - <major>:<minor>
499 */
500 virtual std::pair<size_t, size_t> getSubaddressLookahead() = 0;
501
502 /**
503 * @brief connectToDaemon - connects to the daemon. TODO: check if it can be removed
504 * @return
505 */
506 virtual bool connectToDaemon() = 0;
507
508 /**
509 * @brief connected - checks if the wallet connected to the daemon
510 * @return - true if connected
511 */
512 virtual ConnectionStatus connected() const = 0;
513 virtual void setTrustedDaemon(bool arg) = 0;
514 virtual bool trustedDaemon() const = 0;
515 virtual bool setProxy(const std::string &address) = 0;
516 virtual uint64_t balance(uint32_t accountIndex = 0) const = 0;
517 uint64_t balanceAll() const {
518 uint64_t result = 0;
519 for (uint32_t i = 0; i < numSubaddressAccounts(); ++i)
520 result += balance(i);
521 return result;
522 }
523 virtual uint64_t unlockedBalance(uint32_t accountIndex = 0) const = 0;
524 uint64_t unlockedBalanceAll() const {
525 uint64_t result = 0;
526 for (uint32_t i = 0; i < numSubaddressAccounts(); ++i)
527 result += unlockedBalance(i);
528 return result;
529 }
530 virtual uint64_t viewOnlyBalance(uint32_t accountIndex, const std::vector<std::string> &key_images = {}) const = 0;
531
532 /**
533 * @brief watchOnly - checks if wallet is watch only
534 * @return - true if watch only
535 */
536 virtual bool watchOnly() const = 0;
537
538 /**
539 * @brief isDeterministic - checks if wallet keys are deterministic
540 * @return - true if deterministic
541 */
542 virtual bool isDeterministic() const = 0;
543
544 /**
545 * @brief blockChainHeight - returns current blockchain height
546 * @return
547 */
548 virtual uint64_t blockChainHeight() const = 0;
549
550 /**
551 * @brief approximateBlockChainHeight - returns approximate blockchain height calculated from date/time
552 * @return
553 */
554 virtual uint64_t approximateBlockChainHeight() const = 0;
555
556 /**
557 * @brief estimateBlockChainHeight - returns estimate blockchain height. More accurate than approximateBlockChainHeight,
558 * uses daemon height and falls back to calculation from date/time
559 * @return
560 **/
561 virtual uint64_t estimateBlockChainHeight() const = 0;
562 /**
563 * @brief daemonBlockChainHeight - returns daemon blockchain height
564 * @return 0 - in case error communicating with the daemon.
565 * status() will return Status_Error and errorString() will return verbose error description
566 */
567 virtual uint64_t daemonBlockChainHeight() const = 0;
568
569 /**
570 * @brief daemonBlockChainTargetHeight - returns daemon blockchain target height
571 * @return 0 - in case error communicating with the daemon.
572 * status() will return Status_Error and errorString() will return verbose error description
573 */
574 virtual uint64_t daemonBlockChainTargetHeight() const = 0;
575
576 /**
577 * @brief synchronized - checks if wallet was ever synchronized
578 * @return
579 */
580 virtual bool synchronized() const = 0;
581
582 static std::string displayAmount(uint64_t amount);
583 static uint64_t amountFromString(const std::string &amount);
584 static uint64_t amountFromDouble(double amount);
585 static std::string genPaymentId();
586 static bool paymentIdValid(const std::string &paiment_id);
587 static bool addressValid(const std::string &str, NetworkType nettype);
588 static bool addressValid(const std::string &str, bool testnet) // deprecated
589 {
590 return addressValid(str, testnet ? TESTNET : MAINNET);
591 }
592 static bool keyValid(const std::string &secret_key_string, const std::string &address_string, bool isViewKey, NetworkType nettype, std::string &error);
593 static bool keyValid(const std::string &secret_key_string, const std::string &address_string, bool isViewKey, bool testnet, std::string &error) // deprecated
594 {
595 return keyValid(secret_key_string, address_string, isViewKey, testnet ? TESTNET : MAINNET, error);
596 }
597 static std::string paymentIdFromAddress(const std::string &str, NetworkType nettype);
598 static std::string paymentIdFromAddress(const std::string &str, bool testnet) // deprecated
599 {
600 return paymentIdFromAddress(str, testnet ? TESTNET : MAINNET);
601 }
602 static std::string baseAddressFromIntegratedAddress(const std::string &str, NetworkType nettype);
603 static uint64_t maximumAllowedAmount();
604 // Easylogger wrapper
605 static void init(const char *argv0, const char *default_log_base_name) { init(argv0, default_log_base_name, "", true); }
606 static void init(const char *argv0, const char *default_log_base_name, const std::string &log_path, bool console);
607 static void debug(const std::string &category, const std::string &str);
608 static void info(const std::string &category, const std::string &str);
609 static void warning(const std::string &category, const std::string &str);
610 static void error(const std::string &category, const std::string &str);
611
612 /**
613 * @brief StartRefresh - Start/resume refresh thread (refresh every 10 seconds)
614 */
615 virtual void startRefresh() = 0;
616 /**
617 * @brief pauseRefresh - pause refresh thread
618 */
619 virtual void pauseRefresh() = 0;
620
621 /**
622 * @brief refresh - refreshes the wallet, updating transactions from daemon
623 * @return - true if refreshed successfully;
624 */
625 virtual bool refresh() = 0;
626
627 /**
628 * @brief refreshAsync - refreshes wallet asynchronously.
629 */
630 virtual void refreshAsync() = 0;
631
632 /**
633 * @brief rescanBlockchain - rescans the wallet, updating transactions from daemon
634 * @return - true if refreshed successfully;
635 */
636 virtual bool rescanBlockchain() = 0;
637
638 /**
639 * @brief rescanBlockchainAsync - rescans wallet asynchronously, starting from genesys
640 */
641 virtual void rescanBlockchainAsync() = 0;
642
643 /**
644 * @brief setAutoRefreshInterval - setup interval for automatic refresh.
645 * @param seconds - interval in millis. if zero or less than zero - automatic refresh disabled;
646 */
647 virtual void setAutoRefreshInterval(int millis) = 0;
648
649 /**
650 * @brief autoRefreshInterval - returns automatic refresh interval in millis
651 * @return
652 */
653 virtual int autoRefreshInterval() const = 0;
654
655 /**
656 * @brief addSubaddressAccount - appends a new subaddress account at the end of the last major index of existing subaddress accounts
657 * @param label - the label for the new account (which is the as the label of the primary address (accountIndex,0))
658 */
659 virtual void addSubaddressAccount(const std::string& label) = 0;
660 /**
661 * @brief numSubaddressAccounts - returns the number of existing subaddress accounts
662 */
663 virtual size_t numSubaddressAccounts() const = 0;
664 /**
665 * @brief numSubaddresses - returns the number of existing subaddresses associated with the specified subaddress account
666 * @param accountIndex - the major index specifying the subaddress account
667 */
668 virtual size_t numSubaddresses(uint32_t accountIndex) const = 0;
669 /**
670 * @brief addSubaddress - appends a new subaddress at the end of the last minor index of the specified subaddress account
671 * @param accountIndex - the major index specifying the subaddress account
672 * @param label - the label for the new subaddress
673 */
674 virtual void addSubaddress(uint32_t accountIndex, const std::string& label) = 0;
675 /**
676 * @brief getSubaddressLabel - gets the label of the specified subaddress
677 * @param accountIndex - the major index specifying the subaddress account
678 * @param addressIndex - the minor index specifying the subaddress
679 */
680 virtual std::string getSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex) const = 0;
681 /**
682 * @brief setSubaddressLabel - sets the label of the specified subaddress
683 * @param accountIndex - the major index specifying the subaddress account
684 * @param addressIndex - the minor index specifying the subaddress
685 * @param label - the new label for the specified subaddress
686 */
687 virtual void setSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex, const std::string &label) = 0;
688
689 /**
690 * @brief multisig - returns current state of multisig wallet creation process
691 * @return MultisigState struct
692 */
693 virtual MultisigState multisig() const = 0;
694 /**
695 * @brief getMultisigInfo
696 * @return serialized and signed multisig info string
697 */
698 virtual std::string getMultisigInfo() const = 0;
699 /**
700 * @brief makeMultisig - switches wallet in multisig state. The one and only creation phase for N / N wallets
701 * @param info - vector of multisig infos from other participants obtained with getMulitisInfo call
702 * @param threshold - number of required signers to make valid transaction. Must be <= number of participants
703 * @return in case of N / N wallets returns empty string since no more key exchanges needed. For N - 1 / N wallets returns base58 encoded extra multisig info
704 */
705 virtual std::string makeMultisig(const std::vector<std::string>& info, uint32_t threshold) = 0;
706 /**
707 * @brief exchange_multisig_keys - provides additional key exchange round for arbitrary multisig schemes (like N-1/N, M/N)
708 * @param info - base58 encoded key derivations returned by makeMultisig or exchangeMultisigKeys function call
709 * @param force_update_use_with_caution - force multisig account to update even if not all signers contribute round messages
710 * @return new info string if more rounds required or an empty string if wallet creation is done
711 */
712 virtual std::string exchangeMultisigKeys(const std::vector<std::string> &info, const bool force_update_use_with_caution) = 0;
713 /**
714 * @brief exportMultisigImages - exports transfers' key images
715 * @param images - output paramter for hex encoded array of images
716 * @return true if success
717 */
718 virtual bool exportMultisigImages(std::string& images) = 0;
719 /**
720 * @brief importMultisigImages - imports other participants' multisig images
721 * @param images - array of hex encoded arrays of images obtained with exportMultisigImages
722 * @return number of imported images
723 */
724 virtual size_t importMultisigImages(const std::vector<std::string>& images) = 0;
725 /**
726 * @brief hasMultisigPartialKeyImages - checks if wallet needs to import multisig key images from other participants
727 * @return true if there are partial key images
728 */
729 virtual bool hasMultisigPartialKeyImages() const = 0;
730
731 /**
732 * @brief restoreMultisigTransaction creates PendingTransaction from signData
733 * @param signData encrypted unsigned transaction. Obtained with PendingTransaction::multisigSignData
734 * @return PendingTransaction
735 */
736 virtual PendingTransaction* restoreMultisigTransaction(const std::string& signData) = 0;
737
738 /*!
739 * \brief createTransactionMultDest creates transaction with multiple destinations. if dst_addr is an integrated address, payment_id is ignored
740 * \param dst_addr vector of destination address as string
741 * \param payment_id optional payment_id, can be empty string
742 * \param amount vector of amounts
743 * \param mixin_count mixin count. if 0 passed, wallet will use default value
744 * \param subaddr_account subaddress account from which the input funds are taken
745 * \param subaddr_indices set of subaddress indices to use for transfer or sweeping. if set empty, all are chosen when sweeping, and one or more are automatically chosen when transferring. after execution, returns the set of actually used indices
746 * \param priority
747 * \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
748 * after object returned
749 */
750
751 virtual PendingTransaction * createTransactionMultDest(const std::vector<std::string> &dst_addr, const std::string &payment_id,
752 std::optional<std::vector<uint64_t>> amount, uint32_t mixin_count,
753 PendingTransaction::Priority = PendingTransaction::Priority_Low,
754 uint32_t subaddr_account = 0,
755 std::set<uint32_t> subaddr_indices = {}, const std::set<std::string> &preferred_inputs = {},
756 bool subtractFeeFromAmount = false) = 0;
757
758 /*!
759 * \brief createTransaction creates transaction. if dst_addr is an integrated address, payment_id is ignored
760 * \param dst_addr destination address as string
761 * \param payment_id optional payment_id, can be empty string
762 * \param amount amount
763 * \param mixin_count mixin count. if 0 passed, wallet will use default value
764 * \param subaddr_account subaddress account from which the input funds are taken
765 * \param subaddr_indices set of subaddress indices to use for transfer or sweeping. if set empty, all are chosen when sweeping, and one or more are automatically chosen when transferring. after execution, returns the set of actually used indices
766 * \param priority
767 * \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
768 * after object returned
769 */
770
771 virtual PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
772 std::optional<uint64_t> amount, uint32_t mixin_count,
773 PendingTransaction::Priority = PendingTransaction::Priority_Low,
774 uint32_t subaddr_account = 0,
775 std::set<uint32_t> subaddr_indices = {},
776 const std::set<std::string> &preferred_inputs = {},
777 bool subtractFeeFromAmount = false) = 0;
778
779 /*!
780 * \brief createTransactionSingle creates transaction with single input
781 * \param key_image key image as string
782 * \param dst_addr destination address as string
783 * \param priority
784 * \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
785 * after object returned
786 */
787
788 virtual PendingTransaction * createTransactionSingle(const std::string &key_image, const std::string &dst_addr,
789 size_t outputs = 1, PendingTransaction::Priority = PendingTransaction::Priority_Low) = 0;
790
791
792 /*!
793 * \brief createTransactionSelected creates transaction with selected inputs
794 * \param key_images vector of key images as string
795 * \param dst_addr destination address as string
796 * \param outputs split amount into this many outputs of equal amount
797 * \param priority transaction priority
798 * \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
799 * after object returned
800 */
801
802 virtual PendingTransaction * createTransactionSelected(const std::vector<std::string> &key_images, const std::string &dst_addr,
803 size_t outputs = 1, PendingTransaction::Priority = PendingTransaction::Priority_Low) = 0;
804
805
806 /*!
807 * \brief createSweepUnmixableTransaction creates transaction with unmixable outputs.
808 * \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
809 * after object returned
810 */
811
812 virtual PendingTransaction * createSweepUnmixableTransaction() = 0;
813
814 /*!
815 * \brief loadUnsignedTx - creates transaction from unsigned tx file
816 * \return - UnsignedTransaction object. caller is responsible to check UnsignedTransaction::status()
817 * after object returned
818 */
819 virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename) = 0;
820
821 /*!
822 * \brief loadUnsignedTx - creates transaction from unsigned tx string
823 * \return - UnsignedTransaction object. caller is responsible to check UnsignedTransaction::status()
824 * after object returned
825 */
826 virtual UnsignedTransaction * loadUnsignedTxFromStr(const std::string &unsigned_tx) = 0;
827
828 /*!
829 * \brief loadUnsignedTx - creates transaction from unsigned base64 encoded tx string
830 * \return - UnsignedTransaction object. caller is responsible to check UnsignedTransaction::status()
831 * after object returned
832 */
833 virtual UnsignedTransaction * loadUnsignedTxFromBase64Str(const std::string &unsigned_tx_base64) = 0;
834
835 /*!
836 * \brief loadSignedTx - creates transaction from signed tx file
837 * \return - PendingTransaction object.
838 */
839 virtual PendingTransaction * loadSignedTx(const std::string &signed_filename) = 0;
840 virtual PendingTransaction * loadSignedTxFromStr(const std::string &data) = 0;
841
842 /*!
843 * \brief submitTransaction - submits transaction in signed tx file
844 * \return - true on success
845 */
846 virtual bool submitTransaction(const std::string &fileName) = 0;
847
848 /*!
849 * \brief disposeTransaction - destroys transaction object
850 * \param t - pointer to the "PendingTransaction" object. Pointer is not valid after function returned;
851 */
852 virtual void disposeTransaction(PendingTransaction * t) = 0;
853
854 /*!
855 * \brief Estimates transaction fee.
856 * \param destinations Vector consisting of <address, amount> pairs.
857 * \return Estimated fee.
858 */
859 virtual uint64_t estimateTransactionFee(const std::vector<std::pair<std::string, uint64_t>> &destinations,
860 PendingTransaction::Priority priority) const = 0;
861
862 virtual bool hasUnknownKeyImages() const = 0;
863
864 /*!
865 * \brief exportKeyImages - exports key images to file
866 * \param filename
867 * \param all - export all key images or only those that have not yet been exported
868 * \return - true on success
869 */
870 virtual bool exportKeyImages(const std::string &filename, bool all = false) = 0;
871 virtual bool exportKeyImagesToStr(std::string &keyImages, bool all = false) = 0;
872 virtual bool exportKeyImagesForOutputsFromStr(const std::string &outputs, std::string &keyImages) = 0;
873
874 /*!
875 * \brief importKeyImages - imports key images from file
876 * \param filename
877 * \return - true on success
878 */
879 virtual bool importKeyImages(const std::string &filename) = 0;
880 virtual bool importKeyImagesFromStr(const std::string &keyImages) = 0;
881
882 /*!
883 * \brief importOutputs - exports outputs to file
884 * \param filename
885 * \return - true on success
886 */
887 virtual bool exportOutputs(const std::string &filename, bool all = false) = 0;
888 virtual bool exportOutputsToStr(std::string &outputs, bool all = false) = 0;
889
890 /*!
891 * \brief importOutputs - imports outputs from file
892 * \param filename
893 * \return - true on success
894 */
895 virtual bool importOutputs(const std::string &filename) = 0;
896 virtual bool importOutputsFromStr(const std::string &outputs) = 0;
897
898 /*!
899 * \brief scanTransactions - scan a list of transaction ids, this operation may reveal the txids to the remote node and affect your privacy
900 * \param txids - list of transaction ids
901 * \return - true on success
902 */
903 virtual bool scanTransactions(const std::vector<std::string> &txids) = 0;
904
905 /*!
906 * \brief setupBackgroundSync - setup background sync mode with just a view key
907 * \param background_sync_type - the mode the wallet background syncs in
908 * \param wallet_password
909 * \param background_cache_password - custom password to encrypt background cache, only needed for custom password background sync type
910 * \return - true on success
911 */
912 virtual bool setupBackgroundSync(const BackgroundSyncType background_sync_type, const std::string &wallet_password, const std::optional<std::string> &background_cache_password) = 0;
913
914 /*!
915 * \brief getBackgroundSyncType - get mode the wallet background syncs in
916 * \return - the type, or off if type is unknown
917 */
918 virtual BackgroundSyncType getBackgroundSyncType() const = 0;
919
920 /**
921 * @brief startBackgroundSync - sync the chain in the background with just view key
922 */
923 virtual bool startBackgroundSync() = 0;
924
925 /**
926 * @brief stopBackgroundSync - bring back spend key and process background synced txs
927 * \param wallet_password
928 */
929 virtual bool stopBackgroundSync(const std::string &wallet_password) = 0;
930
931 /**
932 * @brief isBackgroundSyncing - returns true if the wallet is background syncing
933 */
934 virtual bool isBackgroundSyncing() const = 0;
935
936 /**
937 * @brief isBackgroundWallet - returns true if the wallet is a background wallet
938 */
939 virtual bool isBackgroundWallet() const = 0;
940
941 virtual std::string printBlockchain() = 0;
942 virtual std::string printTransfers() = 0;
943 virtual std::string printPayments() = 0;
944 virtual std::string printUnconfirmedPayments() = 0;
945 virtual std::string printConfirmedTransferDetails() = 0;
946 virtual std::string printUnconfirmedTransferDetails() = 0;
947 virtual std::string printPubKeys() = 0;
948 virtual std::string printTxNotes() = 0;
949 virtual std::string printSubaddresses() = 0;
950 virtual std::string printSubaddressLabels() = 0;
951 virtual std::string printAdditionalTxKeys() = 0;
952 virtual std::string printAttributes() = 0;
953 virtual std::string printKeyImages() = 0;
954 virtual std::string printAccountTags() = 0;
955 virtual std::string printTxKeys() = 0;
956 virtual std::string printAddressBook() = 0;
957 virtual std::string printScannedPoolTxs() = 0;
958
959 /*!
960 * \brief haveTranscation - check if transaction is known to wallet
961 * @param txid
962 * @return - true if known
963 */
964 virtual bool haveTransaction(const std::string &txid) = 0;
965
966 virtual void setListener(WalletListener *) = 0;
967 /*!
968 * \brief defaultMixin - returns number of mixins used in transactions
969 * \return
970 */
971 virtual uint32_t defaultMixin() const = 0;
972 /*!
973 * \brief setDefaultMixin - setum number of mixins to be used for new transactions
974 * \param arg
975 */
976 virtual void setDefaultMixin(uint32_t arg) = 0;
977
978 virtual bool cacheAttributeExists(const std::string &key) = 0;
979 /*!
980 * \brief setCacheAttribute - attach an arbitrary string to a wallet cache attribute
981 * \param key - the key
982 * \param val - the value
983 * \return true if successful, false otherwise
984 */
985 virtual bool setCacheAttribute(const std::string &key, const std::string &val) = 0;
986 /*!
987 * \brief getCacheAttribute - return an arbitrary string attached to a wallet cache attribute
988 * \param key - the key
989 * \return the attached string, or empty string if there is none
990 */
991 virtual std::string getCacheAttribute(const std::string &key) const = 0;
992 /*!
993 * \brief setUserNote - attach an arbitrary string note to a txid
994 * \param txid - the transaction id to attach the note to
995 * \param note - the note
996 * \return true if successful, false otherwise
997 */
998 virtual bool setUserNote(const std::string &txid, const std::string &note) = 0;
999 /*!
1000 * \brief getUserNote - return an arbitrary string note attached to a txid
1001 * \param txid - the transaction id to attach the note to
1002 * \return the attached note, or empty string if there is none
1003 */
1004 virtual std::string getUserNote(const std::string &txid) const = 0;
1005 virtual std::string getTxKey(const std::string &txid) const = 0;
1006 virtual bool checkTxKey(const std::string &txid, std::string tx_key, const std::string &address, uint64_t &received, bool &in_pool, uint64_t &confirmations) = 0;
1007 virtual std::string getTxProof(const std::string &txid, const std::string &address, const std::string &message) const = 0;
1008 virtual bool checkTxProof(const std::string &txid, const std::string &address, const std::string &message, const std::string &signature, bool &good, uint64_t &received, bool &in_pool, uint64_t &confirmations) = 0;
1009 virtual std::string getSpendProof(const std::string &txid, const std::string &message) const = 0;
1010 virtual bool checkSpendProof(const std::string &txid, const std::string &message, const std::string &signature, bool &good) const = 0;
1011 /*!
1012 * \brief getReserveProof - Generates a proof that proves the reserve of unspent funds
1013 * Parameters `account_index` and `amount` are ignored when `all` is true
1014 */
1015 virtual std::string getReserveProof(bool all, uint32_t account_index, uint64_t amount, const std::string &message) const = 0;
1016 virtual bool checkReserveProof(const std::string &address, const std::string &message, const std::string &signature, bool &good, uint64_t &total, uint64_t &spent) const = 0;
1017
1018 /*
1019 * \brief signMessage - sign a message with the spend private key
1020 * \param message - the message to sign (arbitrary byte data)
1021 * \param address - the address to make the signature with, defaults to primary address (optional)
1022 * \return the signature, empty string if the address is invalid or does not belong to the wallet
1023 */
1024 virtual std::string signMessage(const std::string &message, const std::string &address = "") = 0;
1025 /*!
1026 * \brief verifySignedMessage - verify a signature matches a given message
1027 * \param message - the message (arbitrary byte data)
1028 * \param address - the address the signature claims to be made with
1029 * \param signature - the signature
1030 * \return true if the signature verified, false otherwise
1031 */
1032 virtual bool verifySignedMessage(const std::string &message, const std::string &addres, const std::string &signature) const = 0;
1033
1034 /*!
1035 * \brief signMultisigParticipant signs given message with the multisig public signer key
1036 * \param message message to sign
1037 * \return signature in case of success. Sets status to Error and return empty string in case of error
1038 */
1039 virtual std::string signMultisigParticipant(const std::string &message) const = 0;
1040 /*!
1041 * \brief verifyMessageWithPublicKey verifies that message was signed with the given public key
1042 * \param message message
1043 * \param publicKey hex encoded public key
1044 * \param signature signature of the message
1045 * \return true if the signature is correct. false and sets error state in case of error
1046 */
1047 virtual bool verifyMessageWithPublicKey(const std::string &message, const std::string &publicKey, const std::string &signature) const = 0;
1048
1049 virtual bool parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error) = 0;
1050 virtual std::string make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error) const = 0;
1051
1052 virtual std::string getDefaultDataDir() const = 0;
1053
1054 /*
1055 * \brief rescanSpent - Rescan spent outputs - Can only be used with trusted daemon
1056 * \return true on success
1057 */
1058 virtual bool rescanSpent() = 0;
1059
1060 /*
1061 * \brief setOffline - toggle set offline on/off
1062 * \param offline - true/false
1063 */
1064 virtual void setOffline(bool offline) = 0;
1065 virtual bool isOffline() const = 0;
1066
1067 //! blackballs a set of outputs
1068 virtual bool blackballOutputs(const std::vector<std::string> &outputs, bool add) = 0;
1069
1070 //! blackballs an output
1071 virtual bool blackballOutput(const std::string &amount, const std::string &offset) = 0;
1072
1073 //! unblackballs an output
1074 virtual bool unblackballOutput(const std::string &amount, const std::string &offset) = 0;
1075
1076 //! gets the ring used for a key image, if any
1077 virtual bool getRing(const std::string &key_image, std::vector<uint64_t> &ring) const = 0;
1078
1079 //! gets the rings used for a txid, if any
1080 virtual bool getRings(const std::string &txid, std::vector<std::pair<std::string, std::vector<uint64_t>>> &rings) const = 0;
1081
1082 //! sets the ring used for a key image
1083 virtual bool setRing(const std::string &key_image, const std::vector<uint64_t> &ring, bool relative) = 0;
1084
1085 //! sets whether pre-fork outs are to be segregated
1086 virtual void segregatePreForkOutputs(bool segregate) = 0;
1087
1088 //! sets the height where segregation should occur
1089 virtual void segregationHeight(uint64_t height) = 0;
1090
1091 //! secondary key reuse mitigation
1092 virtual void keyReuseMitigation2(bool mitigation) = 0;
1093
1094 //! Light wallet authenticate and login
1095 virtual bool lightWalletLogin(bool &isNewWallet) const = 0;
1096
1097 //! Initiates a light wallet import wallet request
1098 virtual bool lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status) = 0;
1099
1100 //! locks/unlocks the keys file; returns true on success
1101 virtual bool lockKeysFile() = 0;
1102 virtual bool unlockKeysFile() = 0;
1103 //! returns true if the keys file is locked
1104 virtual bool isKeysFileLocked() = 0;
1105
1106 /*!
1107 * \brief Queries backing device for wallet keys
1108 * \return Device they are on
1109 */
1110 virtual Device getDeviceType() const = 0;
1111
1112 //! cold-device protocol key image sync
1113 virtual uint64_t coldKeyImageSync(uint64_t &spent, uint64_t &unspent) = 0;
1114
1115 //! shows address on device display
1116 virtual void deviceShowAddress(uint32_t accountIndex, uint32_t addressIndex, const std::string &paymentId) = 0;
1117
1118 //! attempt to reconnect to hardware device
1119 virtual bool reconnectDevice() = 0;
1120
1121 //! get bytes received
1122 virtual uint64_t getBytesReceived() = 0;
1123
1124 //! get bytes sent
1125 virtual uint64_t getBytesSent() = 0;
1126
1127 //! is hw device connected
1128 virtual bool isDeviceConnected() = 0;
1129
1130 //! set ring database path
1131 virtual bool setRingDatabase(const std::string &path) = 0;
1132
1133 virtual tools::wallet2* getWallet() = 0;
1134 };
1135
1136 /**
1137 * @brief WalletManager - provides functions to manage wallets
1138 */
1139 struct WalletManager
1140 {
1141
1142 /*!
1143 * \brief Creates new wallet
1144 * \param path Name of wallet file
1145 * \param password Password of wallet file
1146 * \param language Language to be used to generate electrum seed mnemonic
1147 * \param nettype Network type
1148 * \param kdf_rounds Number of rounds for key derivation function
1149 * \return Wallet instance (Wallet::status() needs to be called to check if created successfully)
1150 */
1151 virtual Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language, NetworkType nettype, uint64_t kdf_rounds = 1) = 0;
1152 Wallet * createWallet(const std::string &path, const std::string &password, const std::string &language, bool testnet = false) // deprecated
1153 {
1154 return createWallet(path, password, language, testnet ? TESTNET : MAINNET);
1155 }
1156
1157 /*!
1158 * \brief Opens existing wallet
1159 * \param path Name of wallet file
1160 * \param password Password of wallet file
1161 * \param nettype Network type
1162 * \param kdf_rounds Number of rounds for key derivation function
1163 * \param listener Wallet listener to set to the wallet after creation
1164 * \return Wallet instance (Wallet::status() needs to be called to check if opened successfully)
1165 */
1166 virtual Wallet * openWallet(const std::string &path, const std::string &password, NetworkType nettype, uint64_t kdf_rounds = 1, const std::string &ringDatabasePath = "", WalletListener * listener = nullptr) = 0;
1167 Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) // deprecated
1168 {
1169 return openWallet(path, password, testnet ? TESTNET : MAINNET);
1170 }
1171
1172 /*!
1173 * \brief recovers existing wallet using mnemonic (electrum seed)
1174 * \param path Name of wallet file to be created
1175 * \param password Password of wallet file
1176 * \param mnemonic mnemonic (25 words electrum seed)
1177 * \param nettype Network type
1178 * \param restoreHeight restore from start height
1179 * \param kdf_rounds Number of rounds for key derivation function
1180 * \param seed_offset Seed offset passphrase (optional)
1181 * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
1182 */
1183 virtual Wallet * recoveryWallet(const std::string &path, const std::string &password, const std::string &mnemonic,
1184 NetworkType nettype = MAINNET, uint64_t restoreHeight = 0, uint64_t kdf_rounds = 1,
1185 const std::string &seed_offset = {}, const std::string &subaddressLookahead = "") = 0;
1186 Wallet * recoveryWallet(const std::string &path, const std::string &password, const std::string &mnemonic,
1187 bool testnet = false, uint64_t restoreHeight = 0) // deprecated
1188 {
1189 return recoveryWallet(path, password, mnemonic, testnet ? TESTNET : MAINNET, restoreHeight);
1190 }
1191
1192 /*!
1193 * \deprecated this method creates a wallet WITHOUT a passphrase, use the alternate recoverWallet() method
1194 * \brief recovers existing wallet using mnemonic (electrum seed)
1195 * \param path Name of wallet file to be created
1196 * \param mnemonic mnemonic (25 words electrum seed)
1197 * \param nettype Network type
1198 * \param restoreHeight restore from start height
1199 * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
1200 */
1201 virtual Wallet * recoveryWallet(const std::string &path, const std::string &mnemonic, NetworkType nettype, uint64_t restoreHeight = 0) = 0;
1202 Wallet * recoveryWallet(const std::string &path, const std::string &mnemonic, bool testnet = false, uint64_t restoreHeight = 0) // deprecated
1203 {
1204 return recoveryWallet(path, mnemonic, testnet ? TESTNET : MAINNET, restoreHeight);
1205 }
1206
1207 /*!
1208 * \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
1209 * \param path Name of wallet file to be created
1210 * \param password Password of wallet file
1211 * \param language language
1212 * \param nettype Network type
1213 * \param restoreHeight restore from start height
1214 * \param addressString public address
1215 * \param viewKeyString view key
1216 * \param spendKeyString spend key (optional)
1217 * \param kdf_rounds Number of rounds for key derivation function
1218 * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
1219 */
1220 virtual Wallet * createWalletFromKeys(const std::string &path,
1221 const std::string &password,
1222 const std::string &language,
1223 NetworkType nettype,
1224 uint64_t restoreHeight,
1225 const std::string &addressString,
1226 const std::string &viewKeyString,
1227 const std::string &spendKeyString = "",
1228 uint64_t kdf_rounds = 1,
1229 const std::string &subaddressLookahead = "") = 0;
1230 Wallet * createWalletFromKeys(const std::string &path,
1231 const std::string &password,
1232 const std::string &language,
1233 bool testnet,
1234 uint64_t restoreHeight,
1235 const std::string &addressString,
1236 const std::string &viewKeyString,
1237 const std::string &spendKeyString = "") // deprecated
1238 {
1239 return createWalletFromKeys(path, password, language, testnet ? TESTNET : MAINNET, restoreHeight, addressString, viewKeyString, spendKeyString);
1240 }
1241
1242 /*!
1243 * \brief recover deterministic wallet from spend key.
1244 * \param path Name of wallet file to be created
1245 * \param password Password of wallet file
1246 * \param language language
1247 * \param nettype Network type
1248 * \param restoreHeight restore from start height
1249 * \param spendKeyString spend key
1250 * \param kdf_rounds Number of rounds for key derivation function
1251 * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
1252 */
1253 virtual Wallet * createDeterministicWalletFromSpendKey(const std::string &path,
1254 const std::string &password,
1255 const std::string &language,
1256 NetworkType nettype,
1257 uint64_t restoreHeight,
1258 const std::string &spendKeyString,
1259 uint64_t kdf_rounds = 1,
1260 const std::string &offset_passphrase = "",
1261 const std::string &subaddressLookahead = "") = 0;
1262
1263 /*!
1264 * \deprecated this method creates a wallet WITHOUT a passphrase, use createWalletFromKeys(..., password, ...) instead
1265 * \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
1266 * \param path Name of wallet file to be created
1267 * \param language language
1268 * \param nettype Network type
1269 * \param restoreHeight restore from start height
1270 * \param addressString public address
1271 * \param viewKeyString view key
1272 * \param spendKeyString spend key (optional)
1273 * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
1274 */
1275 virtual Wallet * createWalletFromKeys(const std::string &path,
1276 const std::string &language,
1277 NetworkType nettype,
1278 uint64_t restoreHeight,
1279 const std::string &addressString,
1280 const std::string &viewKeyString,
1281 const std::string &spendKeyString = "") = 0;
1282 Wallet * createWalletFromKeys(const std::string &path,
1283 const std::string &language,
1284 bool testnet,
1285 uint64_t restoreHeight,
1286 const std::string &addressString,
1287 const std::string &viewKeyString,
1288 const std::string &spendKeyString = "") // deprecated
1289 {
1290 return createWalletFromKeys(path, language, testnet ? TESTNET : MAINNET, restoreHeight, addressString, viewKeyString, spendKeyString);
1291 }
1292
1293 /*!
1294 * \brief creates wallet using hardware device.
1295 * \param path Name of wallet file to be created
1296 * \param password Password of wallet file
1297 * \param nettype Network type
1298 * \param deviceName Device name
1299 * \param restoreHeight restore from start height (0 sets to current height)
1300 * \param subaddressLookahead Size of subaddress lookahead (empty sets to some default low value)
1301 * \param kdf_rounds Number of rounds for key derivation function
1302 * \param listener Wallet listener to set to the wallet after creation
1303 * \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
1304 */
1305 virtual Wallet * createWalletFromDevice(const std::string &path,
1306 const std::string &password,
1307 NetworkType nettype,
1308 const std::string &deviceName,
1309 uint64_t restoreHeight = 0,
1310 const std::string &subaddressLookahead = "",
1311 uint64_t kdf_rounds = 1,
1312 WalletListener * listener = nullptr) = 0;
1313
1314 /*!
1315 * \brief Closes wallet. In case operation succeeded, wallet object deleted. in case operation failed, wallet object not deleted
1316 * \param wallet previously opened / created wallet instance
1317 * \return None
1318 */
1319 virtual bool closeWallet(Wallet *wallet, bool store = true) = 0;
1320
1321 /*
1322 * ! checks if wallet with the given name already exists
1323 */
1324
1325 /*!
1326 * @brief TODO: delme walletExists - check if the given filename is the wallet
1327 * @param path - filename
1328 * @return - true if wallet exists
1329 */
1330 virtual bool walletExists(const std::string &path) = 0;
1331
1332 /*!
1333 * @brief verifyWalletPassword - check if the given filename is the wallet
1334 * @param keys_file_name - location of keys file
1335 * @param password - password to verify
1336 * @param no_spend_key - verify only view keys?
1337 * @param kdf_rounds - number of rounds for key derivation function
1338 * @return - true if password is correct
1339 *
1340 * @note
1341 * This function will fail when the wallet keys file is opened because the wallet program locks the keys file.
1342 * In this case, Wallet::unlockKeysFile() and Wallet::lockKeysFile() need to be called before and after the call to this function, respectively.
1343 */
1344 virtual bool verifyWalletPassword(const std::string &keys_file_name, const std::string &password, bool no_spend_key, uint64_t kdf_rounds = 1) const = 0;
1345
1346 /*!
1347 * \brief determine the key storage for the specified wallet file
1348 * \param device_type (OUT) wallet backend as enumerated in Wallet::Device
1349 * \param keys_file_name Keys file to verify password for
1350 * \param password Password to verify
1351 * \return true if password correct, else false
1352 *
1353 * for verification only - determines key storage hardware
1354 *
1355 */
1356 virtual bool queryWalletDevice(Wallet::Device& device_type, const std::string &keys_file_name, const std::string &password, uint64_t kdf_rounds = 1) const = 0;
1357
1358 /*!
1359 * \brief findWallets - searches for the wallet files by given path name recursively
1360 * \param path - starting point to search
1361 * \return - list of strings with found wallets (absolute paths);
1362 */
1363 virtual std::vector<std::string> findWallets(const std::string &path) = 0;
1364
1365 //! returns verbose error string regarding last error;
1366 virtual std::string errorString() const = 0;
1367
1368 //! set the daemon address (hostname and port)
1369 virtual void setDaemonAddress(const std::string &address) = 0;
1370
1371 //! returns whether the daemon can be reached, and its version number
1372 virtual bool connected(uint32_t *version = NULL) = 0;
1373
1374 //! returns current blockchain height
1375 virtual uint64_t blockchainHeight() = 0;
1376
1377 //! returns current blockchain target height
1378 virtual uint64_t blockchainTargetHeight() = 0;
1379
1380 //! returns current network difficulty
1381 virtual uint64_t networkDifficulty() = 0;
1382
1383 //! returns current mining hash rate (0 if not mining)
1384 virtual double miningHashRate() = 0;
1385
1386 //! returns current block target
1387 virtual uint64_t blockTarget() = 0;
1388
1389 //! returns true iff mining
1390 virtual bool isMining() = 0;
1391
1392 //! starts mining with the set number of threads
1393 virtual bool startMining(const std::string &address, uint32_t threads = 1, bool background_mining = false, bool ignore_battery = true) = 0;
1394
1395 //! stops mining
1396 virtual bool stopMining() = 0;
1397
1398 //! resolves an OpenAlias address to a monero address
1399 virtual std::string resolveOpenAlias(const std::string &address, bool &dnssec_valid) const = 0;
1400
1401 //! checks for an update and returns version, hash and url
1402 static std::tuple<bool, std::string, std::string, std::string, std::string> checkUpdates(
1403 const std::string &software,
1404 std::string subdir,
1405 const char *buildtag = nullptr,
1406 const char *current_version = nullptr);
1407
1408 //! sets proxy address, empty string to disable
1409 virtual bool setProxy(const std::string &address) = 0;
1410 };
1411
1412
1413 struct WalletManagerFactory
1414 {
1415 // logging levels for underlying library
1416 enum LogLevel {
1417 LogLevel_Silent = -1,
1418 LogLevel_0 = 0,
1419 LogLevel_1 = 1,
1420 LogLevel_2 = 2,
1421 LogLevel_3 = 3,
1422 LogLevel_4 = 4,
1423 LogLevel_Min = LogLevel_Silent,
1424 LogLevel_Max = LogLevel_4
1425 };
1426
1427 static WalletManager * getWalletManager();
1428 static void setLogLevel(int level);
1429 static void setLogCategories(const std::string &categories);
1430 };
1431
1432
1433 }