ledger-core
EthereumLikeTransactionBuilder.h
1 /*
2  *
3  * EthereumLikeTransactionBuilder
4  *
5  * Created by El Khalil Bellakrid on 12/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_ETHEREUMLIKETRANSACTIONBUILDER_H
33 #define LEDGER_CORE_ETHEREUMLIKETRANSACTIONBUILDER_H
34 
35 #include <api/EthereumLikeTransactionBuilder.hpp>
36 #include <api/Currency.hpp>
37 #include <api/ExecutionContext.hpp>
38 #include <api/Amount.hpp>
39 
40 #include <wallet/common/Amount.h>
41 #include <wallet/ethereum/explorers/EthereumLikeBlockchainExplorer.h>
42 
43 #include <math/BigInt.h>
44 
45 #include <async/Future.hpp>
46 #include <spdlog/logger.h>
47 
48 namespace ledger {
49  namespace core {
50 
53  wipe = false;
54  nonce = std::make_shared<BigInt>(0);
55  };
56  std::string toAddress;
57  std::shared_ptr<BigInt> value;
58  std::shared_ptr<BigInt> nonce;
59  std::shared_ptr<BigInt> gasPrice;
60  std::shared_ptr<BigInt> gasLimit;
61  std::vector<uint8_t> inputData;
62  bool wipe;
63  };
64 
65  using EthereumLikeTransactionBuildFunction = std::function<Future<std::shared_ptr<api::EthereumLikeTransaction>> (const EthereumLikeTransactionBuildRequest&, const std::shared_ptr<EthereumLikeBlockchainExplorer> &)>;
66 
67  class EthereumLikeTransactionBuilder : public api::EthereumLikeTransactionBuilder, public std::enable_shared_from_this<EthereumLikeTransactionBuilder>{
68  public:
69 
70  explicit EthereumLikeTransactionBuilder(const std::shared_ptr<api::ExecutionContext>& context,
71  const api::Currency& params,
72  const std::shared_ptr<EthereumLikeBlockchainExplorer> &explorer,
73  const std::shared_ptr<spdlog::logger>& logger,
74  const EthereumLikeTransactionBuildFunction& buildFunction);
75 
77 
78  std::shared_ptr<api::EthereumLikeTransactionBuilder> sendToAddress(const std::shared_ptr<api::Amount> & amount,
79  const std::string & address) override;
80 
81  std::shared_ptr<api::EthereumLikeTransactionBuilder> wipeToAddress(const std::string & address) override;
82 
83  std::shared_ptr<api::EthereumLikeTransactionBuilder> setGasPrice(const std::shared_ptr<api::Amount> & gasPrice) override;
84  std::shared_ptr<api::EthereumLikeTransactionBuilder> setGasLimit(const std::shared_ptr<api::Amount> & gasLimit) override;
85  std::shared_ptr<api::EthereumLikeTransactionBuilder> setInputData(const std::vector<uint8_t> & data) override;
86 
87  void build(const std::shared_ptr<api::EthereumLikeTransactionCallback> & callback) override;
89 
90  std::shared_ptr<api::EthereumLikeTransactionBuilder> clone() override;
91 
92  void reset() override;
93 
94  static std::shared_ptr<api::EthereumLikeTransaction> parseRawTransaction(const api::Currency & currency,
95  const std::vector<uint8_t> & rawTransaction,
96  bool isSigned);
97  private:
98  api::Currency _currency;
99  std::shared_ptr<EthereumLikeBlockchainExplorer> _explorer;
100  EthereumLikeTransactionBuildFunction _build;
101  EthereumLikeTransactionBuildRequest _request;
102  std::shared_ptr<api::ExecutionContext> _context;
103  std::shared_ptr<spdlog::logger> _logger;
104 
105  };
106  }
107 }
108 
109 
110 #endif //LEDGER_CORE_ETHEREUMLIKETRANSACTIONBUILDER_H
Definition: Deffered.hpp:49
Definition: EthereumLikeTransactionBuilder.hpp:31
Definition: Currency.hpp:23
Definition: Account.cpp:8
Definition: EthereumLikeTransactionBuilder.h:51
Definition: EthereumLikeTransactionBuilder.h:67
Definition: logger.hpp:44