FC Updates from BitShares and myself #21
1 changed files with 42 additions and 38 deletions
|
|
@ -49,13 +49,9 @@ hash160::operator string()const { return str(); }
|
||||||
|
|
||||||
char* hash160::data()const { return (char*)&_hash[0]; }
|
char* hash160::data()const { return (char*)&_hash[0]; }
|
||||||
|
|
||||||
|
|
||||||
class hash160::encoder::impl {
|
class hash160::encoder::impl {
|
||||||
public:
|
public:
|
||||||
impl()
|
impl() { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
hash160::encoder::~encoder() {}
|
hash160::encoder::~encoder() {}
|
||||||
|
|
@ -66,6 +62,7 @@ hash160 hash160::hash( const char* d, uint32_t dlen ) {
|
||||||
e.write(d,dlen);
|
e.write(d,dlen);
|
||||||
return e.result();
|
return e.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
hash160 hash160::hash( const string& s ) {
|
hash160 hash160::hash( const string& s ) {
|
||||||
return hash( s.c_str(), s.size() );
|
return hash( s.c_str(), s.size() );
|
||||||
}
|
}
|
||||||
|
|
@ -97,6 +94,7 @@ hash160 operator << ( const hash160& h1, uint32_t i ) {
|
||||||
fc::detail::shift_l( h1.data(), result.data(), result.data_size(), i );
|
fc::detail::shift_l( h1.data(), result.data(), result.data_size(), i );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
hash160 operator ^ ( const hash160& h1, const hash160& h2 ) {
|
hash160 operator ^ ( const hash160& h1, const hash160& h2 ) {
|
||||||
hash160 result;
|
hash160 result;
|
||||||
result._hash[0] = h1._hash[0].value() ^ h2._hash[0].value();
|
result._hash[0] = h1._hash[0].value() ^ h2._hash[0].value();
|
||||||
|
|
@ -106,32 +104,38 @@ hash160 operator ^ ( const hash160& h1, const hash160& h2 ) {
|
||||||
result._hash[4] = h1._hash[4].value() ^ h2._hash[4].value();
|
result._hash[4] = h1._hash[4].value() ^ h2._hash[4].value();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator >= ( const hash160& h1, const hash160& h2 ) {
|
bool operator >= ( const hash160& h1, const hash160& h2 ) {
|
||||||
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) >= 0;
|
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator > ( const hash160& h1, const hash160& h2 ) {
|
bool operator > ( const hash160& h1, const hash160& h2 ) {
|
||||||
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) > 0;
|
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < ( const hash160& h1, const hash160& h2 ) {
|
bool operator < ( const hash160& h1, const hash160& h2 ) {
|
||||||
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) < 0;
|
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != ( const hash160& h1, const hash160& h2 ) {
|
bool operator != ( const hash160& h1, const hash160& h2 ) {
|
||||||
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) != 0;
|
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator == ( const hash160& h1, const hash160& h2 ) {
|
bool operator == ( const hash160& h1, const hash160& h2 ) {
|
||||||
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) == 0;
|
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void to_variant( const hash160& bi, variant& v, uint32_t max_depth )
|
void to_variant( const hash160& bi, variant& v, uint32_t max_depth )
|
||||||
{
|
{
|
||||||
to_variant( std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) ), v, max_depth );
|
to_variant( std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) ), v, max_depth );
|
||||||
}
|
}
|
||||||
void from_variant( const variant& v, hash160& bi, uint32_t max_depth )
|
|
||||||
{
|
void from_variant( const variant& v, hash160& bi, uint32_t max_depth )
|
||||||
|
{
|
||||||
std::vector<char> ve = v.as< std::vector<char> >( max_depth );
|
std::vector<char> ve = v.as< std::vector<char> >( max_depth );
|
||||||
memset( &bi, char(0), sizeof(bi) );
|
memset( &bi, char(0), sizeof(bi) );
|
||||||
if( ve.size() )
|
if( ve.size() )
|
||||||
memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // fc
|
} // fc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue