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

Replace N macro with operator ""_n - develop #9447

Merged
merged 7 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void apply_context::exec_one()

if( ( receiver_account->code_hash != digest_type() ) &&
( !( act->account == config::system_account_name
&& act->name == N( setcode )
&& act->name == "setcode"_n
&& receiver == config::system_account_name )
|| control.is_builtin_activated( builtin_protocol_feature_t::forward_setcode )
)
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,7 @@ struct controller_impl {
{
action on_block_act;
on_block_act.account = config::system_account_name;
on_block_act.name = N(onblock);
on_block_act.name = "onblock"_n;
on_block_act.authorization = vector<permission_level>{{config::system_account_name, config::active_name}};
on_block_act.data = fc::raw::pack(self.head_block_header());

Expand Down
22 changes: 11 additions & 11 deletions libraries/chain/include/eosio/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ const static auto default_state_size = 1*1024*1024*1024ll;
const static auto default_state_guard_size = 128*1024*1024ll;


const static name system_account_name { N(eosio) };
const static name null_account_name { N(eosio.null) };
const static name producers_account_name { N(eosio.prods) };
const static name system_account_name { "eosio"_n };
const static name null_account_name { "eosio.null"_n };
const static name producers_account_name { "eosio.prods"_n };

// Active permission of producers account requires greater than 2/3 of the producers to authorize
const static name majority_producers_permission_name { N(prod.major) }; // greater than 1/2 of producers needed to authorize
const static name minority_producers_permission_name { N(prod.minor) }; // greater than 1/3 of producers needed to authorize0
const static name majority_producers_permission_name { "prod.major"_n }; // greater than 1/2 of producers needed to authorize
const static name minority_producers_permission_name { "prod.minor"_n }; // greater than 1/3 of producers needed to authorize0

const static name eosio_auth_scope { N(eosio.auth) };
const static name eosio_all_scope { N(eosio.all) };
const static name eosio_auth_scope { "eosio.auth"_n };
const static name eosio_all_scope { "eosio.all"_n };

const static name active_name { N(active) };
const static name owner_name { N(owner) };
const static name eosio_any_name { N(eosio.any) };
const static name eosio_code_name { N(eosio.code) };
const static name active_name { "active"_n };
const static name owner_name { "owner"_n };
const static name eosio_any_name { "eosio.any"_n };
const static name eosio_code_name { "eosio.code"_n };

const static int block_interval_ms = 500;
const static int block_interval_us = block_interval_ms*1000;
Expand Down
18 changes: 9 additions & 9 deletions libraries/chain/include/eosio/chain/contract_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct newaccount {
}

static action_name get_name() {
return N(newaccount);
return "newaccount"_n;
}
};

Expand All @@ -33,7 +33,7 @@ struct setcode {
}

static action_name get_name() {
return N(setcode);
return "setcode"_n;
}
};

Expand All @@ -46,7 +46,7 @@ struct setabi {
}

static action_name get_name() {
return N(setabi);
return "setabi"_n;
}
};

Expand All @@ -62,7 +62,7 @@ struct updateauth {
}

static action_name get_name() {
return N(updateauth);
return "updateauth"_n;
}
};

Expand All @@ -80,7 +80,7 @@ struct deleteauth {
}

static action_name get_name() {
return N(deleteauth);
return "deleteauth"_n;
}
};

Expand All @@ -100,7 +100,7 @@ struct linkauth {
}

static action_name get_name() {
return N(linkauth);
return "linkauth"_n;
}
};

Expand All @@ -119,7 +119,7 @@ struct unlinkauth {
}

static action_name get_name() {
return N(unlinkauth);
return "unlinkauth"_n;
}
};

Expand All @@ -132,7 +132,7 @@ struct canceldelay {
}

static action_name get_name() {
return N(canceldelay);
return "canceldelay"_n;
}
};

Expand All @@ -148,7 +148,7 @@ struct onerror {
}

static action_name get_name() {
return N(onerror);
return "onerror"_n;
}
};

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/kv_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace eosio { namespace chain {

class apply_context;

inline constexpr name kvram_id = N(eosio.kvram);
inline constexpr name kvram_id = "eosio.kvram"_n;

enum class kv_it_stat {
iterator_ok = 0, // Iterator is positioned at a key-value pair
Expand Down
14 changes: 9 additions & 5 deletions libraries/chain/include/eosio/chain/name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace fc {
} // fc

namespace eosio::chain {
static constexpr uint64_t char_to_symbol( char c ) {
constexpr uint64_t char_to_symbol( char c ) {
if( c >= 'a' && c <= 'z' )
return (c - 'a') + 6;
if( c >= '1' && c <= '5' )
Expand All @@ -24,15 +24,15 @@ namespace eosio::chain {
return 0;
else
FC_THROW_EXCEPTION(name_type_exception, "Name contains invalid character: (${c}) ", ("c", std::string(1, c)));

//unreachable
return 0;
}

// true if std::string can be converted to name
bool is_string_valid_name(std::string_view str);

static constexpr uint64_t string_to_uint64_t( std::string_view str ) {
constexpr uint64_t string_to_uint64_t( std::string_view str ) {
EOS_ASSERT(str.size() <= 13, name_type_exception, "Name is longer than 13 characters (${name}) ", ("name", std::string(str)));

uint64_t n = 0;
Expand Down Expand Up @@ -98,12 +98,16 @@ namespace eosio::chain {
// to its 5-bit slot starting with the highest slot for the first char.
// The 13th char, if str is long enough, is encoded into 4-bit chunk
// and placed in the lowest 4 bits. 64 = 12 * 5 + 4
static constexpr name string_to_name( std::string_view str )
constexpr name string_to_name( std::string_view str )
{
return name( string_to_uint64_t( str ) );
}

#define N(X) eosio::chain::string_to_name(#X)
inline namespace literals {
constexpr name operator""_n(const char* str, std::size_t size) {
return string_to_name(std::string_view(str, size));
}
} // namespace literals

} // eosio::chain

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace eosio { namespace chain {
if (tt.action_traces.empty())
return false;
const auto& act = tt.action_traces[0].act;
if (act.account != eosio::chain::config::system_account_name || act.name != N(onblock) ||
if (act.account != eosio::chain::config::system_account_name || act.name != "onblock"_n ||
act.authorization.size() != 1)
return false;
const auto& auth = act.authorization[0];
Expand Down
10 changes: 8 additions & 2 deletions libraries/state_history/include/eosio/state_history/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ namespace bfs = boost::filesystem;
* payload
*/

inline uint64_t ship_magic(uint32_t version) { return N(ship).to_uint64_t() | version; }
inline bool is_ship(uint64_t magic) { return (magic & 0xffff'ffff'0000'0000) == N(ship).to_uint64_t(); }
inline uint64_t ship_magic(uint32_t version) {
using namespace eosio::chain::literals;
return "ship"_n.to_uint64_t() | version;
}
inline bool is_ship(uint64_t magic) {
using namespace eosio::chain::literals;
return (magic & 0xffff'ffff'0000'0000) == "ship"_n.to_uint64_t();
}
inline uint32_t get_ship_version(uint64_t magic) { return magic; }
inline bool is_ship_supported_version(uint64_t magic) { return get_ship_version(magic) <= 1; }
static const uint32_t ship_current_version = 1;
Expand Down
3 changes: 2 additions & 1 deletion libraries/state_history/transaction_trace_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ bool is_onblock(const transaction_trace_ptr& p) {
if (p->action_traces.size() != 1)
return false;
auto& act = p->action_traces[0].act;
if (act.account != eosio::chain::config::system_account_name || act.name != N(onblock) ||
using namespace eosio::chain::literals;
if (act.account != eosio::chain::config::system_account_name || act.name != "onblock"_n ||
act.authorization.size() != 1)
return false;
auto& auth = act.authorization[0];
Expand Down
8 changes: 4 additions & 4 deletions libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ namespace eosio { namespace testing {
const symbol& asset_symbol,
const account_name& account ) const {
const auto& db = control->db();
const auto* tbl = db.template find<table_id_object, by_code_scope_table>(boost::make_tuple(code, account, N(accounts)));
const auto* tbl = db.template find<table_id_object, by_code_scope_table>(boost::make_tuple(code, account, "accounts"_n));
share_type result = 0;

// the balance is implied to be 0 if either the table or row does not exist
Expand Down Expand Up @@ -1098,7 +1098,7 @@ namespace eosio { namespace testing {
schedule_variant.emplace_back(e.get_abi_variant());
}

return push_action( config::system_account_name, N(setprods), config::system_account_name,
return push_action( config::system_account_name, "setprods"_n, config::system_account_name,
fc::mutable_variant_object()("schedule", schedule_variant));

}
Expand All @@ -1115,7 +1115,7 @@ namespace eosio { namespace testing {
}, p.authority);
}

return push_action( config::system_account_name, N(setprods), config::system_account_name,
return push_action( config::system_account_name, "setprods"_n, config::system_account_name,
fc::mutable_variant_object()("schedule", legacy_keys));

}
Expand All @@ -1136,7 +1136,7 @@ namespace eosio { namespace testing {

void base_tester::preactivate_protocol_features(const vector<digest_type> feature_digests) {
for( const auto& feature_digest: feature_digests ) {
push_action( config::system_account_name, N(activate), config::system_account_name,
push_action( config::system_account_name, "activate"_n, config::system_account_name,
fc::mutable_variant_object()("feature_digest", feature_digest) );
}
}
Expand Down
36 changes: 18 additions & 18 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ vector<asset> read_only::get_currency_balance( const read_only::get_currency_bal
(void)get_table_type( abi, name("accounts") );

vector<asset> results;
walk_key_value_table(p.code, p.account, N(accounts), [&](const key_value_object& obj){
walk_key_value_table(p.code, p.account, "accounts"_n, [&](const key_value_object& obj){
EOS_ASSERT( obj.value.size() >= sizeof(asset), chain::asset_type_exception, "Invalid data on table");

asset cursor;
Expand Down Expand Up @@ -1991,7 +1991,7 @@ fc::variant read_only::get_currency_stats( const read_only::get_currency_stats_p

uint64_t scope = ( eosio::chain::string_to_symbol( 0, boost::algorithm::to_upper_copy(p.symbol).c_str() ) >> 8 );

walk_key_value_table(p.code, name(scope), N(stat), [&](const key_value_object& obj){
walk_key_value_table(p.code, name(scope), "stat"_n, [&](const key_value_object& obj){
EOS_ASSERT( obj.value.size() >= sizeof(read_only::get_currency_stats_result), chain::asset_type_exception, "Invalid data on table");

fc::datastream<const char *> ds(obj.value.data(), obj.value.size());
Expand All @@ -2009,24 +2009,24 @@ fc::variant read_only::get_currency_stats( const read_only::get_currency_stats_p
}

fc::variant get_global_row( const database& db, const abi_def& abi, const abi_serializer& abis, const fc::microseconds& abi_serializer_max_time_us, bool shorten_abi_errors ) {
const auto table_type = get_table_type(abi, N(global));
const auto table_type = get_table_type(abi, "global"_n);
EOS_ASSERT(table_type == read_only::KEYi64, chain::contract_table_query_exception, "Invalid table type ${type} for table global", ("type",table_type));

const auto* const table_id = db.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple(config::system_account_name, config::system_account_name, N(global)));
const auto* const table_id = db.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple(config::system_account_name, config::system_account_name, "global"_n));
EOS_ASSERT(table_id, chain::contract_table_query_exception, "Missing table global");

const auto& kv_index = db.get_index<key_value_index, by_scope_primary>();
const auto it = kv_index.find(boost::make_tuple(table_id->id, N(global).to_uint64_t()));
const auto it = kv_index.find(boost::make_tuple(table_id->id, "global"_n.to_uint64_t()));
EOS_ASSERT(it != kv_index.end(), chain::contract_table_query_exception, "Missing row in table global");

vector<char> data;
read_only::copy_inline_row(*it, data);
return abis.binary_to_variant(abis.get_table_type(N(global)), data, abi_serializer::create_yield_function( abi_serializer_max_time_us ), shorten_abi_errors );
return abis.binary_to_variant(abis.get_table_type("global"_n), data, abi_serializer::create_yield_function( abi_serializer_max_time_us ), shorten_abi_errors );
}

read_only::get_producers_result read_only::get_producers( const read_only::get_producers_params& p ) const try {
const abi_def abi = eosio::chain_apis::get_abi(db, config::system_account_name);
const auto table_type = get_table_type(abi, N(producers));
const auto table_type = get_table_type(abi, "producers"_n);
const abi_serializer abis{ abi, abi_serializer::create_yield_function( abi_serializer_max_time ) };
EOS_ASSERT(table_type == KEYi64, chain::contract_table_query_exception, "Invalid table type ${type} for table producers", ("type",table_type));

Expand All @@ -2035,9 +2035,9 @@ read_only::get_producers_result read_only::get_producers( const read_only::get_p

static const uint8_t secondary_index_num = 0;
const auto* const table_id = d.find<chain::table_id_object, chain::by_code_scope_table>(
boost::make_tuple(config::system_account_name, config::system_account_name, N(producers)));
boost::make_tuple(config::system_account_name, config::system_account_name, "producers"_n));
const auto* const secondary_table_id = d.find<chain::table_id_object, chain::by_code_scope_table>(
boost::make_tuple(config::system_account_name, config::system_account_name, name(N(producers).to_uint64_t() | secondary_index_num)));
boost::make_tuple(config::system_account_name, config::system_account_name, name("producers"_n.to_uint64_t() | secondary_index_num)));
EOS_ASSERT(table_id && secondary_table_id, chain::contract_table_query_exception, "Missing producers table");

const auto& kv_index = d.get_index<key_value_index, by_scope_primary>();
Expand Down Expand Up @@ -2066,7 +2066,7 @@ read_only::get_producers_result read_only::get_producers( const read_only::get_p
}
copy_inline_row(*kv_index.find(boost::make_tuple(table_id->id, it->primary_key)), data);
if (p.json)
result.rows.emplace_back( abis.binary_to_variant( abis.get_table_type(N(producers)), data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors ) );
result.rows.emplace_back( abis.binary_to_variant( abis.get_table_type("producers"_n), data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors ) );
else
result.rows.emplace_back(fc::variant(data));
}
Expand Down Expand Up @@ -2599,14 +2599,14 @@ read_only::get_account_results read_only::get_account( const get_account_params&
if( abi_serializer::to_abi(code_account.abi, abi) ) {
abi_serializer abis( abi, abi_serializer::create_yield_function( abi_serializer_max_time ) );

const auto token_code = N(eosio.token);
const auto token_code = "eosio.token"_n;

auto core_symbol = extract_core_symbol();

if (params.expected_core_symbol)
core_symbol = *(params.expected_core_symbol);

const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( token_code, params.account_name, N(accounts) ));
const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( token_code, params.account_name, "accounts"_n ));
if( t_id != nullptr ) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, core_symbol.to_symbol_code() ));
Expand All @@ -2621,7 +2621,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}

t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, N(userres) ));
t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, "userres"_n ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
Expand All @@ -2632,7 +2632,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}

t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, N(delband) ));
t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, "delband"_n ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
Expand All @@ -2643,7 +2643,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}

t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, N(refunds) ));
t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, "refunds"_n ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
Expand All @@ -2654,7 +2654,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}

t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, N(voters) ));
t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, "voters"_n ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
Expand All @@ -2665,7 +2665,7 @@ read_only::get_account_results read_only::get_account( const get_account_params&
}
}

t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, N(rexbal) ));
t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, "rexbal"_n ));
if (t_id != nullptr) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
Expand Down Expand Up @@ -2760,7 +2760,7 @@ chain::symbol read_only::extract_core_symbol()const {

// The following code makes assumptions about the contract deployed on eosio account (i.e. the system contract) and how it stores its data.
const auto& d = db.db();
const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( N(eosio), N(eosio), N(rammarket) ));
const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( "eosio"_n, "eosio"_n, "rammarket"_n ));
if( t_id != nullptr ) {
const auto &idx = d.get_index<key_value_index, by_scope_primary>();
auto it = idx.find(boost::make_tuple( t_id->id, eosio::chain::string_to_symbol_c(4,"RAMCORE") ));
Expand Down
Loading