Skip to content

Commit

Permalink
Merge pull request #1115 from steemit/steem-prerelease-v0.18.5
Browse files Browse the repository at this point in the history
Steem prerelease v0.18.5
  • Loading branch information
Michael Vandeberg authored May 18, 2017
2 parents 38a009d + f98e474 commit 631c32c
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 80 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ RUN \
-DLOW_MEMORY_NODE=OFF \
-DCLEAR_VOTES=ON \
.. && \
make -j$(nproc) chain_test && \
make -j$(nproc) chain_test test_fixed_string && \
./tests/chain_test && \
./programs/util/test_fixed_string && \
cd /usr/local/src/steem && \
doxygen && \
programs/build_helpers/check_reflect.py && \
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/steemit/chain/steem_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace steemit { namespace chain {
using steemit::protocol::price;
using steemit::protocol::asset_symbol_type;

typedef protocol::fixed_string reward_fund_name_type;
typedef protocol::fixed_string_16 reward_fund_name_type;

/**
* This object is used to track pending requests to convert sbd to steem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using chainbase::allocator;

#define TAGS_PLUGIN_NAME "tags"

typedef protocol::fixed_string tag_name_type;
typedef protocol::fixed_string_32 tag_name_type;

// Plugins need to define object type IDs such that they do not conflict
// globally. If each plugin uses the upper 8 bits as a space identifier,
Expand Down
1 change: 0 additions & 1 deletion libraries/protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ add_library( steemit_protocol
transaction.cpp
block.cpp
asset.cpp
fixed_string.cpp
version.cpp
get_config.cpp

Expand Down
51 changes: 0 additions & 51 deletions libraries/protocol/fixed_string.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion libraries/protocol/include/steemit/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
#pragma once

#define STEEMIT_BLOCKCHAIN_VERSION ( version(0, 18, 4) )
#define STEEMIT_BLOCKCHAIN_VERSION ( version(0, 18, 5) )
#define STEEMIT_BLOCKCHAIN_HARDFORK_VERSION ( hardfork_version( STEEMIT_BLOCKCHAIN_VERSION ) )

#ifdef IS_TEST_NET
Expand Down
113 changes: 98 additions & 15 deletions libraries/protocol/include/steemit/protocol/fixed_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,104 @@
#include <fc/uint128.hpp>
#include <fc/io/raw_fwd.hpp>

#include <boost/endian/conversion.hpp>

// These overloads need to be defined before the implementation in fixed_string
namespace fc
{
/**
* Endian-reversible pair class.
*/

template< typename A, typename B >
struct erpair
{
erpair() {}
erpair(const A& a, const B& b)
: first(a), second(b) {}
friend bool operator < ( const erpair& a, const erpair& b )
{ return std::tie( a.first, a.second ) < std::tie( b.first, b.second ); }
friend bool operator <= ( const erpair& a, const erpair& b )
{ return std::tie( a.first, a.second ) <= std::tie( b.first, b.second ); }
friend bool operator > ( const erpair& a, const erpair& b )
{ return std::tie( a.first, a.second ) > std::tie( b.first, b.second ); }
friend bool operator >= ( const erpair& a, const erpair& b )
{ return std::tie( a.first, a.second ) >= std::tie( b.first, b.second ); }
friend bool operator == ( const erpair& a, const erpair& b )
{ return std::tie( a.first, a.second ) == std::tie( b.first, b.second ); }
friend bool operator != ( const erpair& a, const erpair& b )
{ return std::tie( a.first, a.second ) != std::tie( b.first, b.second ); }

A first{};
B second{};
};

template< typename A, typename B >
erpair<A, B> make_erpair( const A& a, const B& b )
{ return erpair<A, B>(a, b); }

template< typename T >
T endian_reverse( const T& x )
{ return boost::endian::endian_reverse(x); }

template<>
inline uint128 endian_reverse( const uint128& u )
{ return uint128( boost::endian::endian_reverse( u.hi ), boost::endian::endian_reverse( u.lo ) ); }

template<typename A, typename B>
erpair< A, B > endian_reverse( const erpair< A, B >& p )
{
return make_erpair( endian_reverse( p.first ), endian_reverse( p.second ) );
}
}

namespace steemit { namespace protocol {

/**
* This class is an in-place memory allocation of a 16 character string.
* This class is an in-place memory allocation of a fixed length character string.
*
* The string will serialize the same way as std::string for variant and raw formats,
* but will be in memory as a 128-bit integer so that we can exploit efficient
* integer comparisons for sorting.
* The string will serialize the same way as std::string for variant and raw formats.
*/
template< typename Storage = fc::uint128 >
class fixed_string
{
public:
typedef fc::uint128_t Storage;

fixed_string(){}
fixed_string( const fixed_string& c ) : data( c.data ){}
fixed_string( const char* str ) : fixed_string( std::string( str ) ) {}
fixed_string( const std::string& str );
fixed_string( const std::string& str )
{
Storage d;
if( str.size() <= sizeof(d) )
memcpy( (char*)&d, str.c_str(), str.size() );
else
memcpy( (char*)&d, str.c_str(), sizeof(d) );

operator std::string()const;
data = boost::endian::big_to_native( d );
}

uint32_t size()const;
operator std::string()const
{
Storage d = boost::endian::native_to_big( data );
size_t s;

if( *(((const char*)&d) + sizeof(d) - 1) )
s = sizeof(d);
else
s = strnlen( (const char*)&d, sizeof(d) );

const char* self = (const char*)&d;

return std::string( self, self + s );
}

uint32_t size()const
{
Storage d = boost::endian::native_to_big( data );
if( *(((const char*)&d) + sizeof(d) - 1) )
return sizeof(d);
return strnlen( (const char*)&d, sizeof(d) );
}

uint32_t length()const { return size(); }

Expand Down Expand Up @@ -58,26 +134,33 @@ class fixed_string
Storage data;
};

// These storage types work with memory layout and should be used instead of a custom template.
typedef fixed_string< fc::uint128_t > fixed_string_16;
typedef fixed_string< fc::erpair< fc::uint128_t, uint64_t > > fixed_string_24;
typedef fixed_string< fc::erpair< fc::uint128_t, fc::uint128_t > > fixed_string_32;

} } // steemit::protocol

namespace fc { namespace raw {

template< typename Stream >
inline void pack( Stream& s, const steemit::protocol::fixed_string& u )
template< typename Stream, typename Storage >
inline void pack( Stream& s, const steemit::protocol::fixed_string< Storage >& u )
{
pack( s, std::string( u ) );
}

template< typename Stream >
inline void unpack( Stream& s, steemit::protocol::fixed_string& u )
template< typename Stream, typename Storage >
inline void unpack( Stream& s, steemit::protocol::fixed_string< Storage >& u )
{
std::string str;
unpack( s, str );
u = str;
}

} // raw
template< typename Storage >
void to_variant( const steemit::protocol::fixed_string< Storage >& s, variant& v ) { v = std::string( s ); }

void to_variant( const steemit::protocol::fixed_string& s, variant& v );
void from_variant( const variant& v, steemit::protocol::fixed_string& s );
template< typename Storage >
void from_variant( const variant& v, steemit::protocol::fixed_string< Storage >& s ) { s = v.as_string(); }
} // fc
2 changes: 1 addition & 1 deletion libraries/protocol/include/steemit/protocol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace steemit {

typedef fc::ecc::private_key private_key_type;
typedef fc::sha256 chain_id_type;
typedef fixed_string account_name_type;
typedef fixed_string_16 account_name_type;
typedef fc::ripemd160 block_id_type;
typedef fc::ripemd160 checksum_type;
typedef fc::ripemd160 transaction_id_type;
Expand Down
Loading

0 comments on commit 631c32c

Please sign in to comment.