ledger-core
ERC20LikeOperation.h
1 /*
2  *
3  * ERC20LikeTransaction
4  *
5  * Created by El Khalil Bellakrid on 26/08/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_ERC20LIKETRANSACTION_H
33 #define LEDGER_CORE_ERC20LIKETRANSACTION_H
34 
35 #include <api/ERC20LikeOperation.hpp>
36 #include <api/ERC20Token.hpp>
37 #include <api/OperationType.hpp>
38 #include <wallet/common/Operation.h>
39 #include <api_impl/BigIntImpl.hpp>
40 namespace ledger {
41  namespace core {
42 
44  public:
45  ERC20LikeOperation(const std::string &accountAddress,
46  const std::string &operationUid,
47  const Operation &operation,
48  const ERC20Transaction &erc20Tx,
49  const api::Currency &currency);
50 
51  ERC20LikeOperation() : _blockHeight(0){};
52 
53  std::string getHash() override;
54  std::shared_ptr<api::BigInt> getNonce() override;
55  std::shared_ptr<api::BigInt> getGasPrice() override;
56  std::shared_ptr<api::BigInt> getGasLimit() override;
57  std::shared_ptr<api::BigInt> getUsedGas() override;
58  std::string getSender() override;
59  std::string getReceiver() override;
60  std::shared_ptr<api::BigInt> getValue() override ;
61  std::vector<uint8_t> getData() override ;
62  std::chrono::system_clock::time_point getTime() override;
63  api::OperationType getOperationType() override;
64  std::string getOperationUid();
65  std::string getETHOperationUid();
66  int32_t getStatus() override ;
68  ERC20LikeOperation &setHash(const std::string &hash) {
69  _hash = hash;
70  return *this;
71  };
72 
73  ERC20LikeOperation &setNonce(const BigInt &nonce) {
74  _nonce = std::make_shared<api::BigIntImpl>(nonce);
75  return *this;
76  };
77 
78  ERC20LikeOperation &setGasPrice(const BigInt &gasPrice) {
79  _gasPrice = std::make_shared<api::BigIntImpl>(gasPrice);
80  return *this;
81  };
82 
83  ERC20LikeOperation &setGasLimit(const BigInt &gasLimit) {
84  _gasLimit = std::make_shared<api::BigIntImpl>(gasLimit);
85  return *this;
86  };
87 
88  ERC20LikeOperation &setUsedGas(const BigInt &usedGas) {
89  _gasUsed = std::make_shared<api::BigIntImpl>(usedGas);
90  return *this;
91  };
92 
93  ERC20LikeOperation &setSender(const std::string &sender) {
94  _sender = sender;
95  return *this;
96  };
97 
98  ERC20LikeOperation &setReceiver(const std::string &receiver) {
99  _receiver = receiver;
100  return *this;
101  };
102 
103  ERC20LikeOperation &setValue(const BigInt &value) {
104  _value = std::make_shared<api::BigIntImpl>(value);
105  return *this;
106  };
107 
108  ERC20LikeOperation &setData(const std::vector<uint8_t> &data) {
109  _data = data;
110  return *this;
111  };
112 
113  ERC20LikeOperation &setTime(const std::chrono::system_clock::time_point& time) {
114  _time = time;
115  return *this;
116  };
117 
118  ERC20LikeOperation &setOperationType(api::OperationType type) {
119  _operationType = type;
120  return *this;
121  };
122 
123  ERC20LikeOperation &setOperationUid(const std::string &operationUid) {
124  _uid = operationUid;
125  return *this;
126  };
127 
128  ERC20LikeOperation &setETHOperationUid(const std::string &ethOperationUid) {
129  _ethUidOperation = ethOperationUid;
130  return *this;
131  };
132 
133  ERC20LikeOperation &setStatus(int32_t status) {
134  _status = status;
135  return *this;
136  };
137 
138  ERC20LikeOperation &setBlockHeight(int64_t blockHeight) {
139  _blockHeight = blockHeight;
140  return *this;
141  }
142 
143  private:
144  std::string _uid;
145  std::string _ethUidOperation;
146  std::string _hash;
147  std::shared_ptr<api::BigInt> _nonce;
148  std::shared_ptr<api::BigInt> _gasPrice;
149  std::shared_ptr<api::BigInt> _gasLimit;
150  std::shared_ptr<api::BigInt> _gasUsed;
151  std::string _sender;
152  std::string _receiver;
153  std::shared_ptr<api::BigInt> _value;
154  std::vector<uint8_t> _data;
155  std::chrono::system_clock::time_point _time;
156  api::OperationType _operationType;
157  int32_t _status;
158  int64_t _blockHeight;
159  };
160 
161  }
162 }
163 
164 
165 #endif //LEDGER_CORE_ERC20LIKETRANSACTION_H
api::OperationType getOperationType() override
Definition: ERC20LikeOperation.cpp:104
Definition: ERC20LikeOperation.hpp:27
std::shared_ptr< api::BigInt > getNonce() override
Definition: ERC20LikeOperation.cpp:68
int32_t getStatus() override
Definition: ERC20LikeOperation.cpp:116
std::string getHash() override
Definition: ERC20LikeOperation.cpp:64
std::shared_ptr< api::BigInt > getGasLimit() override
Definition: ERC20LikeOperation.cpp:76
std::shared_ptr< api::BigInt > getValue() override
Definition: ERC20LikeOperation.cpp:92
std::string getSender() override
Definition: ERC20LikeOperation.cpp:84
std::shared_ptr< api::BigInt > getGasPrice() override
Definition: ERC20LikeOperation.cpp:72
std::vector< uint8_t > getData() override
Definition: ERC20LikeOperation.cpp:96
std::string getReceiver() override
Definition: ERC20LikeOperation.cpp:88
Definition: ERC20LikeOperation.h:43
Definition: Operation.h:53
std::experimental::optional< int64_t > getBlockHeight() override
Definition: ERC20LikeOperation.cpp:120
Definition: Currency.hpp:23
Definition: EthereumLikeBlockchainExplorer.h:53
Definition: Account.cpp:8
std::chrono::system_clock::time_point getTime() override
Definition: ERC20LikeOperation.cpp:100
Definition: BigInt.h:56
std::shared_ptr< api::BigInt > getUsedGas() override
Definition: ERC20LikeOperation.cpp:80