BitShares-Core  6.1.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_VARIANT(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 }
68 
69 #define GRAPHENE_EXTERNAL_SERIALIZATION_PACK(ext, type) \
70 namespace fc { namespace raw { \
71  ext template void pack< datastream<size_t>, type >( \
72  datastream<size_t>& s, const type& tx, uint32_t _max_depth ); \
73  ext template void pack< sha256::encoder, type >( \
74  sha256::encoder& s, const type& tx, uint32_t _max_depth ); \
75  ext template void pack< datastream<char*>, type >( \
76  datastream<char*>& s, const type& tx, uint32_t _max_depth ); \
77  ext template void unpack< datastream<const char*>, type >( \
78  datastream<const char*>& s, type& tx, uint32_t _max_depth ); \
79 } }
80 
81 #define GRAPHENE_EXTERNAL_SERIALIZATION(ext, type) \
82  GRAPHENE_EXTERNAL_SERIALIZATION_VARIANT(ext, type) \
83  GRAPHENE_EXTERNAL_SERIALIZATION_PACK(ext, type)
84 
85 #define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type) GRAPHENE_EXTERNAL_SERIALIZATION(extern, type)
86 #define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION(type) GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, type)
87 
88 #define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION_VARIANT(type) \
89  GRAPHENE_EXTERNAL_SERIALIZATION_VARIANT(/*not extern*/, type)
90 #define GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION_PACK(type) \
91  GRAPHENE_EXTERNAL_SERIALIZATION_PACK(/*not extern*/, type)
92 
93 #define GRAPHENE_NAME_TO_OBJECT_TYPE(x, prefix, name) BOOST_PP_CAT(prefix, BOOST_PP_CAT(name, _object_type))
94 #define GRAPHENE_NAME_TO_ID_TYPE(x, y, name) BOOST_PP_CAT(name, _id_type)
95 #define GRAPHENE_DECLARE_ID(x, space_prefix_seq, name) \
96  using BOOST_PP_CAT(name, _id_type) = object_id<BOOST_PP_TUPLE_ELEM(2, 0, space_prefix_seq), \
97  GRAPHENE_NAME_TO_OBJECT_TYPE(x, BOOST_PP_TUPLE_ELEM(2, 1, space_prefix_seq), name)>;
98 #define GRAPHENE_REFLECT_ID(x, id_namespace, name) FC_REFLECT_TYPENAME(graphene::id_namespace::name)
99 
100 #define GRAPHENE_DEFINE_IDS(id_namespace, object_space, object_type_prefix, names_seq) \
101  namespace graphene { namespace id_namespace { \
102  \
103  enum BOOST_PP_CAT(object_type_prefix, object_type) { \
104  BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_OBJECT_TYPE, object_type_prefix, names_seq)) \
105  }; \
106  \
107  BOOST_PP_SEQ_FOR_EACH(GRAPHENE_DECLARE_ID, (object_space, object_type_prefix), names_seq) \
108  \
109  } } \
110  \
111  FC_REFLECT_ENUM(graphene::id_namespace::BOOST_PP_CAT(object_type_prefix, object_type), \
112  BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_OBJECT_TYPE, object_type_prefix, names_seq)) \
113  BOOST_PP_SEQ_FOR_EACH(GRAPHENE_REFLECT_ID, id_namespace, BOOST_PP_SEQ_TRANSFORM(GRAPHENE_NAME_TO_ID_TYPE, , names_seq))
114 
115 namespace graphene { namespace protocol {
116 using namespace graphene::db;
117 
118 using std::map;
119 using std::vector;
120 using std::unordered_map;
121 using std::string;
122 using std::deque;
123 using std::shared_ptr;
124 using std::weak_ptr;
125 using std::unique_ptr;
126 using std::set;
127 using std::pair;
128 using std::enable_shared_from_this;
129 using std::tie;
130 using std::make_pair;
131 
132 using fc::variant_object;
133 using fc::variant;
134 using fc::enum_type;
135 using fc::optional;
136 using fc::unsigned_int;
137 using fc::time_point_sec;
138 using fc::time_point;
139 using fc::safe;
140 using fc::flat_map;
141 using fc::flat_set;
142 using fc::static_variant;
146 struct void_t{};
147 
150 using ratio_type = boost::rational<int32_t>;
151 
189  // Permission-enabling bits begin
190  // If one of the following bits is set in asset issuer permissions,
191  // it means the asset issuer (or owner for bitassets) has the permission to update
192  // the corresponding flag, parameters or perform certain actions.
193  // Note: This comment is copied and reformatted above for better Doxygen documentation formatting.
195  white_list = 0x02,
199  global_settle = 0x20,
203  // Permission-enabling bits end
204 
205  // Permission-disabling bits begin
206  // If one of the following bits is set in asset issuer permissions,
207  // it means the asset issuer (or owner for bitassets) does NOT have the permission to update
208  // the corresponding flag, parameters or perform certain actions.
209  // This is to be compatible with old client software.
210  // Note: This comment is copied and reformatted above for better Doxygen documentation formatting.
211  lock_max_supply = 0x200,
213  // For disable_mcr_update, disable_icr_update and disable_mssr_update,
214  // if one of these is set in asset issuer permissions, and
215  // - if the bitasset owner has set a value for the corresponding parameter, the value can not be updated,
216  // - if the bitasset owner has not set a value for the corresponding parameter, the parameter can still be
217  // updated by the price feed producers.
218  // Note: This comment is copied and reformatted above for better Doxygen documentation formatting.
224  // Permission-disabling bits end
225 };
226 
228 const static uint16_t ASSET_ISSUER_PERMISSION_MASK =
230  | white_list
234  | global_settle
246 const static uint16_t ASSET_ISSUER_PERMISSION_ENABLE_BITS_MASK =
248  | white_list
252  | global_settle
257 const static uint16_t ASSET_ISSUER_PERMISSION_DISABLE_BITS_MASK =
266 const static uint16_t UIA_ASSET_ISSUER_PERMISSION_MASK =
268  | white_list
275 const static uint16_t DEFAULT_UIA_ASSET_ISSUER_PERMISSION =
277  | white_list
282 const static uint16_t NON_UIA_ONLY_ISSUER_PERMISSION_MASK =
283  ASSET_ISSUER_PERMISSION_MASK ^ UIA_ASSET_ISSUER_PERMISSION_MASK;
285 const static uint16_t PERMISSION_ONLY_MASK =
292 const static uint16_t VALID_FLAGS_MASK = ASSET_ISSUER_PERMISSION_MASK & (uint16_t)(~PERMISSION_ONLY_MASK);
294 const static uint16_t UIA_VALID_FLAGS_MASK = UIA_ASSET_ISSUER_PERMISSION_MASK;
295 
300 };
301 
302 inline bool is_relative(object_id_type o) { return o.space() == 0; }
303 
310 using weight_type = uint16_t;
311 
313  struct binary_key {
314  binary_key() = default;
315  uint32_t check = 0;
317  };
319  public_key_type();
321  public_key_type(const fc::ecc::public_key& pubkey);
322  explicit public_key_type(const std::string& base58str);
323  operator fc::ecc::public_key_data() const;
324  operator fc::ecc::public_key() const;
325  explicit operator std::string() const;
326  friend bool operator == (const public_key_type& p1, const fc::ecc::public_key& p2);
327  friend bool operator == (const public_key_type& p1, const public_key_type& p2);
328  friend bool operator != (const public_key_type& p1, const public_key_type& p2);
329  friend bool operator < (const public_key_type& p1, const public_key_type& p2);
330 };
331 
333 public:
334  inline bool operator()(const public_key_type& a, const public_key_type& b) const {
335  return a.key_data < b.key_data;
336  }
337 };
338 
339 struct fee_schedule;
340 } } // graphene::protocol
341 
342 namespace fc {
343 void to_variant(const graphene::protocol::public_key_type& var, fc::variant& vo, uint32_t max_depth = 2);
344 void from_variant(const fc::variant& var, graphene::protocol::public_key_type& vo, uint32_t max_depth = 2);
345 
346 
347 template<>
348 struct get_typename<std::shared_ptr<const graphene::protocol::fee_schedule>> { static const char* name() {
349  return "shared_ptr<const fee_schedule>";
350 } };
351 template<>
352 struct get_typename<std::shared_ptr<graphene::protocol::fee_schedule>> { static const char* name() {
353  return "shared_ptr<fee_schedule>";
354 } };
355 void from_variant( const fc::variant& var, std::shared_ptr<const graphene::protocol::fee_schedule>& vo,
356  uint32_t max_depth = 2 );
357 
358 } // fc::raw
359 
360 
362 GRAPHENE_DEFINE_IDS(protocol, protocol_ids, /*protocol objects are not prefixed*/,
363  /* 1.0.x */ (null) // no data
364  /* 1.1.x */ (base) // no data
365  /* 1.2.x */ (account)
366  /* 1.3.x */ (asset)
367  /* 1.4.x */ (force_settlement)
368  /* 1.5.x */ (committee_member)
369  /* 1.6.x */ (witness)
370  /* 1.7.x */ (limit_order)
371  /* 1.8.x */ (call_order)
372  /* 1.9.x */ (custom) // unused
373  /* 1.10.x */ (proposal)
374  /* 1.11.x */ (operation_history) // strictly speaking it is not in protocol
375  /* 1.12.x */ (withdraw_permission)
376  /* 1.13.x */ (vesting_balance)
377  /* 1.14.x */ (worker)
378  /* 1.15.x */ (balance)
379  /* 1.16.x */ (htlc)
380  /* 1.17.x */ (custom_authority)
381  /* 1.18.x */ (ticket)
382  /* 1.19.x */ (liquidity_pool)
383  /* 1.20.x */ (samet_fund)
384  /* 1.21.x */ (credit_offer)
385  /* 1.22.x */ (credit_deal)
386  )
387 
390 
393 
396  (white_list)
400  (global_settle)
411  )
412 
413 namespace fc { namespace raw {
414  extern template void pack( datastream<size_t>& s, const graphene::protocol::public_key_type& tx,
415  uint32_t _max_depth );
416  extern template void pack( datastream<char*>& s, const graphene::protocol::public_key_type& tx,
417  uint32_t _max_depth );
419  uint32_t _max_depth );
420 } } // fc::raw
the max supply of the asset can not be updated
Definition: types.hpp:211
void from_variant(const fc::variant &var, std::shared_ptr< const graphene::protocol::fee_schedule > &vo, uint32_t max_depth=2)
Definition: types.cpp:111
require the issuer to be one party to every transfer
Definition: types.hpp:197
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:388
boost::rational< int32_t > ratio_type
Definition: types.hpp:150
contains all of the parameters necessary to calculate the fee for any operation
An order-perserving dictionary of variant&#39;s.
Definition: api.cpp:48
Defines types and macros used to provide reflection.
#define GRAPHENE_DEFINE_IDS(id_namespace, object_space, object_type_prefix, names_seq)
Definition: types.hpp:100
the bitasset owner can not update MSSR, permission only
Definition: types.hpp:221
bool operator()(const public_key_type &a, const public_key_type &b) const
Definition: types.hpp:334
void unpack(Stream &s, flat_set< T, A... > &value, uint32_t _max_depth)
Definition: flat.hpp:23
the bitasset owner can not update MCR, permission only
Definition: types.hpp:219
bool operator<(const price &a, const price &b)
Definition: asset.cpp:45
bool is_relative(object_id_type o)
Definition: types.hpp:302
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
unable to create new supply for the asset
Definition: types.hpp:212
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:318
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, permission only
Definition: types.hpp:220
market trades in this asset may be charged
Definition: types.hpp:194
accounts must be whitelisted in order to hold or transact this asset
Definition: types.hpp:195
std::vector< char > range_proof_type
Definition: elliptic.hpp:28
Can not bid collateral after a global settlement.
Definition: types.hpp:223
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:101
the bitasset is to be fed by witnesses
Definition: types.hpp:201
uint16_t weight_type
Definition: types.hpp:310
allow the bitasset owner to force a global settlement, permission only
Definition: types.hpp:199
Definition: api.hpp:15
issuer may transfer asset back to himself
Definition: types.hpp:196
the bitasset is to be fed by the committee
Definition: types.hpp:202
an elliptic curve private key.
Definition: elliptic.hpp:89
zero_initialized_array< unsigned char, 65 > compact_signature
Definition: elliptic.hpp:27
the bitasset owner can not update BSRM, permission only
Definition: types.hpp:222
disallow the asset to be used with confidential transactions
Definition: types.hpp:200
bool operator==(const price &a, const price &b)
Definition: asset.cpp:34