31 #ifndef LEDGER_CORE_ABSTRACTWALLET_HPP 32 #define LEDGER_CORE_ABSTRACTWALLET_HPP 34 #include "api/Wallet.hpp" 35 #include <api/Currency.hpp> 36 #include <api/Account.hpp> 37 #include <preferences/Preferences.hpp> 38 #include <async/DedicatedContext.hpp> 39 #include <events/EventPublisher.hpp> 40 #include <debug/logger.hpp> 41 #include <api/WalletType.hpp> 42 #include <database/DatabaseSessionPool.hpp> 43 #include <collections/DynamicObject.hpp> 44 #include <utils/DerivationScheme.hpp> 45 #include <api/AccountCreationInfo.hpp> 46 #include <api/ExtendedKeyAccountCreationInfo.hpp> 47 #include <api/AccountCreationInfoCallback.hpp> 48 #include <api/ExtendedKeyAccountCreationInfoCallback.hpp> 49 #include <api/AccountCallback.hpp> 50 #include <api/Block.hpp> 51 #include <api/BlockCallback.hpp> 52 #include <api/DynamicObject.hpp> 53 #include <utils/TTLCache.h> 54 #include <wallet/common/Amount.h> 60 class AbstractAccount;
65 const std::shared_ptr<WalletPool>& pool,
66 const std::shared_ptr<DynamicObject>& configuration,
69 std::shared_ptr<api::EventBus>
getEventBus()
override;
74 std::shared_ptr<api::Logger>
getLogger()
override;
77 std::shared_ptr<WalletPool> getPool()
const;
84 void getNextAccountIndex(
const std::shared_ptr<api::I32Callback> &callback)
override;
87 void getAccountCount(
const std::shared_ptr<api::I32Callback> &callback)
override;
89 void getLastBlock(
const std::shared_ptr<api::BlockCallback> &callback)
override;
93 std::shared_ptr<T> asInstanceOf() {
95 if (type == T::type) {
96 return std::dynamic_pointer_cast<T>(shared_from_this());
98 throw make_exception(
api::ErrorCode::BAD_CAST,
"Wallet of type {} cannot be cast to {}", api::to_string(type), api::to_string(T::type));
101 void getAccount(int32_t index,
const std::shared_ptr<api::AccountCallback> &callback)
override;
104 getAccounts(int32_t offset, int32_t count,
const std::shared_ptr<api::AccountListCallback> &callback)
override;
107 void getNextAccountCreationInfo(
const std::shared_ptr<api::AccountCreationInfoCallback> &callback)
override;
108 void getNextExtendedKeyAccountCreationInfo(
109 const std::shared_ptr<api::ExtendedKeyAccountCreationInfoCallback> &callback)
override;
111 void getAccountCreationInfo(int32_t accountIndex,
112 const std::shared_ptr<api::AccountCreationInfoCallback> &callback)
override;
114 void getExtendedKeyAccountCreationInfo(int32_t accountIndex,
115 const std::shared_ptr<api::ExtendedKeyAccountCreationInfoCallback> &callback)
override;
118 const std::shared_ptr<api::AccountCallback> &callback)
override;
122 const std::shared_ptr<api::AccountCallback> &callback)
override;
124 void eraseDataSince(
const std::chrono::system_clock::time_point & date,
const std::shared_ptr<api::ErrorCodeCallback> & callback)
override ;
130 void updateBalanceCache(
size_t accountIndex,
Amount balance);
139 virtual std::shared_ptr<Preferences> getAccountExternalPreferences(int32_t index);
140 virtual std::shared_ptr<Preferences> getAccountInternalPreferences(int32_t index);
141 virtual std::shared_ptr<Preferences> getInternalPreferences()
const;
142 virtual std::shared_ptr<Preferences> getExternalPreferences()
const;
143 virtual std::shared_ptr<EventPublisher> getEventPublisher()
const;
144 virtual std::shared_ptr<spdlog::logger>
logger()
const;
145 virtual std::shared_ptr<DatabaseSessionPool> getDatabase()
const;
146 virtual std::shared_ptr<api::ExecutionContext> getMainExecutionContext()
const;
147 virtual std::string getWalletUid()
const;
148 virtual std::shared_ptr<DynamicObject> getConfig()
const;
152 virtual std::shared_ptr<AbstractAccount> createAccountInstance(soci::session& sql,
const std::string& accountUid) = 0;
153 void addAccountInstanceToInstanceCache(
const std::shared_ptr<AbstractAccount>& account);
158 std::shared_ptr<spdlog::logger> _logger;
159 std::shared_ptr<api::Logger> _loggerApi;
160 std::shared_ptr<EventPublisher> _publisher;
161 std::shared_ptr<Preferences> _externalPreferences;
162 std::shared_ptr<Preferences> _internalPreferences;
163 std::shared_ptr<DatabaseSessionPool> _database;
165 std::shared_ptr<api::ExecutionContext> _mainExecutionContext;
166 std::shared_ptr<DynamicObject> _configuration;
168 std::weak_ptr<WalletPool> _pool;
169 std::unordered_map<int32_t, std::shared_ptr<AbstractAccount>> _accounts;
176 #endif //LEDGER_CORE_ABSTRACTWALLET_HPP api::WalletType getWalletType() override
Definition: AbstractWallet.cpp:116
bool isInstanceOfRippleLikeWallet() override
Definition: AbstractWallet.cpp:92
api::Currency getCurrency() override
Definition: AbstractWallet.cpp:136
Definition: AbstractWallet.hpp:61
std::shared_ptr< api::Preferences > getPreferences() override
Definition: AbstractWallet.cpp:80
std::shared_ptr< api::EventBus > getEventBus() override
Definition: AbstractWallet.cpp:76
bool isInstanceOfEthereumLikeWallet() override
Definition: AbstractWallet.cpp:88
Definition: Option.hpp:49
std::shared_ptr< api::Logger > getLogger() override
Definition: AbstractWallet.cpp:112
std::shared_ptr< api::DynamicObject > getConfiguration() override
Definition: AbstractWallet.cpp:355
Definition: Deffered.hpp:49
Definition: ExtendedKeyAccountCreationInfo.hpp:16
Definition: DerivationScheme.hpp:55
std::shared_ptr< api::BitcoinLikeWallet > asBitcoinLikeWallet() override
Definition: AbstractWallet.cpp:144
std::shared_ptr< api::Preferences > getAccountPreferences(int32_t index) override
Definition: AbstractWallet.cpp:128
Definition: Wallet.hpp:39
Definition: Currency.hpp:23
Definition: Account.cpp:8
WalletType
Definition: WalletType.hpp:20
bool isInstanceOfBitcoinLikeWallet() override
Definition: AbstractWallet.cpp:84
std::string getName() override
Definition: AbstractWallet.cpp:140
Definition: DedicatedContext.hpp:39
Definition: AccountCreationInfo.hpp:16
Definition: TTLCache.h:45
Definition: logger.hpp:44