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