ledger-core
EthereumLikeBlockchainExplorer.h
1 /*
2  *
3  * EthereumLikeBlockchainExplorer
4  *
5  * Created by El Khalil Bellakrid on 14/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_ETHEREUMBLOCKCHAINEXPLORER_H
33 #define LEDGER_CORE_ETHEREUMBLOCKCHAINEXPLORER_H
34 
35 #include <string>
36 
37 #include <api/DynamicObject.hpp>
38 #include <api/ExecutionContext.hpp>
39 #include <api/EthereumLikeNetworkParameters.hpp>
40 #include <api/Operation.hpp>
41 #include <async/DedicatedContext.hpp>
42 #include <collections/DynamicObject.hpp>
43 #include <math/BigInt.h>
44 #include <net/HttpClient.hpp>
45 #include <utils/ConfigurationMatchable.h>
46 #include <utils/Option.hpp>
47 #include <wallet/common/Block.h>
48 #include <wallet/common/explorers/AbstractBlockchainExplorer.h>
49 #include <wallet/ethereum/keychains/EthereumLikeKeychain.hpp>
50 namespace ledger {
51  namespace core {
52 
54  std::string from;
55  std::string to;
56  std::string contractAddress;
57  BigInt value;
58  api::OperationType type;
59  };
60 
61  struct InternalTx {
62  std::string from;
63  std::string to;
64  BigInt value;
65  BigInt gasLimit;
66  Option<BigInt> gasUsed;
67  api::OperationType type;
68  std::vector<uint8_t> inputData;
69  };
70 
72  std::string hash;
73  std::chrono::system_clock::time_point receivedAt;
74  BigInt value;
75  BigInt gasPrice;
76  BigInt gasLimit;
77  Option<BigInt> gasUsed;
78  std::string receiver;
79  std::string sender;
80  uint64_t nonce;
81  Option<Block> block;
82  uint64_t confirmations;
83  std::vector<uint8_t> inputData;
84  uint64_t status;
85  std::vector<InternalTx> internalTransactions;
86  std::vector<ERC20Transaction> erc20Transactions;
88  nonce = 0;
89  confirmations = 0;
90  status = 0;
91  }
92 
94  this->block = cpy.block;
95  this->hash = cpy.hash;
96  this->receivedAt = cpy.receivedAt;
97  this->confirmations = cpy.confirmations;
98  this->gasUsed = cpy.gasUsed;
99  this->gasLimit = cpy.gasLimit;
100  this->gasPrice = cpy.gasPrice;
101  this->inputData = cpy.inputData;
102  this->receiver = cpy.receiver;
103  this->sender = cpy.sender;
104  this->nonce = cpy.nonce;
105  this->value = cpy.value;
106  this->status = cpy.status;
107  this->internalTransactions = cpy.internalTransactions;
108  this->erc20Transactions = cpy.erc20Transactions;
109  }
110 
111  };
112 
114  public AbstractBlockchainExplorer<EthereumLikeBlockchainExplorerTransaction> {
115  public:
116  typedef ledger::core::Block Block;
117  EthereumLikeBlockchainExplorer(const std::shared_ptr<ledger::core::api::DynamicObject> &configuration,
118  const std::vector<std::string> &matchableKeys);
119 
120  virtual Future<std::shared_ptr<BigInt>> getNonce(const std::string &address) = 0;
121  virtual Future<std::shared_ptr<BigInt>> getBalance(const std::vector<EthereumLikeKeychain::Address> &addresses) = 0;
122  virtual Future<std::shared_ptr<BigInt>> getGasPrice() = 0;
123  virtual Future<std::shared_ptr<BigInt>> getEstimatedGasLimit(const std::string &address) = 0;
124  virtual Future<std::shared_ptr<BigInt>> getERC20Balance(const std::string &address,
125  const std::string &erc20Address) = 0;
126  virtual Future<std::vector<BigInt>> getERC20Balances(const std::string &address,
127  const std::vector<std::string> &erc20Addresses) = 0;
128  };
129  }
130 }
131 
132 
133 #endif //LEDGER_CORE_ETHEREUMBLOCKCHAINEXPLORER_H
Definition: EthereumLikeBlockchainExplorer.h:71
Definition: Option.hpp:49
Definition: AbstractBlockchainExplorer.h:48
Definition: Deffered.hpp:49
Definition: EthereumLikeBlockchainExplorer.h:113
Definition: ConfigurationMatchable.h:38
Definition: EthereumLikeBlockchainExplorer.h:61
Definition: EthereumLikeBlockchainExplorer.h:53
Definition: Account.cpp:8
Definition: BigInt.h:56
Definition: Block.h:40