ledger-core
EthereumLikeTransactionApi.h
1 /*
2  *
3  * EthereumLikeTransactionApi
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_ETHEREUMLIKETRANSACTIONAPI_H
33 #define LEDGER_CORE_ETHEREUMLIKETRANSACTIONAPI_H
34 
35 #include <wallet/common/api_impl/OperationApi.h>
36 #include <wallet/ethereum/api_impl/EthereumLikeBlockApi.h>
37 
38 #include <api/EthereumLikeTransaction.hpp>
39 #include <api/Amount.hpp>
40 #include <api/Currency.hpp>
41 #include <math/BigInt.h>
42 
43 namespace ledger {
44  namespace core {
46  public:
47  explicit EthereumLikeTransactionApi(const api::Currency& currency);
48  explicit EthereumLikeTransactionApi(const std::shared_ptr<OperationApi>& operation);
49 
50  std::string getHash() override;
51  int32_t getNonce() override;
52  std::shared_ptr<api::Amount> getGasPrice() override ;
53  std::shared_ptr<api::Amount> getGasLimit() override ;
54  std::shared_ptr<api::Amount> getGasUsed() override ;
55  std::shared_ptr<api::EthereumLikeAddress> getReceiver() override ;
56  std::shared_ptr<api::EthereumLikeAddress> getSender() override;
57  std::shared_ptr<api::Amount> getValue() override;
59  int32_t getStatus() override;
60  std::vector<uint8_t> serialize() override;
61  std::chrono::system_clock::time_point getDate() override;
62  std::shared_ptr<api::EthereumLikeBlock> getBlock() override;
63  void setSignature(const std::vector<uint8_t> & vSignature, const std::vector<uint8_t> & rSignature, const std::vector<uint8_t> & sSignature) override ;
64  void setDERSignature(const std::vector<uint8_t> & signature) override;
65  void setVSignature(const std::vector<uint8_t> & vSignature) override;
66  EthereumLikeTransactionApi & setGasPrice(const std::shared_ptr<BigInt>& gasPrice);
67  EthereumLikeTransactionApi & setGasLimit(const std::shared_ptr<BigInt>& gasLimit);
68  EthereumLikeTransactionApi & setNonce(const std::shared_ptr<BigInt>& nonce);
69  EthereumLikeTransactionApi & setValue(const std::shared_ptr<BigInt>& value);
70  EthereumLikeTransactionApi & setData(const std::vector<uint8_t> &data);
71  EthereumLikeTransactionApi & setStatus(int32_t status);
72  EthereumLikeTransactionApi & setReceiver(const std::string &receiver);
73  EthereumLikeTransactionApi & setSender(const std::string &sender);
74  private:
75  std::chrono::system_clock::time_point _time;
76  std::shared_ptr<EthereumLikeBlockApi> _block;
77  std::string _hash;
78  api::Currency _currency;
79  std::shared_ptr<api::Amount> _gasPrice;
80  std::shared_ptr<api::Amount> _gasLimit;
81  std::shared_ptr<api::Amount> _gasUsed;
82  std::shared_ptr<api::Amount> _value;
83  std::shared_ptr<BigInt> _nonce;
84  std::vector<uint8_t> _data;
85  int32_t _status;
86  std::shared_ptr<api::EthereumLikeAddress> _receiver;
87  std::shared_ptr<api::EthereumLikeAddress> _sender;
88  std::vector<uint8_t> _vSignature;
89  std::vector<uint8_t> _rSignature;
90  std::vector<uint8_t> _sSignature;
91  };
92  }
93 }
94 
95 
96 #endif //LEDGER_CORE_ETHEREUMLIKETRANSACTIONAPI_H
std::shared_ptr< api::EthereumLikeAddress > getSender() override
Definition: EthereumLikeTransactionApi.cpp:103
std::vector< uint8_t > serialize() override
Definition: EthereumLikeTransactionApi.cpp:155
int32_t getStatus() override
Definition: EthereumLikeTransactionApi.cpp:115
void setSignature(const std::vector< uint8_t > &vSignature, const std::vector< uint8_t > &rSignature, const std::vector< uint8_t > &sSignature) override
Definition: EthereumLikeTransactionApi.cpp:127
std::shared_ptr< api::EthereumLikeAddress > getReceiver() override
Definition: EthereumLikeTransactionApi.cpp:99
std::shared_ptr< api::EthereumLikeBlock > getBlock() override
Definition: EthereumLikeTransactionApi.cpp:123
int32_t getNonce() override
Definition: EthereumLikeTransactionApi.cpp:84
std::chrono::system_clock::time_point getDate() override
Definition: EthereumLikeTransactionApi.cpp:119
std::shared_ptr< api::Amount > getGasLimit() override
Definition: EthereumLikeTransactionApi.cpp:92
std::shared_ptr< api::Amount > getValue() override
Definition: EthereumLikeTransactionApi.cpp:107
std::experimental::optional< std::vector< uint8_t > > getData() override
Definition: EthereumLikeTransactionApi.cpp:111
Definition: EthereumLikeTransactionApi.h:45
std::shared_ptr< api::Amount > getGasUsed() override
Definition: EthereumLikeTransactionApi.cpp:96
Definition: EthereumLikeTransaction.hpp:28
Definition: Currency.hpp:23
Definition: Account.cpp:8
std::shared_ptr< api::Amount > getGasPrice() override
Definition: EthereumLikeTransactionApi.cpp:88
Definition: optional.hpp:177
std::string getHash() override
Definition: EthereumLikeTransactionApi.cpp:80