iota.lib.cpp
IOTA C++ Library
transaction.hpp
1 //
2 // MIT License
3 //
4 // Copyright (c) 2017-2018 Thibault Martinez and Simon Ninon
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //
24 //
25 
26 #pragma once
27 
28 #include <utility>
29 
30 #include <iota/models/address.hpp>
31 #include <iota/models/tag.hpp>
32 #include <iota/types/trytes.hpp>
33 
34 namespace IOTA {
35 
36 namespace Models {
37 
41 class Transaction {
42 public:
46  Transaction() = default;
47 
51  ~Transaction() = default;
52 
58  explicit Transaction(const Types::Trytes& trytes);
59 
79  Transaction(const Types::Trytes& signatureFragments, int64_t currentIndex, int64_t lastIndex,
80  const Types::Trytes& nonce, const Types::Trytes& hash, int64_t timestamp,
81  const Types::Trytes& trunkTransaction, const Types::Trytes& branchTransaction,
82  const Models::Address& address, int64_t value, const Types::Trytes& bundle,
83  const Models::Tag& tag, int64_t attachmentTimestamp,
84  int64_t attachmentTimestampLowerBound, int64_t attachmentTimestampUpperBound);
85 
97  Transaction(const Models::Address& address, int64_t value, const Models::Tag& tag,
98  int64_t timestamp, int64_t attachmentTimestamp = 0,
99  int64_t attachmentTimestampLowerBound = 0, int64_t attachmentTimestampUpperBound = 0);
100 
101 public:
105  bool isTailTransaction() const;
106 
112  const Types::Trytes& getHash() const;
113 
119  void setHash(const Types::Trytes& hash);
120 
126  const Types::Trytes& getSignatureFragments() const;
127 
133  void setSignatureFragments(const Types::Trytes& signatureFragments);
134 
140  const Models::Address& getAddress() const;
141 
147  void setAddress(const Models::Address& address);
148 
154  int64_t getValue() const;
160  void setValue(int64_t value);
161 
167  const Models::Tag& getTag() const;
168 
174  void setTag(const Models::Tag& tag);
175 
181  const Models::Tag& getObsoleteTag() const;
182 
188  void setObsoleteTag(const Models::Tag& tag);
189 
195  int64_t getTimestamp() const;
196 
202  void setTimestamp(int64_t timestamp);
203 
209  int64_t getAttachmentTimestamp() const;
210 
216  void setAttachmentTimestamp(int64_t timestamp);
217 
223  int64_t getAttachmentTimestampLowerBound() const;
224 
230  void setAttachmentTimestampLowerBound(int64_t timestamp);
231 
237  int64_t getAttachmentTimestampUpperBound() const;
238 
244  void setAttachmentTimestampUpperBound(int64_t timestamp);
245 
251  int64_t getCurrentIndex() const;
252 
258  void setCurrentIndex(int64_t currentIndex);
259 
265  int64_t getLastIndex() const;
266 
272  void setLastIndex(int64_t lastIndex);
273 
279  const Types::Trytes& getBundle() const;
280 
286  void setBundle(const Types::Trytes& bundle);
287 
293  const Types::Trytes& getTrunkTransaction() const;
294 
300  void setTrunkTransaction(const Types::Trytes& trunkTransaction);
301 
307  const Types::Trytes& getBranchTransaction() const;
308 
314  void setBranchTransaction(const Types::Trytes& branchTransaction);
315 
321  const Types::Trytes& getNonce() const;
322 
328  void setNonce(const Types::Trytes& nonce);
329 
335  bool getPersistence() const;
336 
342  void setPersistence(bool persistence);
343 
351  bool operator==(const Transaction& rhs) const;
352 
360  bool operator!=(const Transaction& rhs) const;
361 
367  Types::Trytes toTrytes() const;
368 
374  void initFromTrytes(const Types::Trytes& trytes);
375 
376 private:
380  static const std::pair<int, int> SignatureFragmentsOffset;
384  static const std::pair<int, int> AddressOffset;
388  static const std::pair<int, int> ValueOffset;
392  static const std::pair<int, int> TagOffset;
396  static const std::pair<int, int> TimestampOffset;
400  static const std::pair<int, int> CurrentIndexOffset;
404  static const std::pair<int, int> LastIndexOffset;
408  static const std::pair<int, int> BundleOffset;
412  static const std::pair<int, int> TrunkOffset;
416  static const std::pair<int, int> BranchOffset;
420  static const std::pair<int, int> NonceOffset;
424  static const std::pair<int, int> ObsoleteTagOffset;
428  static const std::pair<int, int> AttachmentTimestampOffset;
432  static const std::pair<int, int> AttachmentTimestampLowerBoundOffset;
436  static const std::pair<int, int> AttachmentTimestampUpperBoundOffset;
440  static const std::pair<int, int> ValidityChunkOffset;
441 
442 private:
446  Types::Trytes hash_;
450  Types::Trytes signatureFragments_;
454  Models::Address address_;
458  int64_t value_ = 0;
462  Models::Tag tag_;
466  Models::Tag obsoleteTag_;
470  int64_t timestamp_ = 0;
474  int64_t attachmentTimestamp_ = 0;
478  int64_t attachmentTimestampLowerBound_ = 0;
482  int64_t attachmentTimestampUpperBound_ = 0;
486  int64_t currentIndex_ = 0;
490  int64_t lastIndex_ = 0;
494  Types::Trytes bundle_;
498  Types::Trytes trunkTransaction_;
502  Types::Trytes branchTransaction_;
506  Types::Trytes nonce_;
510  bool persistence_ = false;
511 };
512 
513 std::ostream& operator<<(std::ostream& os, const Transaction& transaction);
514 
515 } // namespace Models
516 
517 } // namespace IOTA
void setValue(int64_t value)
const Types::Trytes & getSignatureFragments() const
const Types::Trytes & getHash() const
void setCurrentIndex(int64_t currentIndex)
void setPersistence(bool persistence)
Definition: tag.hpp:40
void setAddress(const Models::Address &address)
bool isTailTransaction() const
int64_t getLastIndex() const
void setAttachmentTimestampLowerBound(int64_t timestamp)
Definition: address.hpp:43
int64_t getValue() const
const Models::Tag & getTag() const
const Types::Trytes & getNonce() const
const Types::Trytes & getBranchTransaction() const
void setBranchTransaction(const Types::Trytes &branchTransaction)
const Models::Tag & getObsoleteTag() const
void setAttachmentTimestampUpperBound(int64_t timestamp)
const Models::Address & getAddress() const
void setHash(const Types::Trytes &hash)
const Types::Trytes & getTrunkTransaction() const
int64_t getCurrentIndex() const
void initFromTrytes(const Types::Trytes &trytes)
int64_t getAttachmentTimestampLowerBound() const
void setLastIndex(int64_t lastIndex)
void setNonce(const Types::Trytes &nonce)
const Types::Trytes & getBundle() const
Types::Trytes toTrytes() const
Definition: transaction.hpp:41
int64_t getTimestamp() const
void setBundle(const Types::Trytes &bundle)
void setAttachmentTimestamp(int64_t timestamp)
int64_t getAttachmentTimestamp() const
bool operator==(const Transaction &rhs) const
void setTimestamp(int64_t timestamp)
void setTag(const Models::Tag &tag)
bool operator!=(const Transaction &rhs) const
int64_t getAttachmentTimestampUpperBound() const
void setTrunkTransaction(const Types::Trytes &trunkTransaction)
void setSignatureFragments(const Types::Trytes &signatureFragments)
void setObsoleteTag(const Models::Tag &tag)
Definition: core.hpp:33