ledger-core
LedgerApiEthereumLikeBlockchainExplorer.h
1 /*
2  *
3  * LedgerApiEthereumLikeBlockchainExplorer
4  *
5  * Created by El Khalil Bellakrid on 29/07/2018.
6  *
7  * The MIT License (MIT)
8  *
9  * Copyright (c) 2018 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_LEDGERAPIETHEREUMLIKEBLOCKCHAINEXPLORER_H
33 #define LEDGER_CORE_LEDGERAPIETHEREUMLIKEBLOCKCHAINEXPLORER_H
34 
35 #include <wallet/common/explorers/AbstractLedgerApiBlockchainExplorer.h>
36 #include <wallet/ethereum/explorers/EthereumLikeBlockchainExplorer.h>
37 #include <wallet/ethereum/explorers/api/EthereumLikeTransactionsParser.h>
38 #include <wallet/ethereum/explorers/api/EthereumLikeTransactionsBulkParser.h>
39 #include <wallet/ethereum/explorers/api/EthereumLikeBlockParser.hpp>
40 #include <api/EthereumLikeNetworkParameters.hpp>
41 
42 namespace ledger {
43  namespace core {
44  using LedgerApiEthBlockchainExplorer = AbstractLedgerApiBlockchainExplorer<EthereumLikeBlockchainExplorerTransaction, EthereumLikeBlockchainExplorer::TransactionsBulk, EthereumLikeTransactionsParser, EthereumLikeTransactionsBulkParser, EthereumLikeBlockParser, api::EthereumLikeNetworkParameters>;
47  public DedicatedContext,
48  public std::enable_shared_from_this<LedgerApiEthereumLikeBlockchainExplorer>{
49  public:
50  LedgerApiEthereumLikeBlockchainExplorer(const std::shared_ptr<api::ExecutionContext>& context,
51  const std::shared_ptr<HttpClient>& http,
52  const api::EthereumLikeNetworkParameters& parameters,
53  const std::shared_ptr<api::DynamicObject>& configuration);
54  Future<std::shared_ptr<BigInt>> getNonce(const std::string &address) override;
55  Future<std::shared_ptr<BigInt>> getBalance(const std::vector<EthereumLikeKeychain::Address> &addresses) override;
56  Future<std::shared_ptr<BigInt>> getGasPrice() override;
57  Future<std::shared_ptr<BigInt>> getEstimatedGasLimit(const std::string &address) override;
58 
60  getERC20Balance(const std::string &address,
61  const std::string &erc20Address) override;
63  getERC20Balances(const std::string &address,
64  const std::vector<std::string> &erc20Addresses) override;
65 
66  Future<String> pushLedgerApiTransaction(const std::vector<uint8_t> &transaction) override;
67  Future<void *> startSession() override;
68  Future<Unit> killSession(void *session) override;
69  Future<Bytes> getRawTransaction(const String& transactionHash) override;
70  Future<String> pushTransaction(const std::vector<uint8_t>& transaction) override;
71 
73  getTransactions(const std::vector<std::string> &addresses, Option<std::string> fromBlockHash = Option<std::string>(),
74  Option<void *> session = Option<void *>()) override;
75 
76  FuturePtr<Block> getCurrentBlock() const override;
77  FuturePtr<EthereumLikeBlockchainExplorerTransaction> getTransactionByHash(const String &transactionHash) const override;
78 
79  Future<int64_t > getTimestamp() const override;
80 
81  std::shared_ptr<api::ExecutionContext> getExplorerContext() const override;
82  api::EthereumLikeNetworkParameters getNetworkParameters() const override;
83  std::string getExplorerVersion() const override;
84 
85  private:
86  Future<std::shared_ptr<BigInt>> getHelper(const std::string &url,
87  const std::string &field);
89  std::string _explorerVersion;
90  };
91  }
92 }
93 
94 
95 #endif //LEDGER_CORE_LEDGERAPIETHEREUMLIKEBLOCKCHAINEXPLORER_H
Definition: LedgerApiEthereumLikeBlockchainExplorer.h:45
Definition: Deffered.hpp:49
Definition: EthereumLikeBlockchainExplorer.h:113
Definition: AbstractLedgerApiBlockchainExplorer.h:51
Definition: Account.cpp:8
Definition: DedicatedContext.hpp:39
Definition: EthereumLikeNetworkParameters.hpp:15