BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
types.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 <memory>
27 #include <vector>
28 #include <deque>
29 #include <cstdint>
30 
31 #include <boost/preprocessor/seq/for_each.hpp>
32 #include <boost/preprocessor/seq/transform.hpp>
33 #include <boost/preprocessor/seq/elem.hpp>
34 #include <boost/preprocessor/seq/enum.hpp>
35 #include <boost/preprocessor/tuple/elem.hpp>
36 #include <boost/preprocessor/cat.hpp>
37 
38 #include <boost/rational.hpp>
39 
41 #include <fc/io/varint.hpp>
42 #include <fc/io/enum_type.hpp>
43 #include <fc/crypto/ripemd160.hpp>
44 #include <fc/crypto/sha1.hpp>
45 #include <fc/crypto/sha224.hpp>
46 #include <fc/crypto/sha256.hpp>
47 #include <fc/crypto/hash160.hpp>
48 #include <fc/crypto/elliptic.hpp>
49 #include <fc/reflect/reflect.hpp>
50 #include <fc/reflect/variant.hpp>
51 #include <fc/optional.hpp>
52 #include <fc/safe.hpp>
53 #include <fc/container/flat.hpp>
54 #include <fc/string.hpp>
55 
56 #include <fc/io/datastream.hpp>
57 #include <fc/io/raw_fwd.hpp>
58 #include <fc/static_variant.hpp>
59 
62 
63 #define GRAPHENE_EXTERNAL_SERIALIZATION(ext, type) \
64 namespace fc { \
65  ext template void from_variant( const variant& v, type& vo, uint32_t max_depth ); \
66  ext template void to_variant( const type& v, variant& vo, uint32_t max_depth ); \
67 namespace raw { \
68  ext template void pack< datastream<size_t>, type >( datastream<size_t>& s, const type& tx, uint32_t _max_depth ); \
69  ext template void pack< sha256::encoder, type >( sha256::encoder& s, const type& tx, uint32_t _max_depth ); \
70  ext template void pack< datastream<char*>, type >( datastream<char*>& s, const type& tx, uint32_t _max_depth ); \
71  ext template void unpack< datastream<const char*>, type >( datastream<const char*>& s, type& tx, uint32_t _max_depth ); \
72 } } // fc::raw
73 #define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type) GRAPHENE_EXTERNAL_SERIALIZATION(extern, type)
74 #define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type) GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, type)
75 
76 #define GRAPHENE_NAME_TO_OBJECT_TYPE(x, prefix, name) BOOST_PP_CAT(prefix, BOOST_PP_CAT(name, _object_type))
77 #define GRAPHENE_NAME_TO_ID_TYPE(x, y, name) BOOST_PP_CAT(name, _id_type)
78 #define GRAPHENE_DECLARE_ID(x, space_prefix_seq, name) \
79  using BOOST_PP_CAT(name, _id_type) = object_id<BOOST_PP_TUPLE_ELEM(2, 0, space_prefix_seq), \
80  GRAPHENE_NAME_TO_OBJECT_TYPE(x, BOOST_PP_TUPLE_ELEM(2, 1, space_prefix_seq), name)>;
81 #define GRAPHENE_REFLECT_ID(x, id_namespace, name) FC_REFLECT_TYPENAME(graphene::id_namespace::name)
82 
83 #define GRAPHENE_DEFINE_IDS(id_namespace, object_space, object_type_prefix, names_seq) \
84  namespace graphene { namespace id_namespace { \
85  \
86  enum BOOST_PP_CAT(object_type_prefix, object_type) { \
87  BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_OBJECT_TYPE, object_type_prefix, names_seq)) \
88  }; \
89  \
90  BOOST_PP_SEQ_FOR_EACH(GRAPHENE_DECLARE_ID, (object_space, object_type_prefix), names_seq) \
91  \
92  } } \
93  \
94  FC_REFLECT_ENUM(graphene::id_namespace::BOOST_PP_CAT(object_type_prefix, object_type), \
95  BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_OBJECT_TYPE, object_type_prefix, names_seq)) \
96  BOOST_PP_SEQ_FOR_EACH(GRAPHENE_REFLECT_ID, id_namespace, BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_ID_TYPE, , names_seq))
97 
98 namespace graphene { namespace protocol {
99 using namespace graphene::db;
100 
101 using std::map;
102 using std::vector;
103 using std::unordered_map;
104 using std::string;
105 using std::deque;
106 using std::shared_ptr;
107 using std::weak_ptr;
108 using std::unique_ptr;
109 using std::set;
110 using std::pair;
111 using std::enable_shared_from_this;
112 using std::tie;
113 using std::make_pair;
114 
115 using fc::variant_object;
116 using fc::variant;
117 using fc::enum_type;
118 using fc::optional;
119 using fc::unsigned_int;
120 using fc::time_point_sec;
121 using fc::time_point;
122 using fc::safe;
123 using fc::flat_map;
124 using fc::flat_set;
125 using fc::static_variant;
129 struct void_t{};
130 
133 using ratio_type = boost::rational<int32_t>;
134 
141  white_list = 0x02,
145  global_settle = 0x20,
149  lock_max_supply = 0x200,
157  disable_mcr_update = 0x800,
166 };
169 
170 // The bits that can be used in asset issuer permissions for non-UIA assets
171 const static uint16_t ASSET_ISSUER_PERMISSION_MASK =
173  | white_list
177  | global_settle
186 // The "enable" bits for non-UIA assets
187 const static uint16_t ASSET_ISSUER_PERMISSION_ENABLE_BITS_MASK =
189  | white_list
193  | global_settle
197 // The "disable" bits for non-UIA assets
198 const static uint16_t ASSET_ISSUER_PERMISSION_DISABLE_BITS_MASK =
204 // The bits that can be used in asset issuer permissions for UIA assets
205 const static uint16_t UIA_ASSET_ISSUER_PERMISSION_MASK =
207  | white_list
213 // The bits that can be used in asset issuer permissions for UIA assets before hf48/75
214 const static uint16_t DEFAULT_UIA_ASSET_ISSUER_PERMISSION =
216  | white_list
220 // The bits that can be used in asset issuer permissions for non-UIA assets but not for UIA assets
221 const static uint16_t NON_UIA_ONLY_ISSUER_PERMISSION_MASK =
222  ASSET_ISSUER_PERMISSION_MASK ^ UIA_ASSET_ISSUER_PERMISSION_MASK;
223 // The bits that can be used in asset issuer permissions but can not be used in flags
224 const static uint16_t PERMISSION_ONLY_MASK =
229 // The bits that can be used in flags for non-UIA assets
230 const static uint16_t VALID_FLAGS_MASK = ASSET_ISSUER_PERMISSION_MASK & ~PERMISSION_ONLY_MASK;
231 // the bits that can be used in flags for UIA assets
232 const static uint16_t UIA_VALID_FLAGS_MASK = UIA_ASSET_ISSUER_PERMISSION_MASK;
233 
238 };
239 
240 inline bool is_relative(object_id_type o) { return o.space() == 0; }
241 
248 using weight_type = uint16_t;
249 
251  struct binary_key {
252  binary_key() = default;
253  uint32_t check = 0;
255  };
257  public_key_type();
259  public_key_type(const fc::ecc::public_key& pubkey);
260  explicit public_key_type(const std::string& base58str);
261  operator fc::ecc::public_key_data() const;
262  operator fc::ecc::public_key() const;
263  explicit operator std::string() const;
264  friend bool operator == (const public_key_type& p1, const fc::ecc::public_key& p2);
265  friend bool operator == (const public_key_type& p1, const public_key_type& p2);
266  friend bool operator != (const public_key_type& p1, const public_key_type& p2);
267 };
268 
270 public:
271  inline bool operator()(const public_key_type& a, const public_key_type& b) const {
272  return a.key_data < b.key_data;
273  }
274 };
275 
276 struct fee_schedule;
277 } } // graphene::protocol
278 
279 namespace fc {
280 void to_variant(const graphene::protocol::public_key_type& var, fc::variant& vo, uint32_t max_depth = 2);
281 void from_variant(const fc::variant& var, graphene::protocol::public_key_type& vo, uint32_t max_depth = 2);
282 
283 
284 template<>
285 struct get_typename<std::shared_ptr<const graphene::protocol::fee_schedule>> { static const char* name() {
286  return "shared_ptr<const fee_schedule>";
287 } };
288 template<>
289 struct get_typename<std::shared_ptr<graphene::protocol::fee_schedule>> { static const char* name() {
290  return "shared_ptr<fee_schedule>";
291 } };
292 void from_variant( const fc::variant& var, std::shared_ptr<const graphene::protocol::fee_schedule>& vo,
293  uint32_t max_depth = 2 );
294 
295 } // fc::raw
296 
297 GRAPHENE_DEFINE_IDS(protocol, protocol_ids, /*protocol objects are not prefixed*/,
298  (null)
299  (base)
300  (account)
301  (asset)
302  (force_settlement)
303  (committee_member)
304  (witness)
305  (limit_order)
306  (call_order)
307  (custom) // unused
308  (proposal)
309  (operation_history)
310  (withdraw_permission)
311  (vesting_balance)
312  (worker)
313  (balance)
314  (htlc)
315  (custom_authority)
316  (ticket)
317  (liquidity_pool)
318  )
319 
322 
325 
328  (white_list)
332  (global_settle)
341  )
342 
343 namespace fc { namespace raw {
344  extern template void pack( datastream<size_t>& s, const graphene::protocol::public_key_type& tx,
345  uint32_t _max_depth );
346  extern template void pack( datastream<char*>& s, const graphene::protocol::public_key_type& tx,
347  uint32_t _max_depth );
349  uint32_t _max_depth );
350 } } // fc::raw
the max supply of the asset can not be updated
Definition: types.hpp:155
void from_variant(const fc::variant &var, std::shared_ptr< const graphene::protocol::fee_schedule > &vo, uint32_t max_depth=2)
Definition: types.cpp:106
require the issuer to be one party to every transfer
Definition: types.hpp:143
void pack(Stream &s, const flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:11
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
boost::rational< int32_t > ratio_type
Definition: types.hpp:133
contains all of the parameters necessary to calculate the fee for any operation
An order-perserving dictionary of variant&#39;s.
Definition: api.cpp:56
Defines types and macros used to provide reflection.
#define GRAPHENE_DEFINE_IDS(id_namespace, object_space, object_type_prefix, names_seq)
Definition: types.hpp:83
void unpack(Stream &s, flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:23
the bitasset owner can not update MCR, permisison only
Definition: types.hpp:163
bool is_relative(object_id_type o)
Definition: types.hpp:240
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
FC_REFLECT_TYPENAME(fc::log_message)
FC_REFLECT_ENUM(graphene::net::core_message_type_enum,(trx_message_type)(block_message_type)(core_message_type_first)(item_ids_inventory_message_type)(blockchain_item_ids_inventory_message_type)(fetch_blockchain_item_ids_message_type)(fetch_items_message_type)(item_not_available_message_type)(hello_message_type)(connection_accepted_message_type)(connection_rejected_message_type)(address_request_message_type)(address_message_type)(closing_connection_message_type)(current_time_request_message_type)(current_time_reply_message_type)(check_firewall_message_type)(check_firewall_reply_message_type)(get_current_connections_request_message_type)(get_current_connections_reply_message_type)(core_message_type_last))(different_chain)(already_connected)(connected_to_self)(not_accepting_connections)(blocked)(invalid_hello_message)(client_too_old))(inbound)(outbound))(firewalled)(not_firewalled))(unable_to_connect)(connection_successful)) namespace std
fc::ecc::public_key_data key_data
Definition: types.hpp:256
contains only the public point of an elliptic curve key.
Definition: elliptic.hpp:35
zero_initialized_array< unsigned char, 33 > commitment_type
Definition: elliptic.hpp:22
bool operator!=(const address &a, const address &b)
Definition: address.hpp:61
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
the bitasset owner can not update ICR, permisison only
Definition: types.hpp:164
market trades in this asset may be charged
Definition: types.hpp:140
accounts must be whitelisted in order to hold or transact this asset
Definition: types.hpp:141
std::vector< char > range_proof_type
Definition: elliptic.hpp:28
uint8_t space() const
Definition: object_id.hpp:47
bool operator()(const public_key_type &a, const public_key_type &b) const
Definition: types.hpp:271
zero_initialized_array< unsigned char, 33 > public_key_data
Definition: elliptic.hpp:23
void to_variant(const graphene::protocol::public_key_type &var, fc::variant &vo, uint32_t max_depth=2)
Definition: types.cpp:96
the bitasset is to be fed by witnesses
Definition: types.hpp:147
uint16_t weight_type
Definition: types.hpp:248
allow the bitasset owner to force a global settling, permission only
Definition: types.hpp:145
Definition: api.hpp:15
issuer may transfer asset back to himself
Definition: types.hpp:142
an elliptic curve private key.
Definition: elliptic.hpp:89
zero_initialized_array< unsigned char, 65 > compact_signature
Definition: elliptic.hpp:27
disallow the asset to be used with confidential transactions
Definition: types.hpp:146
bool operator==(const price &a, const price &b)
Definition: asset.cpp:35