| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#ifndef WALLET_IMPL_H |
| 32 |
#define WALLET_IMPL_H |
| 33 |
|
| 34 |
#include "wallet/api/wallet2_api.h" |
| 35 |
#include "wallet/wallet2.h" |
| 36 |
|
| 37 |
#include <string> |
| 38 |
#include <boost/thread/mutex.hpp> |
| 39 |
#include <boost/thread/thread.hpp> |
| 40 |
#include <boost/thread/condition_variable.hpp> |
| 41 |
|
| 42 |
|
| 43 |
namespace Monero { |
| 44 |
class TransactionHistoryImpl; |
| 45 |
class PendingTransactionImpl; |
| 46 |
class UnsignedTransactionImpl; |
| 47 |
class AddressBookImpl; |
| 48 |
class SubaddressImpl; |
| 49 |
class SubaddressAccountImpl; |
| 50 |
struct Wallet2CallbackImpl; |
| 51 |
|
| 52 |
class WalletImpl : public Wallet |
| 53 |
{ |
| 54 |
public: |
| 55 |
WalletImpl(NetworkType nettype = MAINNET, uint64_t kdf_rounds = 1); |
| 56 |
~WalletImpl(); |
| 57 |
bool create(const std::string &path, const std::string &password, |
| 58 |
const std::string &language); |
| 59 |
bool createWatchOnly(const std::string &path, const std::string &password, |
| 60 |
const std::string &language) const override; |
| 61 |
bool open(const std::string &path, const std::string &password); |
| 62 |
bool recover(const std::string &path,const std::string &password, |
| 63 |
const std::string &seed, const std::string &seed_offset = {}); |
| 64 |
bool recoverFromKeysWithPassword(const std::string &path, |
| 65 |
const std::string &password, |
| 66 |
const std::string &language, |
| 67 |
const std::string &address_string, |
| 68 |
const std::string &viewkey_string, |
| 69 |
const std::string &spendkey_string = ""); |
| 70 |
|
| 71 |
|
| 72 |
bool recover(const std::string &path, const std::string &seed); |
| 73 |
|
| 74 |
bool recoverFromKeys(const std::string &path, |
| 75 |
const std::string &language, |
| 76 |
const std::string &address_string, |
| 77 |
const std::string &viewkey_string, |
| 78 |
const std::string &spendkey_string = ""); |
| 79 |
bool recoverFromDevice(const std::string &path, |
| 80 |
const std::string &password, |
| 81 |
const std::string &device_name); |
| 82 |
Device getDeviceType() const override; |
| 83 |
bool close(bool store = true); |
| 84 |
std::string seed(const std::string& seed_offset = "") const override; |
| 85 |
std::string getSeedLanguage() const override; |
| 86 |
void setSeedLanguage(const std::string &arg) override; |
| 87 |
|
| 88 |
int status() const override; |
| 89 |
std::string errorString() const override; |
| 90 |
void statusWithErrorString(int& status, std::string& errorString) const override; |
| 91 |
bool setPassword(const std::string &password) override; |
| 92 |
const std::string& getPassword() const override; |
| 93 |
bool setDevicePin(const std::string &password) override; |
| 94 |
bool setDevicePassphrase(const std::string &password) override; |
| 95 |
std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const override; |
| 96 |
std::string integratedAddress(const std::string &payment_id) const override; |
| 97 |
std::string secretViewKey() const override; |
| 98 |
std::string publicViewKey() const override; |
| 99 |
std::string secretSpendKey() const override; |
| 100 |
std::string publicSpendKey() const override; |
| 101 |
std::string publicMultisigSignerKey() const override; |
| 102 |
std::string path() const override; |
| 103 |
void stop() override; |
| 104 |
bool store(const std::string &path) override; |
| 105 |
std::string filename() const override; |
| 106 |
std::string keysFilename() const override; |
| 107 |
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 = "") override; |
| 108 |
bool connectToDaemon() override; |
| 109 |
ConnectionStatus connected() const override; |
| 110 |
void setTrustedDaemon(bool arg) override; |
| 111 |
bool trustedDaemon() const override; |
| 112 |
bool setProxy(const std::string &address) override; |
| 113 |
uint64_t balance(uint32_t accountIndex = 0) const override; |
| 114 |
uint64_t unlockedBalance(uint32_t accountIndex = 0) const override; |
| 115 |
uint64_t blockChainHeight() const override; |
| 116 |
uint64_t approximateBlockChainHeight() const override; |
| 117 |
uint64_t estimateBlockChainHeight() const override; |
| 118 |
uint64_t daemonBlockChainHeight() const override; |
| 119 |
uint64_t daemonBlockChainTargetHeight() const override; |
| 120 |
bool synchronized() const override; |
| 121 |
bool refresh() override; |
| 122 |
void refreshAsync() override; |
| 123 |
bool rescanBlockchain() override; |
| 124 |
void rescanBlockchainAsync() override; |
| 125 |
void setAutoRefreshInterval(int millis) override; |
| 126 |
int autoRefreshInterval() const override; |
| 127 |
void setRefreshFromBlockHeight(uint64_t refresh_from_block_height) override; |
| 128 |
uint64_t getRefreshFromBlockHeight() const override { return m_wallet->get_refresh_from_block_height(); }; |
| 129 |
void setRecoveringFromSeed(bool recoveringFromSeed) override; |
| 130 |
void setRecoveringFromDevice(bool recoveringFromDevice) override; |
| 131 |
void setSubaddressLookahead(uint32_t major, uint32_t minor) override; |
| 132 |
bool watchOnly() const override; |
| 133 |
bool isDeterministic() const override; |
| 134 |
bool rescanSpent() override; |
| 135 |
NetworkType nettype() const override {return static_cast<NetworkType>(m_wallet->nettype());} |
| 136 |
void hardForkInfo(uint8_t &version, uint64_t &earliest_height) const override; |
| 137 |
bool useForkRules(uint8_t version, int64_t early_blocks) const override; |
| 138 |
|
| 139 |
void addSubaddressAccount(const std::string& label) override; |
| 140 |
size_t numSubaddressAccounts() const override; |
| 141 |
size_t numSubaddresses(uint32_t accountIndex) const override; |
| 142 |
void addSubaddress(uint32_t accountIndex, const std::string& label) override; |
| 143 |
std::string getSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex) const override; |
| 144 |
void setSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex, const std::string &label) override; |
| 145 |
|
| 146 |
MultisigState multisig() const override; |
| 147 |
std::string getMultisigInfo() const override; |
| 148 |
std::string makeMultisig(const std::vector<std::string>& info, uint32_t threshold) override; |
| 149 |
std::string exchangeMultisigKeys(const std::vector<std::string> &info, const bool force_update_use_with_caution = false) override; |
| 150 |
bool exportMultisigImages(std::string& images) override; |
| 151 |
size_t importMultisigImages(const std::vector<std::string>& images) override; |
| 152 |
bool hasMultisigPartialKeyImages() const override; |
| 153 |
PendingTransaction* restoreMultisigTransaction(const std::string& signData) override; |
| 154 |
|
| 155 |
PendingTransaction * createTransactionMultDest(const std::vector<std::string> &dst_addr, const std::string &payment_id, |
| 156 |
optional<std::vector<uint64_t>> amount, uint32_t mixin_count, |
| 157 |
PendingTransaction::Priority priority = PendingTransaction::Priority_Low, |
| 158 |
uint32_t subaddr_account = 0, |
| 159 |
std::set<uint32_t> subaddr_indices = {}) override; |
| 160 |
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id, |
| 161 |
optional<uint64_t> amount, uint32_t mixin_count, |
| 162 |
PendingTransaction::Priority priority = PendingTransaction::Priority_Low, |
| 163 |
uint32_t subaddr_account = 0, |
| 164 |
std::set<uint32_t> subaddr_indices = {}) override; |
| 165 |
virtual PendingTransaction * createSweepUnmixableTransaction() override; |
| 166 |
bool submitTransaction(const std::string &fileName) override; |
| 167 |
virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename) override; |
| 168 |
bool exportKeyImages(const std::string &filename, bool all = false) override; |
| 169 |
bool importKeyImages(const std::string &filename) override; |
| 170 |
bool exportOutputs(const std::string &filename, bool all = false) override; |
| 171 |
bool importOutputs(const std::string &filename) override; |
| 172 |
bool scanTransactions(const std::vector<std::string> &txids) override; |
| 173 |
|
| 174 |
bool setupBackgroundSync(const BackgroundSyncType background_sync_type, const std::string &wallet_password, const optional<std::string> &background_cache_password = optional<std::string>()) override; |
| 175 |
BackgroundSyncType getBackgroundSyncType() const override; |
| 176 |
bool startBackgroundSync() override; |
| 177 |
bool stopBackgroundSync(const std::string &wallet_password) override; |
| 178 |
bool isBackgroundSyncing() const override; |
| 179 |
bool isBackgroundWallet() const override; |
| 180 |
|
| 181 |
virtual void disposeTransaction(PendingTransaction * t) override; |
| 182 |
virtual uint64_t estimateTransactionFee(const std::vector<std::pair<std::string, uint64_t>> &destinations, |
| 183 |
PendingTransaction::Priority priority) const override; |
| 184 |
virtual TransactionHistory * history() override; |
| 185 |
virtual AddressBook * addressBook() override; |
| 186 |
virtual Subaddress * subaddress() override; |
| 187 |
virtual SubaddressAccount * subaddressAccount() override; |
| 188 |
virtual void setListener(WalletListener * l) override; |
| 189 |
virtual uint32_t defaultMixin() const override; |
| 190 |
virtual void setDefaultMixin(uint32_t arg) override; |
| 191 |
|
| 192 |
virtual bool setCacheAttribute(const std::string &key, const std::string &val) override; |
| 193 |
virtual std::string getCacheAttribute(const std::string &key) const override; |
| 194 |
|
| 195 |
virtual void setOffline(bool offline) override; |
| 196 |
virtual bool isOffline() const override; |
| 197 |
|
| 198 |
virtual bool setUserNote(const std::string &txid, const std::string ¬e) override; |
| 199 |
virtual std::string getUserNote(const std::string &txid) const override; |
| 200 |
virtual std::string getTxKey(const std::string &txid) const override; |
| 201 |
virtual bool checkTxKey(const std::string &txid, std::string tx_key, const std::string &address, uint64_t &received, bool &in_pool, uint64_t &confirmations) override; |
| 202 |
virtual std::string getTxProof(const std::string &txid, const std::string &address, const std::string &message) const override; |
| 203 |
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) override; |
| 204 |
virtual std::string getSpendProof(const std::string &txid, const std::string &message) const override; |
| 205 |
virtual bool checkSpendProof(const std::string &txid, const std::string &message, const std::string &signature, bool &good) const override; |
| 206 |
virtual std::string getReserveProof(bool all, uint32_t account_index, uint64_t amount, const std::string &message) const override; |
| 207 |
virtual bool checkReserveProof(const std::string &address, const std::string &message, const std::string &signature, bool &good, uint64_t &total, uint64_t &spent) const override; |
| 208 |
virtual std::string signMessage(const std::string &message, const std::string &address) override; |
| 209 |
virtual bool verifySignedMessage(const std::string &message, const std::string &address, const std::string &signature) const override; |
| 210 |
virtual std::string signMultisigParticipant(const std::string &message) const override; |
| 211 |
virtual bool verifyMessageWithPublicKey(const std::string &message, const std::string &publicKey, const std::string &signature) const override; |
| 212 |
virtual void startRefresh() override; |
| 213 |
virtual void pauseRefresh() override; |
| 214 |
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) override; |
| 215 |
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 override; |
| 216 |
virtual std::string getDefaultDataDir() const override; |
| 217 |
virtual bool lightWalletLogin(bool &isNewWallet) const override; |
| 218 |
virtual bool lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status) override; |
| 219 |
virtual bool blackballOutputs(const std::vector<std::string> &outputs, bool add) override; |
| 220 |
virtual bool blackballOutput(const std::string &amount, const std::string &offset) override; |
| 221 |
virtual bool unblackballOutput(const std::string &amount, const std::string &offset) override; |
| 222 |
virtual bool getRing(const std::string &key_image, std::vector<uint64_t> &ring) const override; |
| 223 |
virtual bool getRings(const std::string &txid, std::vector<std::pair<std::string, std::vector<uint64_t>>> &rings) const override; |
| 224 |
virtual bool setRing(const std::string &key_image, const std::vector<uint64_t> &ring, bool relative) override; |
| 225 |
virtual void segregatePreForkOutputs(bool segregate) override; |
| 226 |
virtual void segregationHeight(uint64_t height) override; |
| 227 |
virtual void keyReuseMitigation2(bool mitigation) override; |
| 228 |
virtual bool lockKeysFile() override; |
| 229 |
virtual bool unlockKeysFile() override; |
| 230 |
virtual bool isKeysFileLocked() override; |
| 231 |
virtual uint64_t coldKeyImageSync(uint64_t &spent, uint64_t &unspent) override; |
| 232 |
virtual void deviceShowAddress(uint32_t accountIndex, uint32_t addressIndex, const std::string &paymentId) override; |
| 233 |
virtual bool reconnectDevice() override; |
| 234 |
virtual uint64_t getBytesReceived() override; |
| 235 |
virtual uint64_t getBytesSent() override; |
| 236 |
|
| 237 |
private: |
| 238 |
void clearStatus() const; |
| 239 |
void setStatusError(const std::string& message) const; |
| 240 |
void setStatusCritical(const std::string& message) const; |
| 241 |
void setStatus(int status, const std::string& message) const; |
| 242 |
void refreshThreadFunc(); |
| 243 |
void doRefresh(); |
| 244 |
bool daemonSynced() const; |
| 245 |
void stopRefresh(); |
| 246 |
bool isNewWallet() const; |
| 247 |
void pendingTxPostProcess(PendingTransactionImpl * pending); |
| 248 |
bool doInit(const std::string &daemon_address, const std::string &proxy_address, uint64_t upper_transaction_size_limit = 0, bool ssl = false); |
| 249 |
bool checkBackgroundSync(const std::string &message) const; |
| 250 |
|
| 251 |
private: |
| 252 |
friend class PendingTransactionImpl; |
| 253 |
friend class UnsignedTransactionImpl; |
| 254 |
friend class TransactionHistoryImpl; |
| 255 |
friend struct Wallet2CallbackImpl; |
| 256 |
friend class AddressBookImpl; |
| 257 |
friend class SubaddressImpl; |
| 258 |
friend class SubaddressAccountImpl; |
| 259 |
|
| 260 |
std::unique_ptr<tools::wallet2> m_wallet; |
| 261 |
mutable boost::mutex m_statusMutex; |
| 262 |
mutable int m_status; |
| 263 |
mutable std::string m_errorString; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
std::string m_password; |
| 269 |
std::unique_ptr<TransactionHistoryImpl> m_history; |
| 270 |
std::unique_ptr<Wallet2CallbackImpl> m_wallet2Callback; |
| 271 |
std::unique_ptr<AddressBookImpl> m_addressBook; |
| 272 |
std::unique_ptr<SubaddressImpl> m_subaddress; |
| 273 |
std::unique_ptr<SubaddressAccountImpl> m_subaddressAccount; |
| 274 |
|
| 275 |
|
| 276 |
std::atomic<bool> m_refreshEnabled; |
| 277 |
std::atomic<bool> m_refreshThreadDone; |
| 278 |
std::atomic<int> m_refreshIntervalMillis; |
| 279 |
std::atomic<bool> m_refreshShouldRescan; |
| 280 |
|
| 281 |
boost::mutex m_refreshMutex; |
| 282 |
|
| 283 |
|
| 284 |
boost::mutex m_refreshMutex2; |
| 285 |
boost::condition_variable m_refreshCV; |
| 286 |
boost::thread m_refreshThread; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
std::atomic<bool> m_recoveringFromSeed; |
| 291 |
std::atomic<bool> m_recoveringFromDevice; |
| 292 |
std::atomic<bool> m_synchronized; |
| 293 |
std::atomic<bool> m_rebuildWalletCache; |
| 294 |
|
| 295 |
mutable std::atomic<bool> m_is_connected; |
| 296 |
boost::optional<epee::net_utils::http::login> m_daemon_login{}; |
| 297 |
}; |
| 298 |
|
| 299 |
|
| 300 |
} |
| 301 |
|
| 302 |
#endif |