BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
pts_address.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
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
14  * all 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
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <array>
27 #include <cstring>
28 #include <string>
29 
30 #include <fc/io/datastream.hpp>
31 #include <fc/io/raw_fwd.hpp>
32 #include <fc/variant.hpp>
33 
34 namespace fc { namespace ecc { class public_key; } }
35 
36 namespace graphene { namespace protocol {
37 
41  struct pts_address
42  {
43  static constexpr uint8_t default_version = 56;
44 
45  pts_address();
46  explicit pts_address( const std::string& base58str );
47  explicit pts_address( const fc::ecc::public_key& pub,
49  bool compressed = true,
50  uint8_t version = default_version );
51 
52  uint8_t version()const { return addr.at(0); }
53  bool is_valid()const;
54 
55  explicit operator std::string()const;
56 
57  std::array<char,25> addr{};
58  };
59 
60  inline bool operator == ( const pts_address& a, const pts_address& b ) { return a.addr == b.addr; }
61  inline bool operator != ( const pts_address& a, const pts_address& b ) { return a.addr != b.addr; }
62  inline bool operator < ( const pts_address& a, const pts_address& b ) { return a.addr < b.addr; }
63 
64 } } // namespace graphene::protocol
65 
66 namespace std
67 {
68  template<>
69  struct hash<graphene::protocol::pts_address>
70  {
71  public:
73  {
74  size_t s;
75  std::memcpy( (char*)&s, a.addr.data() + a.addr.size() - sizeof(s), sizeof(s) );
76  return s;
77  }
78  };
79 }
80 
81 #include <fc/reflect/reflect.hpp>
83 
84 namespace fc
85 {
86  void to_variant( const graphene::protocol::pts_address& var, fc::variant& vo, uint32_t max_depth = 1 );
87  void from_variant( const fc::variant& var, graphene::protocol::pts_address& vo, uint32_t max_depth = 1 );
88 
89 namespace raw {
90  extern template void pack( datastream<size_t>& s, const graphene::protocol::pts_address& tx,
91  uint32_t _max_depth );
92  extern template void pack( datastream<char*>& s, const graphene::protocol::pts_address& tx,
93  uint32_t _max_depth );
94  extern template void unpack( datastream<const char*>& s, graphene::protocol::pts_address& tx,
95  uint32_t _max_depth );
96 } } // fc::raw
graphene::protocol::operator<
bool operator<(const price &a, const price &b)
Definition: asset.cpp:45
graphene::protocol::pts_address::addr
std::array< char, 25 > addr
binary representation of address, 0-initialized
Definition: pts_address.hpp:57
fc::raw::unpack
void unpack(Stream &s, flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:23
fc
Definition: api.hpp:15
graphene::protocol::pts_address
Definition: pts_address.hpp:41
graphene::protocol::pts_address::version
uint8_t version() const
Definition: pts_address.hpp:52
fc::ecc::public_key
contains only the public point of an elliptic curve key.
Definition: elliptic.hpp:35
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
reflect.hpp
Defines types and macros used to provide reflection.
graphene::protocol::pts_address::is_valid
bool is_valid() const
Definition: pts_address.cpp:73
graphene::protocol::operator==
bool operator==(const price &a, const price &b)
Definition: asset.cpp:34
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
std
Definition: zeroed_array.hpp:76
raw_fwd.hpp
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
variant.hpp
graphene::protocol::pts_address::default_version
static constexpr uint8_t default_version
Definition: pts_address.hpp:43
graphene::protocol::pts_address::pts_address
pts_address()
constructs empty / null address
Definition: pts_address.cpp:34
std::hash< graphene::protocol::pts_address >::operator()
size_t operator()(const graphene::protocol::pts_address &a) const
Definition: pts_address.hpp:72
datastream.hpp
graphene
Definition: api.cpp:48
graphene::protocol::operator!=
bool operator!=(const address &a, const address &b)
Definition: address.hpp:61
fc::raw::pack
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11