iota.lib.cpp
IOTA C++ Library
address.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 
30 #include <iota/crypto/kerl.hpp>
31 #include <iota/types/trinary.hpp>
32 
33 namespace IOTA {
34 
35 namespace Models {
36 
43 class Address {
44 public:
45  enum Type { NORMAL, MULTISIG };
46 
47 public:
56  Address(const Types::Trytes& address = "", const int64_t& balance = 0,
57  const int32_t& keyIndex = 0, const int32_t& security = 2, const Type& type = NORMAL);
58 
67  Address(const char* address, const int64_t& balance = 0, const int32_t& keyIndex = 0,
68  const int32_t& security = 2, const Type& type = NORMAL);
69 
75  explicit Address(const Type& type);
76 
80  ~Address() = default;
81 
82 public:
86  const Types::Trytes& toTrytes() const;
87 
98  Types::Trytes toTrytesWithChecksum(bool validChecksum = false);
99 
105  void setAddress(const Types::Trytes& address);
106 
118  const Types::Trytes& getChecksum(bool validChecksum = false);
119 
123  bool empty() const;
124 
128 public:
135  void absorbDigests(const std::vector<uint8_t>& digests);
136 
140  void finalize();
141 
149  bool validate(const std::vector<std::vector<uint8_t>>& digests);
150 
151 public:
155  const int64_t& getBalance() const;
156 
160  void setBalance(const int64_t& balance);
161 
162 public:
166  const int32_t& getKeyIndex() const;
167 
171  void setKeyIndex(const int32_t& keyIndex);
172 
173 public:
177  const int32_t& getSecurity() const;
178 
182  void setSecurity(const int32_t& security);
183 
184 public:
192  bool operator==(const Address& rhs) const;
193 
201  bool operator!=(const Address& rhs) const;
202 
203 public:
211  bool operator==(const Types::Trytes& rhs) const;
212 
220  bool operator!=(const Types::Trytes& rhs) const;
221 
222 private:
226  Types::Trytes address_;
227 
231  int64_t balance_ = 0;
232 
236  int32_t keyIndex_ = 0;
237 
241  int32_t security_ = 2;
242 
246  Type type_;
247 
251  Types::Trytes checksum_;
252 
257  std::shared_ptr<Crypto::Kerl> k_;
258 };
259 
260 std::ostream& operator<<(std::ostream& os, const Address& address);
261 
262 } // namespace Models
263 
264 } // namespace IOTA
bool operator!=(const Address &rhs) const
Types::Trytes toTrytesWithChecksum(bool validChecksum=false)
const int64_t & getBalance() const
void setSecurity(const int32_t &security)
Definition: address.hpp:43
const Types::Trytes & toTrytes() const
void setKeyIndex(const int32_t &keyIndex)
void absorbDigests(const std::vector< uint8_t > &digests)
const int32_t & getKeyIndex() const
Address(const Types::Trytes &address="", const int64_t &balance=0, const int32_t &keyIndex=0, const int32_t &security=2, const Type &type=NORMAL)
bool validate(const std::vector< std::vector< uint8_t >> &digests)
const Types::Trytes & getChecksum(bool validChecksum=false)
void setBalance(const int64_t &balance)
bool operator==(const Address &rhs) const
void setAddress(const Types::Trytes &address)
const int32_t & getSecurity() const
Definition: core.hpp:33