ledger-core
TezosLikeTransactionApi.h
1 /*
2  *
3  * TezosLikeTransactionApi
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_TEZOSLIKETRANSACTIONAPI_H
33 #define LEDGER_CORE_TEZOSLIKETRANSACTIONAPI_H
34 
35 #include <wallet/common/api_impl/OperationApi.h>
36 #include <wallet/tezos/api_impl/TezosLikeBlockApi.h>
37 #include <api/TezosLikeTransaction.hpp>
38 #include <api/Amount.hpp>
39 #include <api/Currency.hpp>
40 #include <math/BigInt.h>
41 #include <api/TezosOperationTag.hpp>
42 namespace ledger {
43  namespace core {
44  // Reference: https://github.com/obsidiansystems/ledger-app-tezos/blob/9a0c8cc546677147b93935e0b0c96925244baf64/src/types.h
46  public:
47  explicit TezosLikeTransactionApi(const api::Currency &currency,
48  const std::string &protocolUpdate);
49 
50  explicit TezosLikeTransactionApi(const std::shared_ptr<OperationApi> &operation,
51  const std::string &protocolUpdate);
52 
53  api::TezosOperationTag getType() override;
54 
55  std::string getHash() override;
56 
57  std::shared_ptr<api::Amount> getFees() override;
58 
59  std::shared_ptr<api::TezosLikeAddress> getReceiver() override;
60 
61  std::shared_ptr<api::TezosLikeAddress> getSender() override;
62 
63  std::shared_ptr<api::Amount> getValue() override;
64 
65  std::vector<uint8_t> serialize() override;
66  std::vector<uint8_t> serializeWithType(api::TezosOperationTag type);
67 
68  std::chrono::system_clock::time_point getDate() override;
69 
70  std::shared_ptr<api::BigInt> getCounter() override;
71 
72  std::shared_ptr<api::Amount> getGasLimit() override ;
73 
74  std::shared_ptr<api::BigInt> getStorageLimit() override;
75 
77 
78  void setSignature(const std::vector<uint8_t> &signature) override;
79 
80  std::vector<uint8_t> getSigningPubKey() override;
81 
82  int32_t getStatus() override;
83 
84  TezosLikeTransactionApi &setFees(const std::shared_ptr<BigInt> &fees);
85 
86  TezosLikeTransactionApi &setValue(const std::shared_ptr<BigInt> &value);
87 
88  TezosLikeTransactionApi &setSender(const std::shared_ptr<api::TezosLikeAddress> &sender, api::TezosCurve curve = api::TezosCurve::ED25519);
89 
90  TezosLikeTransactionApi &setReceiver(const std::shared_ptr<api::TezosLikeAddress> &receiver, api::TezosCurve curve = api::TezosCurve::ED25519);
91 
92  TezosLikeTransactionApi &setSigningPubKey(const std::vector<uint8_t> &pubKey);
93 
94  TezosLikeTransactionApi &setHash(const std::string &hash);
95 
96  TezosLikeTransactionApi &setBlockHash(const std::string &blockHash);
97 
98  TezosLikeTransactionApi & setGasLimit(const std::shared_ptr<BigInt>& gasLimit);
99 
100  TezosLikeTransactionApi & setCounter(const std::shared_ptr<BigInt>& counter);
101 
102  TezosLikeTransactionApi & setStorage(const std::shared_ptr<BigInt>& storage);
103 
104  TezosLikeTransactionApi & setType(api::TezosOperationTag type);
105 
106  TezosLikeTransactionApi & setBalance(const BigInt &balance);
107 
108  TezosLikeTransactionApi & setManagerAddress(const std::string &managerAddress, api::TezosCurve curve);
109  std::string getManagerAddress() const;
110 
111  TezosLikeTransactionApi &setRawTx(const std::vector<uint8_t> &rawTx);
112 
113  TezosLikeTransactionApi &reveal(bool needReveal);
114  bool toReveal() const;
115  private:
116  std::chrono::system_clock::time_point _time;
117  std::shared_ptr<TezosLikeBlockApi> _block;
118  std::string _hash;
119  api::Currency _currency;
120  std::shared_ptr<api::Amount> _fees;
121  std::shared_ptr<api::Amount> _gasLimit;
122  std::shared_ptr<BigInt> _storage;
123  std::shared_ptr<BigInt> _counter;
124  std::shared_ptr<api::Amount> _value;
125  std::shared_ptr<api::TezosLikeAddress> _receiver;
126  api::TezosCurve _receiverCurve;
127  std::shared_ptr<api::TezosLikeAddress> _sender;
128  api::TezosCurve _senderCurve;
129  std::vector<uint8_t> _signature;
130  std::vector<uint8_t> _signingPubKey;
131  api::TezosOperationTag _type;
132  std::string _revealedPubKey;
133  BigInt _balance;
134  std::string _protocolUpdate;
135  std::string _managerAddress;
136  api::TezosCurve _managerCurve;
137  std::vector<uint8_t> _rawTx;
138  bool _needReveal;
139  int32_t _status;
140  };
141  }
142 }
143 #endif //LEDGER_CORE_TEZOSLIKETRANSACTIONAPI_H
void setSignature(const std::vector< uint8_t > &signature) override
Definition: TezosLikeTransactionApi.cpp:150
std::shared_ptr< api::Amount > getValue() override
Definition: TezosLikeTransactionApi.cpp:113
std::shared_ptr< api::Amount > getFees() override
Definition: TezosLikeTransactionApi.cpp:96
std::vector< uint8_t > getSigningPubKey() override
Definition: TezosLikeTransactionApi.cpp:143
Definition: TezosLikeTransactionApi.h:45
int32_t getStatus() override
Definition: TezosLikeTransactionApi.cpp:147
api::TezosOperationTag getType() override
Definition: TezosLikeTransactionApi.cpp:88
std::shared_ptr< api::TezosLikeAddress > getReceiver() override
Definition: TezosLikeTransactionApi.cpp:105
Definition: Currency.hpp:23
std::string getHash() override
Definition: TezosLikeTransactionApi.cpp:92
std::chrono::system_clock::time_point getDate() override
Definition: TezosLikeTransactionApi.cpp:117
std::experimental::optional< std::string > getBlockHash() override
Definition: TezosLikeTransactionApi.cpp:139
Definition: Account.cpp:8
Definition: BigInt.h:56
Definition: TezosLikeTransaction.hpp:29
std::shared_ptr< api::TezosLikeAddress > getSender() override
Definition: TezosLikeTransactionApi.cpp:109
std::vector< uint8_t > serialize() override
Definition: TezosLikeTransactionApi.cpp:159