ledger-core
OperationQuery.h
1 /*
2  *
3  * OperationQuery
4  * ledger-core
5  *
6  * Created by Pierre Pollastri on 03/07/2017.
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_OPERATIONQUERY_H
32 #define LEDGER_CORE_OPERATIONQUERY_H
33 
34 #include <api/OperationQuery.hpp>
35 #include <api/OperationOrderKey.hpp>
36 #include <database/query/QueryBuilder.h>
37 #include <database/DatabaseSessionPool.hpp>
38 #include <async/DedicatedContext.hpp>
39 #include "Operation.h"
40 #include "../common/api_impl/OperationApi.h"
41 #include "AbstractAccount.hpp"
42 #include <unordered_map>
43 #include "api_impl/OperationApi.h"
44 
45 namespace ledger {
46  namespace core {
47  class AbstractAccount;
48  class OperationQuery : public api::OperationQuery, public std::enable_shared_from_this<OperationQuery>,
49  public DedicatedContext {
50  public:
51  OperationQuery( const std::shared_ptr<api::QueryFilter>& headFilter,
52  const std::shared_ptr<DatabaseSessionPool>& pool,
53  const std::shared_ptr<api::ExecutionContext>& context,
54  const std::shared_ptr<api::ExecutionContext>& mainContext
55  );
56  std::shared_ptr<api::OperationQuery> addOrder(api::OperationOrderKey key, bool descending) override;
57  std::shared_ptr<api::QueryFilter> filter() override;
58  std::shared_ptr<api::OperationQuery> offset(int64_t from) override;
59  std::shared_ptr<api::OperationQuery> limit(int64_t count) override;
60  std::shared_ptr<api::OperationQuery> complete() override;
61  std::shared_ptr<api::OperationQuery> partial() override;
62 
63  void execute(const std::shared_ptr<api::OperationListCallback> &callback) override;
65 
66  std::shared_ptr<OperationQuery> registerAccount(const std::shared_ptr<AbstractAccount>& account);
67 
68  private:
69  void performExecute(std::vector<std::shared_ptr<api::Operation>>& operations);
70  void inflateCompleteTransaction(soci::session& sql, const std::string &accountUid, OperationApi& operation);
71  void inflateBitcoinLikeTransaction(soci::session& sql, const std::string &accountUid, OperationApi& operation);
72  void inflateRippleLikeTransaction(soci::session& sql, OperationApi& operation);
73  void inflateTezosLikeTransaction(soci::session& sql, OperationApi& operation);
74  void inflateEthereumLikeTransaction(soci::session& sql, OperationApi& operation);
75  void inflateMoneroLikeTransaction(soci::session& sql, OperationApi& operation);
76 
77  protected:
78  virtual soci::rowset<soci::row> performExecute(soci::session &sql);
79  QueryBuilder _builder;
80  std::shared_ptr<api::QueryFilter> _headFilter;
81  bool _fetchCompleteOperation;
82  std::shared_ptr<api::ExecutionContext> _mainContext;
83  std::shared_ptr<DatabaseSessionPool> _pool;
84  std::unordered_map<std::string, std::shared_ptr<AbstractAccount>> _accounts;
85  };
86  }
87 }
88 
89 
90 #endif //LEDGER_CORE_OPERATIONQUERY_H
std::shared_ptr< api::OperationQuery > partial() override
Definition: OperationQuery.cpp:105
Definition: QueryBuilder.h:42
Definition: OperationQuery.h:48
Definition: Deffered.hpp:49
Definition: OperationApi.h:41
std::shared_ptr< api::OperationQuery > complete() override
Definition: OperationQuery.cpp:100
Definition: OperationQuery.hpp:24
Definition: Account.cpp:8
std::shared_ptr< api::OperationQuery > offset(int64_t from) override
Definition: OperationQuery.cpp:90
std::shared_ptr< api::OperationQuery > limit(int64_t count) override
Definition: OperationQuery.cpp:95
std::shared_ptr< api::QueryFilter > filter() override
Definition: OperationQuery.cpp:86
Definition: DedicatedContext.hpp:39
std::shared_ptr< api::OperationQuery > addOrder(api::OperationOrderKey key, bool descending) override
Definition: OperationQuery.cpp:56