ledger-core
BitcoinLikeWallet.hpp
1 /*
2  *
3  * BitcoinLikeWallet
4  * ledger-core
5  *
6  * Created by Pierre Pollastri on 19/12/2016.
7  *
8  * The MIT License (MIT)
9  *
10  * Copyright (c) 2016 Ledger
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this software and associated documentation files (the "Software"), to deal
14  * in the Software without restriction, including without limitation the rights
15  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  * copies of the Software, and to permit persons to whom the Software is
17  * furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included in all
20  * copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *
30  */
31 #ifndef LEDGER_CORE_BITCOINLIKEWALLET_HPP
32 #define LEDGER_CORE_BITCOINLIKEWALLET_HPP
33 
34 #include "api/BitcoinLikeWallet.hpp"
35 #include <memory>
36 #include "explorers/BitcoinLikeBlockchainExplorer.hpp"
37 #include "keychains/BitcoinLikeKeychain.hpp"
38 #include "observers/BitcoinLikeBlockchainObserver.hpp"
39 #include "synchronizers/BitcoinLikeAccountSynchronizer.hpp"
40 #include "wallet/common/AbstractWallet.hpp"
41 #include "api/BitcoinLikeNetworkParameters.hpp"
42 #include "wallet/bitcoin/factories/BitcoinLikeWalletFactory.hpp"
43 #include "wallet/bitcoin/database/BitcoinLikeWalletDatabase.h"
44 
45 namespace ledger {
46  namespace core {
47  class BitcoinLikeWallet : public virtual api::BitcoinLikeWallet, public virtual AbstractWallet {
48  public:
49  static const api::WalletType type;
50  using BitcoinLikeAccountSynchronizerFactory = std::function<std::shared_ptr<BitcoinLikeAccountSynchronizer> ()>;
52  const std::string& name,
53  const std::shared_ptr<BitcoinLikeBlockchainExplorer>& explorer,
54  const std::shared_ptr<BitcoinLikeBlockchainObserver>& observer,
55  const std::shared_ptr<BitcoinLikeKeychainFactory>& keychainFactory,
56  const BitcoinLikeAccountSynchronizerFactory& synchronizerFactory,
57  const std::shared_ptr<WalletPool>& pool,
58  const api::Currency& network,
59  const std::shared_ptr<DynamicObject>& configuration,
60  const DerivationScheme& scheme
61  );
62 
63  // API methods
64  bool isSynchronizing() override;
65  std::shared_ptr<api::EventBus> synchronize() override;
66 
67  FuturePtr<ledger::core::api::Account> newAccountWithInfo(const api::AccountCreationInfo &info) override;
68 
70  newAccountWithExtendedKeyInfo(const api::ExtendedKeyAccountCreationInfo &info) override;
71 
73  getExtendedKeyAccountCreationInfo(int32_t accountIndex) override;
74 
75  Future<api::AccountCreationInfo> getAccountCreationInfo(int32_t accountIndex) override;
76 
77  std::shared_ptr<BitcoinLikeBlockchainExplorer> getBlockchainExplorer();
78 
79  protected:
80  std::shared_ptr<AbstractAccount>
81  createAccountInstance(soci::session &sql, const std::string &accountUid) override;
82 
83  private:
84  std::shared_ptr<BitcoinLikeWallet> getSelf();
85 
86  private:
87  std::shared_ptr<BitcoinLikeBlockchainExplorer> _explorer;
88  std::shared_ptr<BitcoinLikeBlockchainObserver> _observer;
89  std::shared_ptr<BitcoinLikeKeychainFactory> _keychainFactory;
90  BitcoinLikeAccountSynchronizerFactory _synchronizerFactory;
91  };
92  }
93 }
94 
95 
96 #endif //LEDGER_CORE_BITCOINLIKEWALLET_HPP
Definition: AbstractWallet.hpp:61
std::shared_ptr< api::EventBus > synchronize() override
Definition: BitcoinLikeWallet.cpp:67
bool isSynchronizing() override
Definition: BitcoinLikeWallet.cpp:63
Definition: Deffered.hpp:49
Definition: ExtendedKeyAccountCreationInfo.hpp:16
Definition: DerivationScheme.hpp:55
Definition: Currency.hpp:23
Definition: Account.cpp:8
WalletType
Definition: WalletType.hpp:20
Definition: BitcoinLikeWallet.hpp:47
Definition: BitcoinLikeWallet.hpp:17
Definition: AccountCreationInfo.hpp:16