Debian Codegraph @

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