diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index f6895ce0ca0dd1cbd1e2601216fe337897a4e4fe..00b1d1fd96a7b0e8908e8c6a04a286ef49d6b688 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -15,6 +15,7 @@ add_library( eosio_chain genesis_state.cpp transaction_context.cpp eosio_contract.cpp + eosio_contract_abi.cpp # chain_config.cpp # block_trace.cpp diff --git a/libraries/chain/apply_context.cpp b/libraries/chain/apply_context.cpp index a8ccf10dadaaf61b0d7edef156e3b58aa0ef2fc8..889eda67db55d266799d43ccecbb04c7b7db4c63 100644 --- a/libraries/chain/apply_context.cpp +++ b/libraries/chain/apply_context.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include using boost::container::flat_set; @@ -36,11 +37,11 @@ action_trace apply_context::exec_one() action_receipt r; r.receiver = receiver; r.act_digest = digest_type::hash(act); - r.global_sequence = control.next_global_sequence(); - r.recv_sequence = control.next_recv_sequence( receiver ); + r.global_sequence = next_global_sequence(); + r.recv_sequence = next_recv_sequence( receiver ); for( const auto& auth : act.authorization ) { - r.auth_sequence[auth.actor] = control.next_auth_sequence( auth.actor ); + r.auth_sequence[auth.actor] = next_auth_sequence( auth.actor ); } action_trace t(r); @@ -313,7 +314,7 @@ const table_id_object& apply_context::find_or_create_table( name code, name scop update_db_usage(payer, config::billable_size_v); - return mutable_db.create([&](table_id_object &t_id){ + return db.create([&](table_id_object &t_id){ t_id.code = code; t_id.scope = scope; t_id.table = table; @@ -323,7 +324,7 @@ const table_id_object& apply_context::find_or_create_table( name code, name scop void apply_context::remove_table( const table_id_object& tid ) { update_db_usage(tid.payer, - config::billable_size_v); - mutable_db.remove(tid); + db.remove(tid); } vector apply_context::get_active_producers() const { @@ -431,7 +432,7 @@ int apply_context::db_store_i64( uint64_t code, uint64_t scope, uint64_t table, FC_ASSERT( payer != account_name(), "must specify a valid account to pay for new record" ); - const auto& obj = mutable_db.create( [&]( auto& o ) { + const auto& obj = db.create( [&]( auto& o ) { o.t_id = tableid; o.primary_key = id; o.value.resize( buffer_size ); @@ -439,7 +440,7 @@ int apply_context::db_store_i64( uint64_t code, uint64_t scope, uint64_t table, memcpy( o.value.data(), buffer, buffer_size ); }); - mutable_db.modify( tab, [&]( auto& t ) { + db.modify( tab, [&]( auto& t ) { ++t.count; }); @@ -474,7 +475,7 @@ void apply_context::db_update_i64( int iterator, account_name payer, const char* update_db_usage( obj.payer, new_size - old_size); } - mutable_db.modify( obj, [&]( auto& o ) { + db.modify( obj, [&]( auto& o ) { o.value.resize( buffer_size ); memcpy( o.value.data(), buffer, buffer_size ); o.payer = payer; @@ -491,10 +492,10 @@ void apply_context::db_remove_i64( int iterator ) { update_db_usage( obj.payer, -(obj.value.size() + config::billable_size_v) ); - mutable_db.modify( table_obj, [&]( auto& t ) { + db.modify( table_obj, [&]( auto& t ) { --t.count; }); - mutable_db.remove( obj ); + db.remove( obj ); if (table_obj.count == 0) { remove_table(table_obj); @@ -611,4 +612,22 @@ int apply_context::db_end_i64( uint64_t code, uint64_t scope, uint64_t table ) { return keyval_cache.cache_table( *tab ); } + + +uint64_t apply_context::next_global_sequence() { + const auto& p = control.get_dynamic_global_properties(); + db.modify( p, [&]( auto& dgp ) { + ++dgp.global_action_sequence; + }); + return p.global_action_sequence; +} + +uint64_t apply_context::next_recv_sequence( account_name receiver ) { + return 0; +} +uint64_t apply_context::next_auth_sequence( account_name actor ) { + return 0; +} + + } } /// eosio::chain diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index c38b3aeccdfb3cd0ccd04411fcce14ece4309d32..2e9b3efa025b4f26fb88274cc31aa60c0d41d705 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -25,7 +25,6 @@ namespace eosio { namespace chain { using resource_limits::resource_limits_manager; -abi_def eos_contract_abi(const abi_def& eosio_system_abi); struct pending_state { pending_state( database::session&& s ) @@ -217,7 +216,7 @@ struct controller_impl { a.privileged = true; if( name == config::system_account_name ) { - a.set_abi(eos_contract_abi(abi_def())); + a.set_abi(eosio_contract_abi(abi_def())); } }); const auto& owner = db.create([&](permission_object& p) { @@ -776,20 +775,6 @@ time_point controller::head_block_time()const { return my->head->header.timestamp; } -uint64_t controller::next_global_sequence() { - const auto& p = get_dynamic_global_properties(); - my->db.modify( p, [&]( auto& dgp ) { - ++dgp.global_action_sequence; - }); - return p.global_action_sequence; -} - -uint64_t controller::next_recv_sequence( account_name receiver ) { - return 0; -} -uint64_t controller::next_auth_sequence( account_name actor ) { - return 0; -} void controller::record_transaction( const transaction_metadata_ptr& trx ) { my->record_transaction( trx ); } @@ -853,286 +838,6 @@ void controller::pop_block() { } -abi_def eos_contract_abi(const abi_def& eosio_system_abi) -{ - abi_def eos_abi(eosio_system_abi); - eos_abi.types.push_back( type_def{"account_name","name"} ); - eos_abi.types.push_back( type_def{"table_name","name"} ); - eos_abi.types.push_back( type_def{"share_type","int64"} ); - eos_abi.types.push_back( type_def{"onerror","bytes"} ); - eos_abi.types.push_back( type_def{"context_free_type","bytes"} ); - eos_abi.types.push_back( type_def{"weight_type","uint16"} ); - eos_abi.types.push_back( type_def{"fields","field[]"} ); - eos_abi.types.push_back( type_def{"time_point_sec","time"} ); - - // TODO add ricardian contracts - eos_abi.actions.push_back( action_def{name("setcode"), "setcode",""} ); - eos_abi.actions.push_back( action_def{name("setabi"), "setabi",""} ); - eos_abi.actions.push_back( action_def{name("linkauth"), "linkauth",""} ); - eos_abi.actions.push_back( action_def{name("unlinkauth"), "unlinkauth",""} ); - eos_abi.actions.push_back( action_def{name("updateauth"), "updateauth",""} ); - eos_abi.actions.push_back( action_def{name("deleteauth"), "deleteauth",""} ); - eos_abi.actions.push_back( action_def{name("newaccount"), "newaccount",""} ); - eos_abi.actions.push_back( action_def{name("postrecovery"), "postrecovery",""} ); - eos_abi.actions.push_back( action_def{name("passrecovery"), "passrecovery",""} ); - eos_abi.actions.push_back( action_def{name("vetorecovery"), "vetorecovery",""} ); - eos_abi.actions.push_back( action_def{name("onerror"), "onerror",""} ); - eos_abi.actions.push_back( action_def{name("onblock"), "onblock",""} ); - eos_abi.actions.push_back( action_def{name("canceldelay"), "canceldelay",""} ); - - // TODO add any ricardian_clauses - // - // ACTION PAYLOADS - - - eos_abi.structs.emplace_back( struct_def { - "setcode", "", { - {"account", "account_name"}, - {"vmtype", "uint8"}, - {"vmversion", "uint8"}, - {"code", "bytes"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "setabi", "", { - {"account", "account_name"}, - {"abi", "abi_def"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "updateauth", "", { - {"account", "account_name"}, - {"permission", "permission_name"}, - {"parent", "permission_name"}, - {"data", "authority"}, - {"delay", "uint32"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "linkauth", "", { - {"account", "account_name"}, - {"code", "account_name"}, - {"type", "action_name"}, - {"requirement", "permission_name"}, - } - }); - - eos_abi.structs.emplace_back( struct_def { - "unlinkauth", "", { - {"account", "account_name"}, - {"code", "account_name"}, - {"type", "action_name"}, - } - }); - - eos_abi.structs.emplace_back( struct_def { - "deleteauth", "", { - {"account", "account_name"}, - {"permission", "permission_name"}, - } - }); - - eos_abi.structs.emplace_back( struct_def { - "newaccount", "", { - {"creator", "account_name"}, - {"name", "account_name"}, - {"owner", "authority"}, - {"active", "authority"}, - {"recovery", "authority"}, - } - }); - - eos_abi.structs.emplace_back( struct_def { - "postrecovery", "", { - {"account", "account_name"}, - {"data", "authority"}, - {"memo", "string"}, - } - }); - - eos_abi.structs.emplace_back( struct_def { - "passrecovery", "", { - {"account", "account_name"}, - } - }); - - eos_abi.structs.emplace_back( struct_def { - "vetorecovery", "", { - {"account", "account_name"}, - } - }); - - eos_abi.structs.emplace_back( struct_def { - "canceldelay", "", { - {"trx_id", "transaction_id_type"}, - } - }); - - // DATABASE RECORDS - - eos_abi.structs.emplace_back( struct_def { - "pending_recovery", "", { - {"account", "name"}, - {"request_id", "uint128"}, - {"update", "updateauth"}, - {"memo", "string"} - } - }); - - eos_abi.tables.emplace_back( table_def { - "recovery", "i64", { - "account", - }, { - "name" - }, - "pending_recovery" - }); - - // abi_def fields - - eos_abi.structs.emplace_back( struct_def { - "field", "", { - {"name", "field_name"}, - {"type", "type_name"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "struct_def", "", { - {"name", "type_name"}, - {"base", "type_name"}, - {"fields", "fields"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "permission_level", "", { - {"actor", "account_name"}, - {"permission", "permission_name"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "action", "", { - {"account", "account_name"}, - {"name", "action_name"}, - {"authorization", "permission_level[]"}, - {"data", "bytes"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "permission_level_weight", "", { - {"permission", "permission_level"}, - {"weight", "weight_type"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "transaction_header", "", { - {"expiration", "time_point_sec"}, - {"region", "uint16"}, - {"ref_block_num", "uint16"}, - {"ref_block_prefix", "uint32"}, - {"max_net_usage_words", "varuint32"}, - {"max_kcpu_usage", "varuint32"}, - {"delay_sec", "varuint32"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "transaction", "transaction_header", { - {"context_free_actions", "action[]"}, - {"actions", "action[]"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "signed_transaction", "transaction", { - {"signatures", "signature[]"}, - {"context_free_data", "bytes[]"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "key_weight", "", { - {"key", "public_key"}, - {"weight", "weight_type"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "authority", "", { - {"threshold", "uint32"}, - {"keys", "key_weight[]"}, - {"accounts", "permission_level_weight[]"} - } - }); - eos_abi.structs.emplace_back( struct_def { - "clause_pair", "", { - {"id", "string"}, - {"body", "string"} - } - }); - eos_abi.structs.emplace_back( struct_def { - "type_def", "", { - {"new_type_name", "type_name"}, - {"type", "type_name"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "action_def", "", { - {"name", "action_name"}, - {"type", "type_name"}, - {"ricardian_contract", "string"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "table_def", "", { - {"name", "table_name"}, - {"index_type", "type_name"}, - {"key_names", "field_name[]"}, - {"key_types", "type_name[]"}, - {"type", "type_name"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "abi_def", "", { - {"types", "type_def[]"}, - {"structs", "struct_def[]"}, - {"actions", "action_def[]"}, - {"tables", "table_def[]"}, - {"ricardian_clauses", "clause_pair[]"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "block_header", "", { - {"previous", "checksum256"}, - {"timestamp", "uint32"}, - {"transaction_mroot", "checksum256"}, - {"action_mroot", "checksum256"}, - {"block_mroot", "checksum256"}, - {"producer", "account_name"}, - {"schedule_version", "uint32"}, - {"new_producers", "producer_schedule?"} - } - }); - - eos_abi.structs.emplace_back( struct_def { - "onblock", "", { - {"header", "block_header"} - } - }); - - return eos_abi; -} /** * @param actions - the actions to check authorization across * @param provided_keys - the set of public keys which have authorized the transaction diff --git a/libraries/chain/eosio_contract.cpp b/libraries/chain/eosio_contract.cpp index 410389226415766db9039f93f51da89cec12be0e..c4fd3f23c7bee4a0e786ab7382fd47eb70691741 100644 --- a/libraries/chain/eosio_contract.cpp +++ b/libraries/chain/eosio_contract.cpp @@ -26,7 +26,6 @@ namespace eosio { namespace chain { -abi_def eos_contract_abi(const abi_def& eosio_system_abi); uint128_t transaction_id_to_sender_id( const transaction_id_type& tid ) { fc::uint128_t _id(tid._hash[3], tid._hash[2]); @@ -54,7 +53,7 @@ void apply_eosio_newaccount(apply_context& context) { EOS_ASSERT( validate(create.active), action_validate_exception, "Invalid active authority"); EOS_ASSERT( validate(create.recovery), action_validate_exception, "Invalid recovery authority"); - auto& db = context.mutable_db; + auto& db = context.db; auto name_str = name(create.name).to_string(); @@ -111,7 +110,7 @@ void apply_eosio_newaccount(apply_context& context) { } FC_CAPTURE_AND_RETHROW( (create) ) } void apply_eosio_setcode(apply_context& context) { - auto& db = context.mutable_db; + auto& db = context.db; auto& resources = context.mutable_controller.get_mutable_resource_limits_manager(); auto act = context.act.data_as(); context.require_authorization(act.account); @@ -154,7 +153,7 @@ void apply_eosio_setcode(apply_context& context) { } void apply_eosio_setabi(apply_context& context) { - auto& db = context.mutable_db; + auto& db = context.db; auto& resources = context.mutable_controller.get_mutable_resource_limits_manager(); auto act = context.act.data_as(); @@ -162,7 +161,7 @@ void apply_eosio_setabi(apply_context& context) { // if system account append native abi if ( act.account == eosio::chain::config::system_account_name ) { - act.abi = eos_contract_abi(act.abi); + act.abi = eosio_contract_abi(act.abi); } /// if an ABI is specified make sure it is well formed and doesn't /// reference any undefined types @@ -190,7 +189,7 @@ void apply_eosio_updateauth(apply_context& context) { auto& resources = context.mutable_controller.get_mutable_resource_limits_manager(); // context.require_write_lock( config::eosio_auth_scope ); - auto& db = context.mutable_db; + auto& db = context.db; auto update = context.act.data_as(); EOS_ASSERT(!update.permission.empty(), action_validate_exception, "Cannot create authority with empty name"); @@ -294,7 +293,7 @@ void apply_eosio_deleteauth(apply_context& context) { EOS_ASSERT(remove.permission != config::active_name, action_validate_exception, "Cannot delete active authority"); EOS_ASSERT(remove.permission != config::owner_name, action_validate_exception, "Cannot delete owner authority"); - auto& db = context.mutable_db; + auto& db = context.db; context.require_authorization(remove.account); // TODO/QUESTION: // Inconsistency between permissions that can be satisfied to create/modify (via updateauth) a permission and the @@ -331,7 +330,7 @@ void apply_eosio_linkauth(apply_context& context) { context.require_authorization(requirement.account); - auto& db = context.mutable_db; + auto& db = context.db; const auto *account = db.find(requirement.account); EOS_ASSERT(account != nullptr, account_query_exception, "Failed to retrieve account: ${account}", ("account", requirement.account)); // Redundant? @@ -371,7 +370,7 @@ void apply_eosio_linkauth(apply_context& context) { void apply_eosio_unlinkauth(apply_context& context) { auto& resources = context.mutable_controller.get_mutable_resource_limits_manager(); - auto& db = context.mutable_db; + auto& db = context.db; auto unlink = context.act.data_as(); context.require_authorization(unlink.account); @@ -396,7 +395,7 @@ void apply_eosio_onerror(apply_context& context) { static const abi_serializer& get_abi_serializer() { static optional _abi_serializer; if (!_abi_serializer) { - _abi_serializer.emplace(eos_contract_abi(abi_def())); + _abi_serializer.emplace(eosio_contract_abi(abi_def())); } return *_abi_serializer; diff --git a/libraries/chain/eosio_contract_abi.cpp b/libraries/chain/eosio_contract_abi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1d899a76473d48d54490868fb83262eb7832bcb --- /dev/null +++ b/libraries/chain/eosio_contract_abi.cpp @@ -0,0 +1,285 @@ +#include + +namespace eosio { namespace chain { + +abi_def eosio_contract_abi(const abi_def& eosio_system_abi) +{ + abi_def eos_abi(eosio_system_abi); + eos_abi.types.push_back( type_def{"account_name","name"} ); + eos_abi.types.push_back( type_def{"table_name","name"} ); + eos_abi.types.push_back( type_def{"share_type","int64"} ); + eos_abi.types.push_back( type_def{"onerror","bytes"} ); + eos_abi.types.push_back( type_def{"context_free_type","bytes"} ); + eos_abi.types.push_back( type_def{"weight_type","uint16"} ); + eos_abi.types.push_back( type_def{"fields","field[]"} ); + eos_abi.types.push_back( type_def{"time_point_sec","time"} ); + + // TODO add ricardian contracts + eos_abi.actions.push_back( action_def{name("setcode"), "setcode",""} ); + eos_abi.actions.push_back( action_def{name("setabi"), "setabi",""} ); + eos_abi.actions.push_back( action_def{name("linkauth"), "linkauth",""} ); + eos_abi.actions.push_back( action_def{name("unlinkauth"), "unlinkauth",""} ); + eos_abi.actions.push_back( action_def{name("updateauth"), "updateauth",""} ); + eos_abi.actions.push_back( action_def{name("deleteauth"), "deleteauth",""} ); + eos_abi.actions.push_back( action_def{name("newaccount"), "newaccount",""} ); + eos_abi.actions.push_back( action_def{name("postrecovery"), "postrecovery",""} ); + eos_abi.actions.push_back( action_def{name("passrecovery"), "passrecovery",""} ); + eos_abi.actions.push_back( action_def{name("vetorecovery"), "vetorecovery",""} ); + eos_abi.actions.push_back( action_def{name("onerror"), "onerror",""} ); + eos_abi.actions.push_back( action_def{name("onblock"), "onblock",""} ); + eos_abi.actions.push_back( action_def{name("canceldelay"), "canceldelay",""} ); + + // TODO add any ricardian_clauses + // + // ACTION PAYLOADS + + + eos_abi.structs.emplace_back( struct_def { + "setcode", "", { + {"account", "account_name"}, + {"vmtype", "uint8"}, + {"vmversion", "uint8"}, + {"code", "bytes"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "setabi", "", { + {"account", "account_name"}, + {"abi", "abi_def"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "updateauth", "", { + {"account", "account_name"}, + {"permission", "permission_name"}, + {"parent", "permission_name"}, + {"data", "authority"}, + {"delay", "uint32"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "linkauth", "", { + {"account", "account_name"}, + {"code", "account_name"}, + {"type", "action_name"}, + {"requirement", "permission_name"}, + } + }); + + eos_abi.structs.emplace_back( struct_def { + "unlinkauth", "", { + {"account", "account_name"}, + {"code", "account_name"}, + {"type", "action_name"}, + } + }); + + eos_abi.structs.emplace_back( struct_def { + "deleteauth", "", { + {"account", "account_name"}, + {"permission", "permission_name"}, + } + }); + + eos_abi.structs.emplace_back( struct_def { + "newaccount", "", { + {"creator", "account_name"}, + {"name", "account_name"}, + {"owner", "authority"}, + {"active", "authority"}, + {"recovery", "authority"}, + } + }); + + eos_abi.structs.emplace_back( struct_def { + "postrecovery", "", { + {"account", "account_name"}, + {"data", "authority"}, + {"memo", "string"}, + } + }); + + eos_abi.structs.emplace_back( struct_def { + "passrecovery", "", { + {"account", "account_name"}, + } + }); + + eos_abi.structs.emplace_back( struct_def { + "vetorecovery", "", { + {"account", "account_name"}, + } + }); + + eos_abi.structs.emplace_back( struct_def { + "canceldelay", "", { + {"trx_id", "transaction_id_type"}, + } + }); + + // DATABASE RECORDS + + eos_abi.structs.emplace_back( struct_def { + "pending_recovery", "", { + {"account", "name"}, + {"request_id", "uint128"}, + {"update", "updateauth"}, + {"memo", "string"} + } + }); + + eos_abi.tables.emplace_back( table_def { + "recovery", "i64", { + "account", + }, { + "name" + }, + "pending_recovery" + }); + + // abi_def fields + + eos_abi.structs.emplace_back( struct_def { + "field", "", { + {"name", "field_name"}, + {"type", "type_name"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "struct_def", "", { + {"name", "type_name"}, + {"base", "type_name"}, + {"fields", "fields"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "permission_level", "", { + {"actor", "account_name"}, + {"permission", "permission_name"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "action", "", { + {"account", "account_name"}, + {"name", "action_name"}, + {"authorization", "permission_level[]"}, + {"data", "bytes"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "permission_level_weight", "", { + {"permission", "permission_level"}, + {"weight", "weight_type"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "transaction_header", "", { + {"expiration", "time_point_sec"}, + {"region", "uint16"}, + {"ref_block_num", "uint16"}, + {"ref_block_prefix", "uint32"}, + {"max_net_usage_words", "varuint32"}, + {"max_kcpu_usage", "varuint32"}, + {"delay_sec", "varuint32"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "transaction", "transaction_header", { + {"context_free_actions", "action[]"}, + {"actions", "action[]"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "signed_transaction", "transaction", { + {"signatures", "signature[]"}, + {"context_free_data", "bytes[]"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "key_weight", "", { + {"key", "public_key"}, + {"weight", "weight_type"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "authority", "", { + {"threshold", "uint32"}, + {"keys", "key_weight[]"}, + {"accounts", "permission_level_weight[]"} + } + }); + eos_abi.structs.emplace_back( struct_def { + "clause_pair", "", { + {"id", "string"}, + {"body", "string"} + } + }); + eos_abi.structs.emplace_back( struct_def { + "type_def", "", { + {"new_type_name", "type_name"}, + {"type", "type_name"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "action_def", "", { + {"name", "action_name"}, + {"type", "type_name"}, + {"ricardian_contract", "string"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "table_def", "", { + {"name", "table_name"}, + {"index_type", "type_name"}, + {"key_names", "field_name[]"}, + {"key_types", "type_name[]"}, + {"type", "type_name"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "abi_def", "", { + {"types", "type_def[]"}, + {"structs", "struct_def[]"}, + {"actions", "action_def[]"}, + {"tables", "table_def[]"}, + {"ricardian_clauses", "clause_pair[]"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "block_header", "", { + {"previous", "checksum256"}, + {"timestamp", "uint32"}, + {"transaction_mroot", "checksum256"}, + {"action_mroot", "checksum256"}, + {"block_mroot", "checksum256"}, + {"producer", "account_name"}, + {"schedule_version", "uint32"}, + {"new_producers", "producer_schedule?"} + } + }); + + eos_abi.structs.emplace_back( struct_def { + "onblock", "", { + {"header", "block_header"} + } + }); + + return eos_abi; +} +} } /// eosio::chain diff --git a/libraries/chain/include/eosio/chain/apply_context.hpp b/libraries/chain/include/eosio/chain/apply_context.hpp index 25e0c4167e0bb9eb62cdfb43982ba5cae218d334..7e485f1150a3ed135b3cad17d5e222120958d8ef 100644 --- a/libraries/chain/include/eosio/chain/apply_context.hpp +++ b/libraries/chain/include/eosio/chain/apply_context.hpp @@ -185,14 +185,14 @@ class apply_context { const auto& tab = context.find_or_create_table( context.receiver, scope, table, payer ); - const auto& obj = context.mutable_db.create( [&]( auto& o ){ + const auto& obj = context.db.create( [&]( auto& o ){ o.t_id = tab.id; o.primary_key = id; secondary_key_helper_t::set(o.secondary_key, value); o.payer = payer; }); - context.mutable_db.modify( tab, [&]( auto& t ) { + context.db.modify( tab, [&]( auto& t ) { ++t.count; }); @@ -211,10 +211,10 @@ class apply_context { // context.require_write_lock( table_obj.scope ); - context.mutable_db.modify( table_obj, [&]( auto& t ) { + context.db.modify( table_obj, [&]( auto& t ) { --t.count; }); - context.mutable_db.remove( obj ); + context.db.remove( obj ); if (table_obj.count == 0) { context.remove_table(table_obj); @@ -240,7 +240,7 @@ class apply_context { context.update_db_usage( payer, +(billing_size) ); } - context.mutable_db.modify( obj, [&]( auto& o ) { + context.db.modify( obj, [&]( auto& o ) { secondary_key_helper_t::set(o.secondary_key, secondary); o.payer = payer; }); @@ -457,7 +457,6 @@ class apply_context { db(con.db()), act(a), mutable_controller(con), - mutable_db(con.db()), used_authorizations(act.authorization.size(), false), trx_meta(trx_meta), idx64(*this), @@ -512,8 +511,8 @@ class apply_context { const bytes& get_packed_transaction(); - controller& control; - const chainbase::database& db; ///< database where state is stored + controller& control; + chainbase::database& db; ///< database where state is stored const action& act; ///< message being applied account_name receiver; ///< the code that is currently running bool privileged = false; @@ -521,7 +520,6 @@ class apply_context { bool used_context_free_api = false; controller& mutable_controller; - chainbase::database& mutable_db; ///< Parallel to act.authorization; tracks which permissions have been used while processing the message @@ -588,6 +586,12 @@ class apply_context { uint64_t cpu_usage; uint64_t total_cpu_usage; + + + uint64_t next_global_sequence(); + uint64_t next_recv_sequence( account_name receiver ); + uint64_t next_auth_sequence( account_name actor ); + private: iterator_cache keyval_cache; diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index 267a99c2ae0eaedcef94c54c939ac7ba6fbbf5d9..6b030266d5195677023d42225781313c7e9d557c 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -90,9 +90,6 @@ namespace eosio { namespace chain { block_state_ptr head_block_state()const; block_state_ptr pending_block_state()const; - uint64_t next_global_sequence(); - uint64_t next_recv_sequence( account_name receiver ); - uint64_t next_auth_sequence( account_name actor ); void record_transaction( const transaction_metadata_ptr& trx ); const account_object& get_account( account_name n )const; diff --git a/libraries/chain/include/eosio/chain/eosio_contract.hpp b/libraries/chain/include/eosio/chain/eosio_contract.hpp index e6d83d54d12ad6b8f910b70c007b368f2e0d3421..6f4230813cc1bc0863f0e1353df91d57dcd19eca 100644 --- a/libraries/chain/include/eosio/chain/eosio_contract.hpp +++ b/libraries/chain/include/eosio/chain/eosio_contract.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include namespace eosio { namespace chain { @@ -31,5 +32,7 @@ namespace eosio { namespace chain { void apply_eosio_canceldelay(apply_context&); ///@} end action handlers + + abi_def eosio_contract_abi(const abi_def& eosio_system_abi); } } /// namespace eosio::chain diff --git a/libraries/chain/wasm_interface.cpp b/libraries/chain/wasm_interface.cpp index 9b68754db4032aba0de774907f0ad4901a4209ad..ea3f9d5e0b5e246672ef13e77c5c58b9eafadd07 100644 --- a/libraries/chain/wasm_interface.cpp +++ b/libraries/chain/wasm_interface.cpp @@ -167,7 +167,7 @@ class privileged_api : public context_aware_api { datastream ds( packed_blockchain_parameters, datalen ); chain::chain_config cfg; fc::raw::unpack(ds, cfg); - context.mutable_db.modify( context.control.get_global_properties(), + context.db.modify( context.control.get_global_properties(), [&]( auto& gprops ) { gprops.configuration = cfg; }); @@ -179,7 +179,7 @@ class privileged_api : public context_aware_api { void set_privileged( account_name n, bool is_priv ) { const auto& a = context.db.get( n ); - context.mutable_db.modify( a, [&]( auto& ma ){ + context.db.modify( a, [&]( auto& ma ){ ma.privileged = is_priv; }); }