BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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  pts_address();
44  pts_address( const std::string& base58str );
45  pts_address( const fc::ecc::public_key& pub, bool compressed = true, uint8_t version=56 );
46 
47  uint8_t version()const { return addr.at(0); }
48  bool is_valid()const;
49 
50  operator std::string()const;
51 
52  std::array<char,25> addr{};
53  };
54 
55  inline bool operator == ( const pts_address& a, const pts_address& b ) { return a.addr == b.addr; }
56  inline bool operator != ( const pts_address& a, const pts_address& b ) { return a.addr != b.addr; }
57  inline bool operator < ( const pts_address& a, const pts_address& b ) { return a.addr < b.addr; }
58 
59 } } // namespace graphene::protocol
60 
61 namespace std
62 {
63  template<>
64  struct hash<graphene::protocol::pts_address>
65  {
66  public:
68  {
69  size_t s;
70  std::memcpy( (char*)&s, a.addr.data() + a.addr.size() - sizeof(s), sizeof(s) );
71  return s;
72  }
73  };
74 }
75 
76 #include <fc/reflect/reflect.hpp>
78 
79 namespace fc
80 {
81  void to_variant( const graphene::protocol::pts_address& var, fc::variant& vo, uint32_t max_depth = 1 );
82  void from_variant( const fc::variant& var, graphene::protocol::pts_address& vo, uint32_t max_depth = 1 );
83 
84 namespace raw {
85  extern template void pack( datastream<size_t>& s, const graphene::protocol::pts_address& tx,
86  uint32_t _max_depth );
87  extern template void pack( datastream<char*>& s, const graphene::protocol::pts_address& tx,
88  uint32_t _max_depth );
89  extern template void unpack( datastream<const char*>& s, graphene::protocol::pts_address& tx,
90  uint32_t _max_depth );
91 } } // fc::raw
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
Definition: api.cpp:56
Defines types and macros used to provide reflection.
template void pack(datastream< char * > &s, const graphene::protocol::pts_address &tx, uint32_t _max_depth)
bool operator!=(const optional< T > &left, const optional< T > &right)
Definition: optional.hpp:253
bool operator==(const optional< T > &left, const optional< T > &right)
Definition: optional.hpp:245
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
contains only the public point of an elliptic curve key.
Definition: elliptic.hpp:35
template void unpack(datastream< const char * > &s, graphene::protocol::pts_address &tx, uint32_t _max_depth)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
Definition: api.hpp:15
bool operator<(const variant &a, const variant &b)
Definition: variant.cpp:734
std::array< char, 25 > addr
binary representation of address, 0-initialized
Definition: pts_address.hpp:52
size_t operator()(const graphene::protocol::pts_address &a) const
Definition: pts_address.hpp:67