FC Updates from BitShares and myself #21

Closed
nathanielhourt wants to merge 687 commits from dapp-support into latest-fc
8 changed files with 81 additions and 16 deletions
Showing only changes of commit efa4a504de - Show all commits

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <fc/io/raw_fwd.hpp>
#include <fc/crypto/sha512.hpp> #include <fc/crypto/sha512.hpp>
#include <fc/crypto/sha256.hpp> #include <fc/crypto/sha256.hpp>
#include <fc/uint128.hpp> #include <fc/uint128.hpp>

View file

@ -71,6 +71,20 @@ class ripemd160
uint32_t _hash[5]; uint32_t _hash[5];
}; };
namespace raw {
template<typename T>
inline void pack( T& ds, const ripemd160& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, ripemd160& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
class variant; class variant;
void to_variant( const ripemd160& bi, variant& v ); void to_variant( const ripemd160& bi, variant& v );
void from_variant( const variant& v, ripemd160& bi ); void from_variant( const variant& v, ripemd160& bi );

View file

@ -70,6 +70,20 @@ class sha224
uint32_t _hash[7]; uint32_t _hash[7];
}; };
namespace raw {
template<typename T>
inline void pack( T& ds, const sha224& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, sha224& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
class variant; class variant;
void to_variant( const sha224& bi, variant& v ); void to_variant( const sha224& bi, variant& v );
void from_variant( const variant& v, sha224& bi ); void from_variant( const variant& v, sha224& bi );

View file

@ -98,6 +98,20 @@ class sha256
uint64_t _hash[4]; uint64_t _hash[4];
}; };
namespace raw {
template<typename T>
inline void pack( T& ds, const sha256& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, sha256& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
typedef sha256 uint256; typedef sha256 uint256;
class variant; class variant;

View file

@ -66,6 +66,20 @@ class sha512
uint64_t _hash[8]; uint64_t _hash[8];
}; };
namespace raw {
template<typename T>
inline void pack( T& ds, const sha512& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, sha512& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
typedef fc::sha512 uint512; typedef fc::sha512 uint512;
class variant; class variant;

View file

@ -351,13 +351,10 @@ namespace fc {
const uint32_t max_depth; const uint32_t max_depth;
}; };
// Default pack/unpack functions for classes (if_class<fc::true_type>) are removed due to recursion issue.
// Classes should implement pack/unpack functions explicitly.
template<typename IsClass=fc::true_type> template<typename IsClass=fc::true_type>
struct if_class{ struct if_class;
template<typename Stream, typename T>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) { s << v; }
template<typename Stream, typename T>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) { s >> v; }
};
template<> template<>
struct if_class<fc::false_type> { struct if_class<fc::false_type> {

View file

@ -22,6 +22,11 @@ namespace fc {
class path; class path;
template<typename... Types> class static_variant; template<typename... Types> class static_variant;
class sha224;
class sha256;
class sha512;
class ripemd160;
template<typename IntType, typename EnumType> class enum_type; template<typename IntType, typename EnumType> class enum_type;
namespace ip { class endpoint; } namespace ip { class endpoint; }
@ -96,6 +101,15 @@ namespace fc {
template<typename Stream> void unpack( Stream& s, fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template<typename Stream> void unpack( Stream& s, fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> void pack( Stream& s, const fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template<typename Stream> void pack( Stream& s, const fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::sha224&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::sha224&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::sha256&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::sha256&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::sha512&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::sha512&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::ripemd160&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::ripemd160&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void pack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template<typename Stream, typename T> inline void pack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template<typename Stream, typename T> inline void unpack( Stream& s, T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );

View file

@ -7,8 +7,8 @@
namespace fc { namespace test { namespace fc { namespace test {
struct item; struct item;
inline bool operator < ( const item& a, const item& b );
inline bool operator == ( const item& a, const item& b ); inline bool operator == ( const item& a, const item& b );
inline bool operator < ( const item& a, const item& b );
struct item_wrapper struct item_wrapper
{ {
@ -16,8 +16,11 @@ namespace fc { namespace test {
item_wrapper(item&& it) { v.reserve(1); v.insert( it ); } item_wrapper(item&& it) { v.reserve(1); v.insert( it ); }
boost::container::flat_set<struct item> v; boost::container::flat_set<struct item> v;
}; };
inline bool operator < ( const item_wrapper& a, const item_wrapper& b );
inline bool operator == ( const item_wrapper& a, const item_wrapper& b ); inline bool operator == ( const item_wrapper& a, const item_wrapper& b )
{ return ( std::tie( a.v ) == std::tie( b.v ) ); }
inline bool operator < ( const item_wrapper& a, const item_wrapper& b )
{ return ( std::tie( a.v ) < std::tie( b.v ) ); }
struct item struct item
{ {
@ -29,17 +32,11 @@ namespace fc { namespace test {
inline bool operator == ( const item& a, const item& b ) inline bool operator == ( const item& a, const item& b )
{ return ( std::tie( a.level, a.w ) == std::tie( b.level, b.w ) ); } { return ( std::tie( a.level, a.w ) == std::tie( b.level, b.w ) ); }
inline bool operator < ( const item& a, const item& b ) inline bool operator < ( const item& a, const item& b )
{ return ( std::tie( a.level, a.w ) < std::tie( b.level, b.w ) ); } { return ( std::tie( a.level, a.w ) < std::tie( b.level, b.w ) ); }
inline bool operator == ( const item_wrapper& a, const item_wrapper& b )
{ return ( std::tie( a.v ) == std::tie( b.v ) ); }
inline bool operator < ( const item_wrapper& a, const item_wrapper& b ) } } // namespace fc::test
{ return ( std::tie( a.v ) < std::tie( b.v ) ); }
} }
FC_REFLECT( fc::test::item_wrapper, (v) ); FC_REFLECT( fc::test::item_wrapper, (v) );
FC_REFLECT( fc::test::item, (level)(w) ); FC_REFLECT( fc::test::item, (level)(w) );