Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Replace fc::optional with std::optional
Browse files Browse the repository at this point in the history
Cherry-picked from 9a10d21 with
adaptation to 2.0.x.
  • Loading branch information
swatanabe committed Jan 28, 2022
1 parent 0c4f36d commit 1fe4aef
Show file tree
Hide file tree
Showing 66 changed files with 499 additions and 509 deletions.
10 changes: 5 additions & 5 deletions libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace eosio { namespace chain {
if( is_array )
fc::raw::pack( ds, var.as<vector<T>>() );
else if ( is_optional )
fc::raw::pack( ds, var.as<optional<T>>() );
fc::raw::pack( ds, var.as<std::optional<T>>() );
else
fc::raw::pack( ds, var.as<T>());
};
Expand All @@ -51,7 +51,7 @@ namespace eosio { namespace chain {
if( is_array )
return variant_from_stream<vector<T>>(stream);
else if ( is_optional )
return variant_from_stream<optional<T>>(stream);
return variant_from_stream<std::optional<T>>(stream);
return variant_from_stream<T>(stream);
},
pack_function<T>()
Expand All @@ -65,7 +65,7 @@ namespace eosio { namespace chain {
if( is_array )
return variant_from_stream<vector<T>>(stream);
else if ( is_optional )
return variant_from_stream<optional<T>>(stream);
return variant_from_stream<std::optional<T>>(stream);
return variant_from_stream<T>(stream, yield);
},
pack_function<T>()
Expand Down Expand Up @@ -606,10 +606,10 @@ namespace eosio { namespace chain {
return type_name();
}

optional<string> abi_serializer::get_error_message( uint64_t error_code )const {
std::optional<string> abi_serializer::get_error_message( uint64_t error_code )const {
auto itr = error_messages.find( error_code );
if( itr == error_messages.end() )
return optional<string>();
return std::optional<string>();

return itr->second;
}
Expand Down
26 changes: 12 additions & 14 deletions libraries/chain/authorization_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ namespace eosio { namespace chain {
return _db.get<permission_object, by_owner>( boost::make_tuple(level.actor,level.permission) );
} EOS_RETHROW_EXCEPTIONS( chain::permission_query_exception, "Failed to retrieve permission: ${level}", ("level", level) ) }

optional<permission_name> authorization_manager::lookup_linked_permission( account_name authorizer_account,
account_name scope,
action_name act_name
)const
std::optional<permission_name> authorization_manager::lookup_linked_permission( account_name authorizer_account,
account_name scope,
action_name act_name
)const
{
try {
// First look up a specific link for this message act_name
Expand All @@ -254,16 +254,14 @@ namespace eosio { namespace chain {
if (link != nullptr) {
return link->required_permission;
}
return optional<permission_name>();

// return optional<permission_name>();
return std::optional<permission_name>();
} FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name))
}

optional<permission_name> authorization_manager::lookup_minimum_permission( account_name authorizer_account,
account_name scope,
action_name act_name
)const
std::optional<permission_name> authorization_manager::lookup_minimum_permission( account_name authorizer_account,
account_name scope,
action_name act_name
)const
{
// Special case native actions cannot be linked to a minimum permission, so there is no need to check.
if( scope == config::system_account_name ) {
Expand All @@ -277,12 +275,12 @@ namespace eosio { namespace chain {
}

try {
optional<permission_name> linked_permission = lookup_linked_permission(authorizer_account, scope, act_name);
std::optional<permission_name> linked_permission = lookup_linked_permission(authorizer_account, scope, act_name);
if( !linked_permission )
return config::active_name;

if( *linked_permission == config::eosio_any_name )
return optional<permission_name>();
return std::optional<permission_name>();

return linked_permission;
} FC_CAPTURE_AND_RETHROW((authorizer_account)(scope)(act_name))
Expand Down Expand Up @@ -377,7 +375,7 @@ namespace eosio { namespace chain {
"the owner of the linked permission needs to be the actor of the declared authorization" );

const auto unlinked_permission_name = lookup_linked_permission(unlink.account, unlink.code, unlink.type);
EOS_ASSERT( unlinked_permission_name.valid(), transaction_exception,
EOS_ASSERT( unlinked_permission_name, transaction_exception,
"cannot unlink non-existent permission link of account '${account}' for actions matching '${code}::${action}'",
("account", unlink.account)("code", unlink.code)("action", unlink.type) );

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace eosio { namespace chain {
signed_block_header pending_block_header_state::make_block_header(
const checksum256_type& transaction_mroot,
const checksum256_type& action_mroot,
const optional<producer_authority_schedule>& new_producers,
const std::optional<producer_authority_schedule>& new_producers,
vector<digest_type>&& new_protocol_feature_activations,
const protocol_feature_set& pfs
)const
Expand Down
22 changes: 11 additions & 11 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace eosio { namespace chain {
uint64_t append(const signed_block_ptr& b);

template <typename ChainContext, typename Lambda>
static fc::optional<ChainContext> extract_chain_context( const fc::path& data_dir, Lambda&& lambda );
static std::optional<ChainContext> extract_chain_context( const fc::path& data_dir, Lambda&& lambda );
};

void detail::block_log_impl::reopen() {
Expand Down Expand Up @@ -609,10 +609,10 @@ namespace eosio { namespace chain {
new_block_stream.write( (char*)&actual_totem, sizeof(actual_totem) );
}

std::exception_ptr except_ptr;
vector<char> incomplete_block_data;
optional<signed_block> bad_block;
uint32_t block_num = 0;
std::exception_ptr except_ptr;
vector<char> incomplete_block_data;
std::optional<signed_block> bad_block;
uint32_t block_num = 0;

block_id_type previous;

Expand Down Expand Up @@ -662,7 +662,7 @@ namespace eosio { namespace chain {
break;
}

if( bad_block.valid() ) {
if( bad_block ) {
ilog( "Recovered only up to block number ${num}. Last block in block log was not properly committed:\n${last_block}",
("num", block_num)("last_block", *bad_block) );
} else if( except_ptr ) {
Expand Down Expand Up @@ -702,7 +702,7 @@ namespace eosio { namespace chain {
}

template <typename ChainContext, typename Lambda>
fc::optional<ChainContext> detail::block_log_impl::extract_chain_context( const fc::path& data_dir, Lambda&& lambda ) {
std::optional<ChainContext> detail::block_log_impl::extract_chain_context( const fc::path& data_dir, Lambda&& lambda ) {
EOS_ASSERT( fc::is_directory(data_dir) && fc::is_regular_file(data_dir / "blocks.log"), block_log_not_found,
"Block log not found in '${blocks_dir}'", ("blocks_dir", data_dir) );

Expand All @@ -723,21 +723,21 @@ namespace eosio { namespace chain {
return lambda(block_stream, version, first_block_num);
}

fc::optional<genesis_state> block_log::extract_genesis_state( const fc::path& data_dir ) {
return detail::block_log_impl::extract_chain_context<genesis_state>(data_dir, [](std::fstream& block_stream, uint32_t version, uint32_t first_block_num ) -> fc::optional<genesis_state> {
std::optional<genesis_state> block_log::extract_genesis_state( const fc::path& data_dir ) {
return detail::block_log_impl::extract_chain_context<genesis_state>(data_dir, [](std::fstream& block_stream, uint32_t version, uint32_t first_block_num ) -> std::optional<genesis_state> {
if (contains_genesis_state(version, first_block_num)) {
genesis_state gs;
fc::raw::unpack(block_stream, gs);
return gs;
}

// current versions only have a genesis state if they start with block number 1
return fc::optional<genesis_state>();
return std::optional<genesis_state>();
});
}

chain_id_type block_log::extract_chain_id( const fc::path& data_dir ) {
return *(detail::block_log_impl::extract_chain_context<chain_id_type>(data_dir, [](std::fstream& block_stream, uint32_t version, uint32_t first_block_num ) -> fc::optional<chain_id_type> {
return *(detail::block_log_impl::extract_chain_context<chain_id_type>(data_dir, [](std::fstream& block_stream, uint32_t version, uint32_t first_block_num ) -> std::optional<chain_id_type> {
// supported versions either contain a genesis state, or else the chain id only
if (contains_genesis_state(version, first_block_num)) {
genesis_state gs;
Expand Down
Loading

0 comments on commit 1fe4aef

Please sign in to comment.