ledger-core
RippleLikeAccount.h
1 /*
2  *
3  * RippleLikeAccount
4  *
5  * Created by El Khalil Bellakrid on 06/01/2019.
6  *
7  * The MIT License (MIT)
8  *
9  * Copyright (c) 2019 Ledger
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in all
19  * copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  *
29  */
30 
31 
32 #ifndef LEDGER_CORE_RIPPLELIKEACCOUNT_H
33 #define LEDGER_CORE_RIPPLELIKEACCOUNT_H
34 
35 
36 #include <time.h>
37 #include <api/AddressListCallback.hpp>
38 #include <api/AmountCallback.hpp>
39 #include <api/Address.hpp>
40 #include <api/RippleLikeAccount.hpp>
41 #include <api/RippleLikeTransactionBuilder.hpp>
42 #include <api/StringCallback.hpp>
43 #include <api/Event.hpp>
44 #include <api/BoolCallback.hpp>
45 #include <wallet/common/AbstractWallet.hpp>
46 #include <wallet/common/AbstractAccount.hpp>
47 #include <wallet/common/Amount.h>
48 #include <wallet/ripple/explorers/RippleLikeBlockchainExplorer.h>
49 #include <wallet/ripple/synchronizers/RippleLikeAccountSynchronizer.h>
50 #include <wallet/ripple/observers/RippleLikeBlockchainObserver.h>
51 #include <wallet/ripple/keychains/RippleLikeKeychain.h>
52 
53 namespace ledger {
54  namespace core {
56  public:
57 
58  static const int FLAG_TRANSACTION_IGNORED = 0x00;
59  static const int FLAG_NEW_TRANSACTION = 0x01;
60  static const int FLAG_TRANSACTION_UPDATED = 0x01 << 1;
61 
62  RippleLikeAccount(const std::shared_ptr<AbstractWallet> &wallet,
63  int32_t index,
64  const std::shared_ptr<RippleLikeBlockchainExplorer> &explorer,
65  const std::shared_ptr<RippleLikeBlockchainObserver> &observer,
66  const std::shared_ptr<RippleLikeAccountSynchronizer> &synchronizer,
67  const std::shared_ptr<RippleLikeKeychain> &keychain);
68 
69  FuturePtr<RippleLikeBlockchainExplorerTransaction> getTransaction(const std::string &hash);
70 
71  void inflateOperation(Operation &out,
72  const std::shared_ptr<const AbstractWallet> &wallet,
74 
75  int putTransaction(soci::session &sql, const RippleLikeBlockchainExplorerTransaction &transaction);
76 
77  bool putBlock(soci::session &sql, const RippleLikeBlockchainExplorer::Block &block);
78 
79  std::shared_ptr<RippleLikeKeychain> getKeychain() const;
80 
81  FuturePtr<Amount> getBalance() override;
82 
83  Future<AbstractAccount::AddressList> getFreshPublicAddresses() override;
84 
86  getBalanceHistory(const std::string &start,
87  const std::string &end,
88  api::TimePeriod precision) override;
89 
90  Future<api::ErrorCode> eraseDataSince(const std::chrono::system_clock::time_point &date) override;
91 
92  bool isSynchronizing() override;
93 
94  std::shared_ptr<api::EventBus> synchronize() override;
95 
96  void startBlockchainObservation() override;
97 
98  void stopBlockchainObservation() override;
99 
100  bool isObservingBlockchain() override;
101 
102  std::string getRestoreKey() override;
103 
104  void broadcastRawTransaction(const std::vector<uint8_t> &transaction,
105  const std::shared_ptr<api::StringCallback> &callback) override;
106 
107  void broadcastTransaction(const std::shared_ptr<api::RippleLikeTransaction> &transaction,
108  const std::shared_ptr<api::StringCallback> &callback) override;
109 
110  std::shared_ptr<api::RippleLikeTransactionBuilder> buildTransaction() override;
111 
112  std::shared_ptr<api::OperationQuery> queryOperations() override;
113 
114  void getFees(const std::shared_ptr<api::AmountCallback> & callback) override;
115  FuturePtr<api::Amount> getFees();
116 
117  void getBaseReserve(const std::shared_ptr<api::AmountCallback> & callback) override;
118  FuturePtr<api::Amount> getBaseReserve();
119 
120  void isAddressActivated(const std::string &address,
121  const std::shared_ptr<api::BoolCallback> &isActivated) override;
122  Future<bool> isAddressActivated(const std::string &address);
123  private:
124  std::shared_ptr<RippleLikeAccount> getSelf();
125 
126  std::shared_ptr<RippleLikeKeychain> _keychain;
127  std::string _accountAddress;
128  std::shared_ptr<RippleLikeBlockchainExplorer> _explorer;
129  std::shared_ptr<RippleLikeAccountSynchronizer> _synchronizer;
130  std::shared_ptr<RippleLikeBlockchainObserver> _observer;
131  std::shared_ptr<api::EventBus> _currentSyncEventBus;
132  std::mutex _synchronizationLock;
133  uint64_t _currentLedgerSequence;
134  };
135  }
136 }
137 
138 #endif //LEDGER_CORE_RIPPLELIKEACCOUNT_H
Definition: RippleLikeAccount.hpp:28
void startBlockchainObservation() override
Definition: RippleLikeAccount.cpp:361
Definition: AbstractAccount.hpp:55
Definition: Deffered.hpp:49
bool isSynchronizing() override
Definition: RippleLikeAccount.cpp:306
std::shared_ptr< api::EventBus > synchronize() override
Definition: RippleLikeAccount.cpp:311
std::string getRestoreKey() override
Definition: RippleLikeAccount.cpp:373
Definition: RippleLikeBlockchainExplorer.h:55
bool isObservingBlockchain() override
Definition: RippleLikeAccount.cpp:369
Definition: Operation.h:53
std::shared_ptr< api::OperationQuery > queryOperations() override
Definition: RippleLikeAccount.cpp:184
Definition: Account.cpp:8
void stopBlockchainObservation() override
Definition: RippleLikeAccount.cpp:365
Definition: Block.h:40
Definition: RippleLikeAccount.h:55