ledger-core
ExternalTezosLikeBlockchainExplorer.h
1 /*
2  *
3  * ExternalTezosLikeBlockchainExplorer
4  *
5  * Created by El Khalil Bellakrid on 20/10/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 #pragma once
32 #include <wallet/common/explorers/AbstractLedgerApiBlockchainExplorer.h>
33 #include <wallet/tezos/explorers/TezosLikeBlockchainExplorer.h>
34 #include <wallet/tezos/explorers/api/TezosLikeTransactionsParser.h>
35 #include <wallet/tezos/explorers/api/TezosLikeTransactionsBulkParser.h>
36 #include <wallet/tezos/explorers/api/TezosLikeBlockParser.h>
37 #include <api/TezosLikeNetworkParameters.hpp>
38 
39 namespace ledger {
40  namespace core {
41  using ExternalApiBlockchainExplorer = AbstractLedgerApiBlockchainExplorer<
42  TezosLikeBlockchainExplorerTransaction,
43  TezosLikeBlockchainExplorer::TransactionsBulk,
44  TezosLikeTransactionsParser,
45  TezosLikeTransactionsBulkParser,
46  TezosLikeBlockParser,
47  api::TezosLikeNetworkParameters>;
48 
51  public DedicatedContext,
52  public std::enable_shared_from_this<ExternalTezosLikeBlockchainExplorer> {
53  public:
54  ExternalTezosLikeBlockchainExplorer(const std::shared_ptr<api::ExecutionContext> &context,
55  const std::shared_ptr<HttpClient> &http,
56  const api::TezosLikeNetworkParameters &parameters,
57  const std::shared_ptr<api::DynamicObject> &configuration);
58 
60  getBalance(const std::vector<TezosLikeKeychain::Address> &addresses) override;
61 
63  getFees() override;
64 
65  Future<String> pushLedgerApiTransaction(const std::vector<uint8_t> &transaction) override;
66 
67  Future<void *> startSession() override;
68 
69  Future<Unit> killSession(void *session) override;
70 
71  Future<Bytes> getRawTransaction(const String &transactionHash) override;
72 
73  Future<String> pushTransaction(const std::vector<uint8_t> &transaction) override;
74 
76  getTransactions(const std::vector<std::string> &addresses,
77  Option<std::string> fromBlockHash = Option<std::string>(),
78  Option<void *> session = Option<void *>()) override;
79 
80  FuturePtr<Block> getCurrentBlock() const override;
81 
83  getTransactionByHash(const String &transactionHash) const override;
84 
85  Future<int64_t> getTimestamp() const override;
86 
87  std::shared_ptr<api::ExecutionContext> getExplorerContext() const override;
88 
89  api::TezosLikeNetworkParameters getNetworkParameters() const override;
90 
91  std::string getExplorerVersion() const override;
92 
94  getEstimatedGasLimit(const std::string &address) override;
95 
97  getStorage(const std::string &address) override;
98 
99  Future<std::shared_ptr<BigInt>> getCounter(const std::string &address) override;
100 
101  Future<std::vector<uint8_t>> forgeKTOperation(const std::shared_ptr<TezosLikeTransactionApi> &tx) override;
102 
103  Future<std::string> getManagerKey(const std::string &address) override;
104 
105  Future<bool> isAllocated(const std::string &address) override;
106  private:
107  /*
108  * Helper to a get specific field's value from given url
109  * WARNING: this is only useful for fields with an integer (decimal representation) value (with a string type)
110  * @param url : base url to fetch the value on,
111  * @param field: name of field we are interested into,
112  * @param params: additional params to query value of field
113  * @return BigInt representing the value of targetted field
114  */
116  getHelper(const std::string &url,
117  const std::string &field,
118  const std::unordered_map<std::string, std::string> &params = std::unordered_map<std::string, std::string>(),
119  const std::string &fallbackValue = "",
120  const std::string &forceUrl = "",
121  bool isDecimal = false);
122 
123  api::TezosLikeNetworkParameters _parameters;
124  std::unordered_map<std::string, uint64_t> _sessions;
125  };
126  }
127 }
Definition: Deffered.hpp:49
Definition: ExternalTezosLikeBlockchainExplorer.h:49
Definition: TezosLikeBlockchainExplorer.h:108
Definition: AbstractLedgerApiBlockchainExplorer.h:51
Definition: Account.cpp:8
Definition: DedicatedContext.hpp:39