iota.lib.cpp
IOTA C++ Library
bundle.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 <memory>
29 #include <vector>
30 
31 #include <iota/models/tag.hpp>
32 #include <iota/models/transaction.hpp>
33 #include <iota/types/trytes.hpp>
34 
35 namespace IOTA {
36 
37 namespace Models {
38 
42 class Bundle {
43 public:
47  Bundle() = default;
51  ~Bundle() = default;
52 
58  explicit Bundle(const std::vector<Transaction>& transactions);
59 
60 public:
64  const std::vector<Transaction>& getTransactions() const;
65 
71  std::vector<Transaction>& getTransactions();
72 
76  const Types::Trytes& getHash() const;
77 
83  void setHash(const Types::Trytes& hash);
84 
88  std::size_t getLength() const;
89 
93  bool empty() const;
94 
95 public:
103  void addTransaction(const Transaction& transaction, int32_t signatureMessageLength = 1);
104 
108  void finalize();
109 
115  void addTrytes(const std::vector<Types::Trytes>& signatureFragments);
116 
123  std::vector<int8_t> normalizedBundle(const Types::Trytes& bundleHash);
124 
125 protected:
131  void generateHash(void);
132 
133 public:
138  bool operator<(const Bundle& rhs) const;
139 
144  bool operator>(const Bundle& rhs) const;
145 
150  bool operator==(const Bundle& rhs) const;
151 
156  bool operator!=(const Bundle& rhs) const;
157 
162  Transaction& operator[](const int index);
163 
168  const Transaction& operator[](const int index) const;
169 
170 private:
174  std::vector<Transaction> transactions_;
175 
179  Types::Trytes hash_;
180 };
181 
182 } // namespace Models
183 
184 } // namespace IOTA
Transaction & operator[](const int index)
bool empty() const
void generateHash(void)
const Types::Trytes & getHash() const
void addTrytes(const std::vector< Types::Trytes > &signatureFragments)
std::size_t getLength() const
bool operator==(const Bundle &rhs) const
bool operator>(const Bundle &rhs) const
Definition: bundle.hpp:42
bool operator<(const Bundle &rhs) const
Definition: transaction.hpp:41
const std::vector< Transaction > & getTransactions() const
std::vector< int8_t > normalizedBundle(const Types::Trytes &bundleHash)
bool operator!=(const Bundle &rhs) const
void setHash(const Types::Trytes &hash)
void addTransaction(const Transaction &transaction, int32_t signatureMessageLength=1)
Definition: core.hpp:33