Skip to content

Commit

Permalink
Rename some pack() / unpack() overrides steemit#1940
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Dec 22, 2017
1 parent 95b4175 commit e580e6d
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 66 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace steem { namespace chain {
FC_ASSERT( static_cast<uint64_t>(my->index_stream.tellp()) == sizeof( uint64_t ) * ( b.block_num() - 1 ),
"Append to index file occuring at wrong position.",
( "position", (uint64_t) my->index_stream.tellp() )( "expected",( b.block_num() - 1 ) * sizeof( uint64_t ) ) );
auto data = fc::raw::pack( b );
auto data = fc::raw::pack_to_vector( b );
my->block_stream.write( data.data(), data.size() );
my->block_stream.write( (char*)&pos, sizeof( pos ) );
my->index_stream.write( (char*)&pos, sizeof( pos ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ class generic_custom_operation_interpreter

try
{
custom_operations = fc::raw::unpack< vector< CustomOperationType > >( outer_o.data );
custom_operations = fc::raw::unpack_from_vector< vector< CustomOperationType > >( outer_o.data );
}
catch ( fc::exception& )
{
custom_operations.push_back( fc::raw::unpack< CustomOperationType >( outer_o.data ) );
custom_operations.push_back( fc::raw::unpack_from_vector< CustomOperationType >( outer_o.data ) );
}

apply_operations( custom_operations, operation( outer_o ) );
Expand Down
16 changes: 8 additions & 8 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,57 +136,57 @@ void witness_set_properties_evaluator::do_apply( const witness_set_properties_op
auto itr = o.props.find( "key" );

// This existence of 'key' is checked in witness_set_properties_operation::validate
fc::raw::unpack( itr->second, signing_key );
fc::raw::unpack_from_vector( itr->second, signing_key );
FC_ASSERT( signing_key == witness.signing_key, "'key' does not match witness signing key.",
("key", signing_key)("signing_key", witness.signing_key) );

itr = o.props.find( "account_creation_fee" );
if( itr != o.props.end() )
{
fc::raw::unpack( itr->second, props.account_creation_fee );
fc::raw::unpack_from_vector( itr->second, props.account_creation_fee );
account_creation_changed = true;
}

itr = o.props.find( "maximum_block_size" );
if( itr != o.props.end() )
{
fc::raw::unpack( itr->second, props.maximum_block_size );
fc::raw::unpack_from_vector( itr->second, props.maximum_block_size );
max_block_changed = true;
}

itr = o.props.find( "sbd_interest_rate" );
if( itr != o.props.end() )
{
fc::raw::unpack( itr->second, props.sbd_interest_rate );
fc::raw::unpack_from_vector( itr->second, props.sbd_interest_rate );
sbd_interest_changed = true;
}

itr = o.props.find( "account_subsidy_limit" );
if( itr != o.props.end() )
{
fc::raw::unpack( itr->second, props.account_subsidy_limit );
fc::raw::unpack_from_vector( itr->second, props.account_subsidy_limit );
account_subsidy_changed = true;
}

itr = o.props.find( "new_signing_key" );
if( itr != o.props.end() )
{
fc::raw::unpack( itr->second, signing_key );
fc::raw::unpack_from_vector( itr->second, signing_key );
key_changed = true;
}

itr = o.props.find( "sbd_exchange_rate" );
if( itr != o.props.end() )
{
fc::raw::unpack( itr->second, sbd_exchange_rate );
fc::raw::unpack_from_vector( itr->second, sbd_exchange_rate );
last_sbd_exchange_update = _db.head_block_time();
sbd_exchange_changed = true;
}

itr = o.props.find( "url" );
if( itr != o.props.end() )
{
fc::raw::unpack< std::string >( itr->second, url );
fc::raw::unpack_from_vector< std::string >( itr->second, url );
url_changed = true;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/fc
2 changes: 1 addition & 1 deletion libraries/net/include/graphene/net/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace graphene { namespace net {
message( const T& m )
{
msg_type = T::type;
data = fc::raw::pack(m);
data = fc::raw::pack_to_vector(m);
size = (uint32_t)data.size();
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/net/peer_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace graphene { namespace net
{
// patch the current time into the message. Since this operates on the packed version of the structure,
// it won't work for anything after a variable-length field
std::vector<char> packed_current_time = fc::raw::pack(fc::time_point::now());
std::vector<char> packed_current_time = fc::raw::pack_to_vector(fc::time_point::now());
assert(message_send_time_field_offset + packed_current_time.size() <= message_to_send.data.size());
memcpy(message_to_send.data.data() + message_send_time_field_offset,
packed_current_time.data(), packed_current_time.size());
Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/apis/database_api/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ DEFINE_API_IMPL( database_api_impl, get_order_book )

DEFINE_API_IMPL( database_api_impl, get_transaction_hex )
{
return get_transaction_hex_return( { fc::to_hex( fc::raw::pack( args.trx ) ) } );
return get_transaction_hex_return( { fc::to_hex( fc::raw::pack_to_vector( args.trx ) ) } );
}

DEFINE_API_IMPL( database_api_impl, get_required_signatures )
Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/block_log_info/block_log_info_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void block_log_info_plugin_impl::on_applied_block( const signed_block& b )


uint64_t offset = state.total_size;
std::vector< char > data = fc::raw::pack( b );
std::vector< char > data = fc::raw::pack_to_vector( b );
for( int i=0; i<8; i++ )
{
data.push_back( (char) (offset & 0xFF) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ namespace steem { namespace protocol {
if( key_itr != props.end() )
{
public_key_type signing_key;
fc::raw::unpack( key_itr->second, signing_key );
fc::raw::unpack_from_vector( key_itr->second, signing_key );
a.push_back( authority( 1, signing_key, 1 ) );
}
else
Expand Down
14 changes: 7 additions & 7 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace steem { namespace protocol {
if( itr != props.end() )
{
asset account_creation_fee;
fc::raw::unpack( itr->second, account_creation_fee );
fc::raw::unpack_from_vector( itr->second, account_creation_fee );
FC_ASSERT( account_creation_fee.symbol == STEEM_SYMBOL, "account_creation_fee must be in STEEM" );
FC_ASSERT( account_creation_fee.amount >= STEEM_MIN_ACCOUNT_CREATION_FEE , "account_creation_fee smaller than minimum account creation fee" );
}
Expand All @@ -217,15 +217,15 @@ namespace steem { namespace protocol {
if( itr != props.end() )
{
uint32_t maximum_block_size;
fc::raw::unpack( itr->second, maximum_block_size );
fc::raw::unpack_from_vector( itr->second, maximum_block_size );
FC_ASSERT( maximum_block_size >= STEEM_MIN_BLOCK_SIZE_LIMIT, "maximum_block_size smaller than minimum max block size" );
}

itr = props.find( "sbd_interest_rate" );
if( itr != props.end() )
{
uint16_t sbd_interest_rate;
fc::raw::unpack( itr->second, sbd_interest_rate );
fc::raw::unpack_from_vector( itr->second, sbd_interest_rate );
FC_ASSERT( sbd_interest_rate >= 0, "sbd_interest_rate must be positive" );
FC_ASSERT( sbd_interest_rate <= STEEM_100_PERCENT, "sbd_interest_rate must not exceed 100%" );
}
Expand All @@ -234,15 +234,15 @@ namespace steem { namespace protocol {
if( itr != props.end() )
{
public_key_type signing_key;
fc::raw::unpack( itr->second, signing_key );
fc::raw::unpack_from_vector( itr->second, signing_key );
FC_UNUSED( signing_key ); // This tests the deserialization of the key
}

itr = props.find( "sbd_exchange_rate" );
if( itr != props.end() )
{
price sbd_exchange_rate;
fc::raw::unpack( itr->second, sbd_exchange_rate );
fc::raw::unpack_from_vector( itr->second, sbd_exchange_rate );
FC_ASSERT( ( is_asset_type( sbd_exchange_rate.base, SBD_SYMBOL ) && is_asset_type( sbd_exchange_rate.quote, STEEM_SYMBOL ) ),
"Price feed must be a STEEM/SBD price" );
sbd_exchange_rate.validate();
Expand All @@ -252,7 +252,7 @@ namespace steem { namespace protocol {
if( itr != props.end() )
{
std::string url;
fc::raw::unpack< std::string >( itr->second, url );
fc::raw::unpack_from_vector< std::string >( itr->second, url );

FC_ASSERT( url.size() <= STEEM_MAX_WITNESS_URL_LENGTH, "URL is too long" );
FC_ASSERT( url.size() > 0, "URL size must be greater than 0" );
Expand All @@ -263,7 +263,7 @@ namespace steem { namespace protocol {
if( itr != props.end() )
{
uint32_t account_subsidy_limit;
fc::raw::unpack( itr->second, account_subsidy_limit ); // Checks that the value can be deserialized
fc::raw::unpack_from_vector( itr->second, account_subsidy_limit ); // Checks that the value can be deserialized
FC_UNUSED( account_subsidy_limit );
}
}
Expand Down
12 changes: 6 additions & 6 deletions libraries/protocol/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace steem { namespace protocol {
FC_ASSERT( base58str.size() > prefix_len );
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
auto bin_key = fc::raw::unpack<binary_key>(bin);
auto bin_key = fc::raw::unpack_from_vector<binary_key>(bin);
key_data = bin_key.data;
FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check );
};
Expand All @@ -47,7 +47,7 @@ namespace steem { namespace protocol {
binary_key k;
k.data = key_data;
k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0];
auto data = fc::raw::pack( k );
auto data = fc::raw::pack_to_vector( k );
return STEEM_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
}

Expand Down Expand Up @@ -86,7 +86,7 @@ namespace steem { namespace protocol {
FC_ASSERT( base58str.size() > prefix_len );
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
auto bin_key = fc::raw::unpack<binary_key>(bin);
auto bin_key = fc::raw::unpack_from_vector<binary_key>(bin);
FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == bin_key.check );
key_data = bin_key.data;
}
Expand All @@ -101,7 +101,7 @@ namespace steem { namespace protocol {
binary_key k;
k.data = key_data;
k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0];
auto data = fc::raw::pack( k );
auto data = fc::raw::pack_to_vector( k );
return STEEM_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
}

Expand Down Expand Up @@ -140,7 +140,7 @@ namespace steem { namespace protocol {
FC_ASSERT( base58str.size() > prefix_len );
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
auto bin_key = fc::raw::unpack<binary_key>(bin);
auto bin_key = fc::raw::unpack_from_vector<binary_key>(bin);
FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == bin_key.check );
key_data = bin_key.data;
}
Expand All @@ -155,7 +155,7 @@ namespace steem { namespace protocol {
binary_key k;
k.data = key_data;
k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0];
auto data = fc::raw::pack( k );
auto data = fc::raw::pack_to_vector( k );
return STEEM_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/wallet/include/steem/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct memo_data {
try {
if( str.size() > sizeof(memo_data) && str[0] == '#') {
auto data = fc::from_base58( str.substr(1) );
auto m = fc::raw::unpack<memo_data>( data );
auto m = fc::raw::unpack_from_vector<memo_data>( data );
FC_ASSERT( string(m) == str );
return m;
}
Expand All @@ -39,7 +39,7 @@ struct memo_data {
vector<char> encrypted;

operator string()const {
auto data = fc::raw::pack(*this);
auto data = fc::raw::pack_to_vector(*this);
auto base58 = fc::to_base58( data );
return '#'+base58;
}
Expand Down
10 changes: 5 additions & 5 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class wallet_api_impl
plain_keys data;
data.keys = _keys;
data.checksum = _checksum;
auto plain_txt = fc::raw::pack(data);
auto plain_txt = fc::raw::pack_to_vector(data);
_wallet.cipher_keys = fc::aes_encrypt( data.checksum, plain_txt );
}
}
Expand Down Expand Up @@ -984,7 +984,7 @@ brain_key_info wallet_api::suggest_brain_key()const

string wallet_api::serialize_transaction( signed_transaction tx )const
{
return fc::to_hex(fc::raw::pack(tx));
return fc::to_hex(fc::raw::pack_to_vector(tx));
}

string wallet_api::get_wallet_filename() const
Expand Down Expand Up @@ -1142,7 +1142,7 @@ void wallet_api::unlock(string password)
FC_ASSERT(password.size() > 0);
auto pw = fc::sha512::hash(password.c_str(), password.size());
vector<char> decrypted = fc::aes_decrypt(pw, my->_wallet.cipher_keys);
auto pk = fc::raw::unpack<plain_keys>(decrypted);
auto pk = fc::raw::unpack_from_vector<plain_keys>(decrypted);
FC_ASSERT(pk.checksum == pw);
my->_keys = std::move(pk.keys);
my->_checksum = pk.checksum;
Expand Down Expand Up @@ -1742,7 +1742,7 @@ string wallet_api::get_encrypted_memo( string from, string to, string memo ) {
fc::raw::pack( enc, shared_secret );
auto encrypt_key = enc.result();

m.encrypted = fc::aes_encrypt( encrypt_key, fc::raw::pack(memo.substr(1)) );
m.encrypted = fc::aes_encrypt( encrypt_key, fc::raw::pack_to_vector(memo.substr(1)) );
m.check = fc::sha256::hash( encrypt_key )._hash[0];
return m;
} else {
Expand Down Expand Up @@ -2042,7 +2042,7 @@ string wallet_api::decrypt_memo( string encrypted_memo ) {

try {
vector<char> decrypted = fc::aes_decrypt( encryption_key, m->encrypted );
return fc::raw::unpack<std::string>( decrypted );
return fc::raw::unpack_from_vector<std::string>( decrypted );
} catch ( ... ){}
}
}
Expand Down
2 changes: 1 addition & 1 deletion programs/size_checker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ template< typename T >
uint64_t get_wire_size()
{
T data;
return fc::raw::pack( data ).size();
return fc::raw::pack_to_vector( data ).size();
}

struct size_check_type_visitor
Expand Down
10 changes: 7 additions & 3 deletions tests/db_fixture/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ void database_fixture::proxy( const string& account, const string& proxy )
void database_fixture::set_price_feed( const price& new_price )
{
flat_map< string, vector< char > > props;
props[ "sbd_exchange_rate" ] = fc::raw::pack( new_price );
props[ "sbd_exchange_rate" ] = fc::raw::pack_to_vector( new_price );

set_witness_props( props );

Expand All @@ -555,7 +555,7 @@ void database_fixture::set_witness_props( const flat_map< string, vector< char >

if( op.props.find( "key" ) == op.props.end() )
{
op.props[ "key" ] = fc::raw::pack( init_account_pub_key );
op.props[ "key" ] = fc::raw::pack_to_vector( init_account_pub_key );
}

trx.operations.push_back( op );
Expand Down Expand Up @@ -586,7 +586,11 @@ vector< operation > database_fixture::get_last_operations( uint32_t num_ops )
while( itr != acc_hist_idx.begin() && ops.size() < num_ops )
{
itr--;
ops.push_back( fc::raw::unpack< steem::chain::operation >( db->get(itr->op).serialized_op ) );
const buffer_type& bip_serialized_op = db->get(itr->op).serialized_op;
std::vector<char> serialized_op;
serialized_op.reserve( bip_serialized_op.size() );
std::copy( bip_serialized_op.begin(), bip_serialized_op.end(), std::back_inserter( serialized_op ) );
ops.push_back( fc::raw::unpack_from_vector< steem::chain::operation >( serialized_op ) );
}

return ops;
Expand Down
Loading

0 comments on commit e580e6d

Please sign in to comment.