ledger-core
TezosLikeBlockchainExplorer.h
1 /*
2  *
3  * TezosLikeBlockchainExplorer
4  *
5  * Created by El Khalil Bellakrid on 27/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_TEZOSLIKEBLOCKCHAINEXPLORER_H
33 #define LEDGER_CORE_TEZOSLIKEBLOCKCHAINEXPLORER_H
34 
35 #include <string>
36 
37 #include <api/DynamicObject.hpp>
38 #include <api/ExecutionContext.hpp>
39 #include <api/TezosLikeNetworkParameters.hpp>
40 #include <async/DedicatedContext.hpp>
41 #include <collections/DynamicObject.hpp>
42 #include <math/BigInt.h>
43 #include <net/HttpClient.hpp>
44 #include <utils/ConfigurationMatchable.h>
45 #include <utils/Option.hpp>
46 #include <wallet/common/Block.h>
47 #include <wallet/common/explorers/AbstractBlockchainExplorer.h>
48 #include <wallet/tezos/keychains/TezosLikeKeychain.h>
49 #include <api/TezosOperationTag.hpp>
50 
51 namespace ledger {
52  namespace core {
53 
55  TezosLikeBlockchainExplorerOriginatedAccount(const std::string &a = "",
56  bool isSpendable = false,
57  bool isDelegatable = false) :
58  address(a),
59  spendable(isSpendable),
60  delegatable(isDelegatable) {
61  };
62 
63  std::string address;
64  bool spendable;
65  bool delegatable;
66  };
67 
69  std::string hash;
70  std::chrono::system_clock::time_point receivedAt;
71  BigInt value;
72  BigInt fees;
73  BigInt gas_limit;
74  BigInt storage_limit;
75  std::string receiver;
76  std::string sender;
77  Option<Block> block;
78  uint64_t confirmations;
79  api::TezosOperationTag type;
80  Option<std::string> publicKey;
82  uint64_t status;
84  confirmations = 0;
85  type = api::TezosOperationTag::OPERATION_TAG_NONE;
86  status = 0;
87  }
88 
90  this->hash = cpy.hash;
91  this->receivedAt = cpy.receivedAt;
92  this->value = cpy.value;
93  this->fees = cpy.fees;
94  this->gas_limit = cpy.gas_limit;
95  this->storage_limit = cpy.storage_limit;
96  this->receiver = cpy.receiver;
97  this->sender = cpy.sender;
98  this->block = cpy.block;
99  this->confirmations = cpy.confirmations;
100  this->type = cpy.type;
101  this->publicKey = cpy.publicKey;
102  this->originatedAccount = cpy.originatedAccount;
103  this->status = cpy.status;
104  }
105 
106  };
109  public AbstractBlockchainExplorer<TezosLikeBlockchainExplorerTransaction> {
110  public:
111  typedef ledger::core::Block Block;
112 
113  TezosLikeBlockchainExplorer(const std::shared_ptr<ledger::core::api::DynamicObject> &configuration,
114  const std::vector<std::string> &matchableKeys);
115 
117  getBalance(const std::vector<TezosLikeKeychain::Address> &addresses) = 0;
118 
120  getFees() = 0;
121 
123  getEstimatedGasLimit(const std::string &address) = 0;
124 
126  getStorage(const std::string &address) = 0;
127 
129  getCounter(const std::string &address) = 0;
130 
131  virtual Future<std::vector<uint8_t>> forgeKTOperation(const std::shared_ptr<TezosLikeTransactionApi> &tx) = 0;
132  // This a helper to manage legacy KT accounts
133  // WARNING: we will only support removing delegation and transfer from KT to implicit account
134  static Future<std::vector<uint8_t>> forgeKTOperation(const std::shared_ptr<TezosLikeTransactionApi> &tx,
135  const std::shared_ptr<api::ExecutionContext> &context,
136  const std::shared_ptr<HttpClient> &http,
137  const std::string &rpcNode);
138 
139  virtual Future<std::string> getManagerKey(const std::string &address) = 0;
140  // This a helper to manage legacy KT accounts
141  // WARNING: we will only support removing delegation and transfer from KT to implicit account
142  static Future<std::string> getManagerKey(const std::string &address,
143  const std::shared_ptr<api::ExecutionContext> &context,
144  const std::shared_ptr<HttpClient> &http,
145  const std::string &rpcNode);
146 
147  virtual Future<bool> isAllocated(const std::string &address) = 0;
148  static Future<bool> isAllocated(const std::string &address,
149  const std::shared_ptr<api::ExecutionContext> &context,
150  const std::shared_ptr<HttpClient> &http,
151  const std::string &rpcNode);
152 
153  protected:
154  std::string getRPCNodeEndpoint() const {
155  return _rpcNode;
156  };
157  private:
158  std::string _rpcNode;
159  };
160  }
161 }
162 #endif //LEDGER_CORE_TEZOSLIKEBLOCKCHAINEXPLORER_H
Definition: TezosLikeBlockchainExplorer.h:54
Definition: TezosLikeBlockchainExplorer.h:68
Definition: Option.hpp:49
Definition: TezosLikeTransactionApi.h:45
Definition: AbstractBlockchainExplorer.h:48
Definition: Deffered.hpp:49
Definition: ConfigurationMatchable.h:38
Definition: TezosLikeBlockchainExplorer.h:108
Definition: Account.cpp:8
Definition: BigInt.h:56
Definition: Block.h:40