message: Add code to validate or skip or validate or set the key type for a scope-account-table entry.
diff: @@ -259,4 +259,58 @@ const bytes& apply_context::get_packed_transaction() {
  return trx_meta.packed_trx;
  }
  +
  +const char* to_string(contracts::table_key_type key_type) {
  + switch(key_type) {
  + case contracts::type_unassigned:
  + return "unassigned";
  + case contracts::type_i64:
  + return "i64";
  + case contracts::type_str:
  + return "str";
  + case contracts::type_i128i128:
  + return "i128i128";
  + case contracts::type_i64i64i64:
  + return "i64i64i64";
  + default:
  + return "<unkown table_key_type>";
  + }
  +}
  +
  +void apply_context::validate_table_key( const table_id_object& t_id, contracts::table_key_type key_type ) {
  + FC_ASSERT( t_id.key_type == contracts::table_key_type::type_unassigned || key_type == t_id.key_type,
  + "Table entry for ${scope}-${code}-${table} uses key type ${act_type} should have had type of ${exp_type}",
  + ("scope",t_id.scope)("code",t_id.code)("table",t_id.table)("act_type",to_string(t_id.key_type))("exp_type", to_string(key_type)) );
  +}
  +
  +void apply_context::validate_or_add_table_key( const table_id_object& t_id, contracts::table_key_type key_type ) {
  + if (t_id.key_type == contracts::table_key_type::type_unassigned)
  + mutable_db.modify( t_id, [&key_type]( auto& o) {
  + o.key_type = key_type;
  + });
  + else
  + FC_ASSERT( key_type == t_id.key_type,
  + "Table entry for ${scope}-${code}-${table} uses key type ${act_type} should have had type of ${exp_type}",
  + ("scope",t_id.scope)("code",t_id.code)("table",t_id.table)("act_type",to_string(t_id.key_type))("exp_type", to_string(key_type)) );
  +}
  +
  +template<>
  +contracts::table_key_type apply_context::get_key_type<contracts::key_value_object>() {
  + return contracts::table_key_type::type_i64;
  +}
  +
  +template<>
  +contracts::table_key_type apply_context::get_key_type<contracts::keystr_value_object>() {
  + return contracts::table_key_type::type_str;
  +}
  +
  +template<>
  +contracts::table_key_type apply_context::get_key_type<contracts::key128x128_value_object>() {
  + return contracts::table_key_type::type_i128i128;
  +}
  +
  +template<>
  +contracts::table_key_type apply_context::get_key_type<contracts::key64x64x64_value_object>() {
  + return contracts::table_key_type::type_i64i64i64;
  +}
  } } /// eosio::chain
  