ledger-core
TezosLikeOriginatedAccount.h
1 /*
2  *
3  * TezosLikeOriginatedAccount
4  *
5  * Created by El Khalil Bellakrid on 17/05/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_TEZOSLIKEORIGINATEDACCOUNT_H
33 #define LEDGER_CORE_TEZOSLIKEORIGINATEDACCOUNT_H
34 
35 #include <string>
36 #include <api/TezosLikeOriginatedAccount.hpp>
37 #include <api/OperationQuery.hpp>
38 #include <utils/Option.hpp>
39 #include <wallet/tezos/TezosLikeAccount.h>
40 #include <wallet/common/OperationQuery.h>
41 #include <api/Amount.hpp>
42 #include <api/AmountCallback.hpp>
43 #include <api/AmountListCallback.hpp>
44 #include <api/TimePeriod.hpp>
45 namespace ledger {
46  namespace core {
48  public:
49  TezosOriginatedOperationQuery(const std::shared_ptr<api::QueryFilter>& headFilter,
50  const std::shared_ptr<DatabaseSessionPool>& pool,
51  const std::shared_ptr<api::ExecutionContext>& context,
52  const std::shared_ptr<api::ExecutionContext>& mainContext) : OperationQuery(headFilter, pool, context, mainContext) {
53 
54  };
55  protected:
56  virtual soci::rowset<soci::row> performExecute(soci::session &sql) {
57  return _builder.select("o.account_uid, o.uid, o.wallet_uid, o.type, o.date, o.senders, o.recipients,"
58  "o.amount, o.fees, o.currency_name, o.trust, b.hash, b.height, b.time, orig_op.uid"
59  )
60  .from("operations").to("o")
61  .outerJoin("blocks AS b", "o.block_uid = b.uid")
62  .outerJoin("tezos_originated_operations AS orig_op", "o.uid = orig_op.uid")
63  .execute(sql);
64 
65  };
66  };
68  public:
69  TezosLikeOriginatedAccount(const std::string &uid,
70  const std::string &address,
71  const std::shared_ptr<TezosLikeAccount> &originatorAccount,
72  bool isSpendable,
73  bool isDelegatable,
74  const Option<std::string> &publicKey = Option<std::string>());
75 
76  std::string getAccountUid();
77 
78  std::string getAddress() override;
79 
80  std::experimental::optional<std::string> getPublicKey() override;
81 
82  void getBalance(const std::shared_ptr<api::AmountCallback> & callback) override;
83  FuturePtr<api::Amount> getBalance(const std::shared_ptr<api::ExecutionContext>& context);
84 
85  void getBalanceHistory(const std::chrono::system_clock::time_point & start,
86  const std::chrono::system_clock::time_point & end,
87  api::TimePeriod period,
88  const std::shared_ptr<api::AmountListCallback> & callback) override;
89 
90  Future<std::vector<std::shared_ptr<api::Amount>>> getBalanceHistory(const std::shared_ptr<api::ExecutionContext>& context,
91  const std::chrono::system_clock::time_point & start,
92  const std::chrono::system_clock::time_point & end,
93  api::TimePeriod period);
94 
95  bool isSpendable() override;
96 
97  bool isDelegatable() override;
98 
99  std::shared_ptr<api::OperationQuery> queryOperations() override;
100 
101  void setPublicKey(const std::string &publicKey);
102 
103  std::shared_ptr<api::TezosLikeTransactionBuilder> buildTransaction() override;
104 
105  private:
106  std::string _accountUid;
107  std::string _address;
108  Option<std::string> _publicKey;
109  bool _isSpendable;
110  bool _isDelegatable;
111  std::weak_ptr<TezosLikeAccount> _originatorAccount;
112  };
113  }
114 }
115 #endif //LEDGER_CORE_TEZOSLIKEORIGINATEDACCOUNT_H
Definition: OperationQuery.h:48
Definition: Deffered.hpp:49
Definition: TezosLikeOriginatedAccount.hpp:28
Definition: TezosLikeOriginatedAccount.h:67
Definition: Account.cpp:8
Definition: TezosLikeOriginatedAccount.h:47