diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 1c76bb228c51f25cfe9da1b07a985f1a2792aa90..76d7a5534c1c066c71a766c1977459d583fc6d3c 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -1,15 +1,13 @@ - file(GLOB HEADERS "include/eos/chain/*.hpp") -file(GLOB PROTOCOL_HEADERS "include/eos/chain/protocol/*.hpp") ## SORT .cpp by most likely to change / break compile add_library( eos_chain database.cpp fork_database.cpp - protocol/types.cpp - protocol/transaction.cpp - protocol/block.cpp + types.cpp + transaction.cpp + block.cpp genesis_state.cpp get_config.cpp @@ -36,4 +34,3 @@ INSTALL( TARGETS ARCHIVE DESTINATION lib ) INSTALL( FILES ${HEADERS} DESTINATION "include/eos/chain" ) -INSTALL( FILES ${PROTOCOL_HEADERS} DESTINATION "include/eos/chain/protocol" ) diff --git a/libraries/chain/protocol/block.cpp b/libraries/chain/block.cpp similarity index 99% rename from libraries/chain/protocol/block.cpp rename to libraries/chain/block.cpp index 9407adaa3716e9848ee87696776483e27239a5f7..1a51337a3ad3a916f4833b7bf8b7116dc41398fe 100644 --- a/libraries/chain/protocol/block.cpp +++ b/libraries/chain/block.cpp @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include +#include #include #include #include diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 30824fd23fa3f5586270d17691cd93b246fc7880..f2b691f9bef5a72e88808db0cb857acaa3e4741a 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -80,7 +80,7 @@ optional database::fetch_block_by_number(uint32_t num)const if (const auto& block = _block_log.read_block_by_num(num)) return *block; - // Not in _block_id_to_block, so it must be since the last irreversible block. Grab it from _fork_db instead + // Not in _block_log, so it must be since the last irreversible block. Grab it from _fork_db instead if (num <= head_block_num()) { auto block = _fork_db.head(); while (block && block->num > num) @@ -458,25 +458,28 @@ void database::apply_transaction(const signed_transaction& trx, uint32_t skip) with_skip_flags( skip, [&]() { _apply_transaction(trx); }); } -void database::validate_tapos( const signed_transaction& trx )const { +void database::validate_transaction(const signed_transaction& trx)const { try { - if( !should_check_tapos() ) return; - - const chain_parameters& chain_parameters = get_global_properties().parameters; - const auto& tapos_block_summary = get(trx.ref_block_num); + EOS_ASSERT(trx.messages.size() > 0, transaction_exception, "A transaction must have at least one message"); - //Verify TaPoS block summary has correct ID prefix, and that this block's time is not past the expiration - EOS_ASSERT(trx.ref_block_prefix == tapos_block_summary.block_id._hash[1], transaction_exception, - "Transaction's reference block did not match. Is this transaction from a different fork?"); + validate_uniqueness(trx); + validate_tapos(trx); + validate_referenced_accounts(trx); + validate_expiration(trx); - fc::time_point_sec now = head_block_time(); + for( const auto& m : trx.messages ) { /// TODO: this loop can be processed in parallel + message_validate_context mvc( trx, m ); + auto contract_handlers_itr = message_validate_handlers.find( m.recipient ); + if( contract_handlers_itr != message_validate_handlers.end() ) { + auto message_handler_itr = contract_handlers_itr->second.find( {m.recipient, m.type} ); + if( message_handler_itr != contract_handlers_itr->second.end() ) { + message_handler_itr->second(mvc); + continue; + } + } - EOS_ASSERT(trx.expiration <= now + chain_parameters.maximum_time_until_expiration, - transaction_exception, "Transaction expiration is too far in the future", - ("trx.expiration",trx.expiration)("now",now) - ("max_til_exp",chain_parameters.maximum_time_until_expiration)); - EOS_ASSERT(now <= trx.expiration, transaction_exception, "Transaction is expired", - ("now",now)("trx.exp",trx.expiration)); + /// TODO: dispatch to script if not handled above + } } FC_CAPTURE_AND_RETHROW( (trx) ) } void database::validate_uniqueness( const signed_transaction& trx )const { @@ -488,21 +491,35 @@ void database::validate_uniqueness( const signed_transaction& trx )const { transaction_exception, "Transaction is not unique"); } -void database::validate_referenced_accounts( const signed_transaction& trx )const { - for( const auto& auth : trx.provided_authorizations ) { - get_account( auth.authorizing_account ); +void database::validate_tapos( const signed_transaction& trx )const { +try { + if( !should_check_tapos() ) return; + + const auto& tapos_block_summary = get(trx.ref_block_num); + + //Verify TaPoS block summary has correct ID prefix, and that this block's time is not past the expiration + EOS_ASSERT(trx.ref_block_prefix == tapos_block_summary.block_id._hash[1], transaction_exception, + "Transaction's reference block did not match. Is this transaction from a different fork?"); +} FC_CAPTURE_AND_RETHROW( (trx) ) } + +void database::validate_referenced_accounts(const signed_transaction& trx)const { + for(const auto& auth : trx.provided_authorizations) { + get_account(auth.authorizing_account); } - for( const auto& msg : trx.messages ) { - get_account( msg.sender ); - get_account( msg.recipient ); - const account_name* prev = nullptr; - for( const auto& acnt : msg.notify ) { - get_account( acnt ); - if( prev ) - FC_ASSERT( acnt < *prev ); - FC_ASSERT( acnt != msg.sender ); - FC_ASSERT( acnt != msg.recipient ); - prev = &acnt; + for(const auto& msg : trx.messages) { + get_account(msg.sender); + get_account(msg.recipient); + const account_name* previous_notify_account = nullptr; + for(const auto& current_notify_account : msg.notify) { + get_account(current_notify_account); + if(previous_notify_account) + EOS_ASSERT(current_notify_account < *previous_notify_account, message_validate_exception, + "Message notify accounts out of order. Possibly a bug in the wallet?"); + EOS_ASSERT(current_notify_account != msg.sender, message_validate_exception, + "Message sender is listed in accounts to notify. Possibly a bug in the wallet?"); + EOS_ASSERT(current_notify_account != msg.recipient, message_validate_exception, + "Message recipient is listed in accounts to notify. Possibly a bug in the wallet?"); + previous_notify_account = ¤t_notify_account; } } } @@ -535,14 +552,24 @@ try { continue; } } - - /// TODO: dispatch to script if not handled above } -} FC_CAPTURE_AND_RETHROW( (trx) ) } +} +void database::validate_expiration(const signed_transaction& trx) const +{ try { + fc::time_point_sec now = head_block_time(); + const chain_parameters& chain_parameters = get_global_properties().parameters; + + EOS_ASSERT(trx.expiration <= now + chain_parameters.maximum_time_until_expiration, + transaction_exception, "Transaction expiration is too far in the future", + ("trx.expiration",trx.expiration)("now",now) + ("max_til_exp",chain_parameters.maximum_time_until_expiration)); + EOS_ASSERT(now <= trx.expiration, transaction_exception, "Transaction is expired", + ("now",now)("trx.exp",trx.expiration)); +} FC_CAPTURE_AND_RETHROW((trx)) } void database::validate_message_precondition( precondition_validate_context& context )const { const auto& m = context.msg; - auto contract_handlers_itr = precondition_validate_handlers.find( context.receiver ); + auto contract_handlers_itr = precondition_validate_handlers.find( context.recipient ); if( contract_handlers_itr != precondition_validate_handlers.end() ) { auto message_handler_itr = contract_handlers_itr->second.find( {m.recipient, m.type} ); if( message_handler_itr != contract_handlers_itr->second.end() ) { @@ -555,7 +582,7 @@ void database::validate_message_precondition( precondition_validate_context& con void database::apply_message( apply_context& context ) { const auto& m = context.msg; - auto contract_handlers_itr = apply_handlers.find( context.receiver ); + auto contract_handlers_itr = apply_handlers.find( context.recipient ); if( contract_handlers_itr != apply_handlers.end() ) { auto message_handler_itr = contract_handlers_itr->second.find( {m.recipient, m.type} ); if( message_handler_itr != contract_handlers_itr->second.end() ) { @@ -569,7 +596,7 @@ void database::apply_message( apply_context& context ) { void database::_apply_transaction(const signed_transaction& trx) { try { - validate_transaction( trx ); + validate_transaction(trx); for( const auto& m : trx.messages ) { apply_context ac( *this, trx, m, m.recipient ); diff --git a/libraries/chain/get_config.cpp b/libraries/chain/get_config.cpp index 4fa6113d470247d06b6b76d0fbb0513bd6e04950..e6b606fbe3b9937ab9d9c7702b0a62d6d87c4c92 100644 --- a/libraries/chain/get_config.cpp +++ b/libraries/chain/get_config.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include namespace eos { namespace chain { diff --git a/libraries/chain/include/eos/chain/protocol/README.md b/libraries/chain/include/eos/chain/README.md similarity index 100% rename from libraries/chain/include/eos/chain/protocol/README.md rename to libraries/chain/include/eos/chain/README.md diff --git a/libraries/chain/include/eos/chain/account_object.hpp b/libraries/chain/include/eos/chain/account_object.hpp index a12decd3b9f6e6a065f5971f4303c324469767d6..a6eb88c84339e7cb2a41918341caa74236c8b82f 100644 --- a/libraries/chain/include/eos/chain/account_object.hpp +++ b/libraries/chain/include/eos/chain/account_object.hpp @@ -22,8 +22,8 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include #include "multi_index_includes.hpp" diff --git a/libraries/chain/include/eos/chain/protocol/authority.hpp b/libraries/chain/include/eos/chain/authority.hpp similarity index 92% rename from libraries/chain/include/eos/chain/protocol/authority.hpp rename to libraries/chain/include/eos/chain/authority.hpp index 1296cca38bbb69d32a2e660d916081ee5758ab73..b16507fd3b0d96238aa2245b8b1b81d226c3e811 100644 --- a/libraries/chain/include/eos/chain/protocol/authority.hpp +++ b/libraries/chain/include/eos/chain/authority.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include namespace eos { namespace chain { diff --git a/libraries/chain/include/eos/chain/protocol/base.hpp b/libraries/chain/include/eos/chain/base.hpp similarity index 98% rename from libraries/chain/include/eos/chain/protocol/base.hpp rename to libraries/chain/include/eos/chain/base.hpp index bac20658cf471d555c22a289416c72a90c390dad..c7b84e162b1b8f65803736a5164604c56cc8a187 100644 --- a/libraries/chain/include/eos/chain/protocol/base.hpp +++ b/libraries/chain/include/eos/chain/base.hpp @@ -23,7 +23,7 @@ */ #pragma once -#include +#include namespace eos { namespace chain { diff --git a/libraries/chain/include/eos/chain/protocol/block.hpp b/libraries/chain/include/eos/chain/block.hpp similarity index 98% rename from libraries/chain/include/eos/chain/protocol/block.hpp rename to libraries/chain/include/eos/chain/block.hpp index 45499b3d878aaf22430aa74966ed7310d5cc648f..04a4387d246fda646b7436735fdce57704c34edd 100644 --- a/libraries/chain/include/eos/chain/protocol/block.hpp +++ b/libraries/chain/include/eos/chain/block.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include namespace eos { namespace chain { diff --git a/libraries/chain/include/eos/chain/block_log.hpp b/libraries/chain/include/eos/chain/block_log.hpp index 19dfdc8fb55e1161a024f14e9a03e7bcb399bca4..514e8521dc233861ea5d2e506f955fd238f02c0d 100644 --- a/libraries/chain/include/eos/chain/block_log.hpp +++ b/libraries/chain/include/eos/chain/block_log.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include namespace eos { namespace chain { diff --git a/libraries/chain/include/eos/chain/block_summary_object.hpp b/libraries/chain/include/eos/chain/block_summary_object.hpp index 6e53d114a826cc10977190a3776862dba22710f7..dbeb8e005769602e97b5dc084c04590fabef8289 100644 --- a/libraries/chain/include/eos/chain/block_summary_object.hpp +++ b/libraries/chain/include/eos/chain/block_summary_object.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include "multi_index_includes.hpp" diff --git a/libraries/chain/include/eos/chain/protocol/chain_parameters.hpp b/libraries/chain/include/eos/chain/chain_parameters.hpp similarity index 95% rename from libraries/chain/include/eos/chain/protocol/chain_parameters.hpp rename to libraries/chain/include/eos/chain/chain_parameters.hpp index e8a6c16da5957e061d30c11436b7a9db5b5831d3..d95c7c04150c355c5894c813b954c64bce022211 100644 --- a/libraries/chain/include/eos/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/eos/chain/chain_parameters.hpp @@ -22,8 +22,8 @@ * THE SOFTWARE. */ #pragma once -#include -#include +#include +#include #include namespace eos { namespace chain { diff --git a/libraries/chain/include/eos/chain/chain_property_object.hpp b/libraries/chain/include/eos/chain/chain_property_object.hpp index 22c10e7c4cd20a5c0162d5bd142a139592826429..5ad1c3b185575db6537830d823395237b8b6e359 100644 --- a/libraries/chain/include/eos/chain/chain_property_object.hpp +++ b/libraries/chain/include/eos/chain/chain_property_object.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include #include "multi_index_includes.hpp" diff --git a/libraries/chain/include/eos/chain/database.hpp b/libraries/chain/include/eos/chain/database.hpp index 8c0720927c318a68b80a43c2850d9234070eb57f..14ff67cbd10ff233ccd2ef2f35b9c6ef6fd3a9f2 100644 --- a/libraries/chain/include/eos/chain/database.hpp +++ b/libraries/chain/include/eos/chain/database.hpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include @@ -55,16 +55,16 @@ namespace eos { namespace chain { class precondition_validate_context : public message_validate_context { public: precondition_validate_context( const database& d, const transaction& t, const message& m, const account_name& r ) - :message_validate_context(t,m),receiver(r),db(d){} + :message_validate_context(t,m),recipient(r),db(d){} - const account_name& receiver; + const account_name& recipient; const database& db; }; class apply_context : public precondition_validate_context { public: - apply_context( database& d, const transaction& t, const message& m, const account_name& receiver ) - :precondition_validate_context(d,t,m,receiver),mutable_db(d){} + apply_context( database& d, const transaction& t, const message& m, const account_name& recipient ) + :precondition_validate_context(d,t,m,recipient),mutable_db(d){} database& mutable_db; }; @@ -326,13 +326,25 @@ namespace eos { namespace chain { // these were formerly private, but they have a fairly well-defined API, so let's make them public void apply_block(const signed_block& next_block, uint32_t skip = skip_nothing); void apply_transaction(const signed_transaction& trx, uint32_t skip = skip_nothing); - private: + + private: void _apply_block(const signed_block& next_block); void _apply_transaction(const signed_transaction& trx); - void validate_uniqueness( const signed_transaction& trx )const; - void validate_message_precondition( precondition_validate_context& c )const; - void apply_message( apply_context& c ); + /** + * This method validates transactions without adding it to the pending state. + * @return true if the transaction would validate + */ + void validate_transaction(const signed_transaction& trx)const; + /// Validate transaction helpers @{ + void validate_uniqueness(const signed_transaction& trx)const; + void validate_tapos(const signed_transaction& trx)const; + void validate_referenced_accounts(const signed_transaction& trx)const; + void validate_expiration(const signed_transaction& trx) const; + /// @} + + void validate_message_precondition(precondition_validate_context& c)const; + void apply_message(apply_context& c); @@ -351,18 +363,19 @@ namespace eos { namespace chain { void update_last_irreversible_block(); void clear_expired_transactions(); - deque< signed_transaction > _pending_transactions; - fork_database _fork_db; + optional _pending_tx_session; + deque _pending_transactions; + fork_database _fork_db; - block_log _block_log; + block_log _block_log; - bool _producing = false; - bool _pushing = false; - uint64_t _skip_flags = 0; + bool _producing = false; + bool _pushing = false; + uint64_t _skip_flags = 0; - flat_map _checkpoints; + flat_map _checkpoints; - node_property_object _node_property_object; + node_property_object _node_property_object; typedef pair handler_key; map< account_name, map > message_validate_handlers; diff --git a/libraries/chain/include/eos/chain/exceptions.hpp b/libraries/chain/include/eos/chain/exceptions.hpp index 6eb8df70ffce1136470950df9141dab1d1d3fd51..ff99673edb17b68e66013b704162368f6f94a5e6 100644 --- a/libraries/chain/include/eos/chain/exceptions.hpp +++ b/libraries/chain/include/eos/chain/exceptions.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include #define EOS_ASSERT( expr, exc_type, FORMAT, ... ) \ FC_MULTILINE_MACRO_BEGIN \ diff --git a/libraries/chain/include/eos/chain/protocol/ext.hpp b/libraries/chain/include/eos/chain/ext.hpp similarity index 100% rename from libraries/chain/include/eos/chain/protocol/ext.hpp rename to libraries/chain/include/eos/chain/ext.hpp diff --git a/libraries/chain/include/eos/chain/fork_database.hpp b/libraries/chain/include/eos/chain/fork_database.hpp index 9aa7eb148ef6a82b9ac40a1a7a833fafdeb9d910..d4a602527a8639358b9da1cfba2ed266a5d427ec 100644 --- a/libraries/chain/include/eos/chain/fork_database.hpp +++ b/libraries/chain/include/eos/chain/fork_database.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/eos/chain/genesis_state.hpp b/libraries/chain/include/eos/chain/genesis_state.hpp index 62079a0084ccff4c260e364b6699c934e7c041da..324e57eb85b5b7c2c4a55e0358581e6cb8f75cf6 100644 --- a/libraries/chain/include/eos/chain/genesis_state.hpp +++ b/libraries/chain/include/eos/chain/genesis_state.hpp @@ -23,8 +23,8 @@ */ #pragma once -#include -#include +#include +#include #include #include diff --git a/libraries/chain/include/eos/chain/global_property_object.hpp b/libraries/chain/include/eos/chain/global_property_object.hpp index 017c7863b458bc31879cac8b593c1634c64ae3f2..c9a4a7ba84eab9d10aa67ee9581f5706c382691f 100644 --- a/libraries/chain/include/eos/chain/global_property_object.hpp +++ b/libraries/chain/include/eos/chain/global_property_object.hpp @@ -25,8 +25,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/libraries/chain/include/eos/chain/message.hpp b/libraries/chain/include/eos/chain/message.hpp index 51f04e556c1610f5de018f0056456a0b103c628e..49ed1d1f0f305adeac8af6c75d5aa175ce8f3772 100644 --- a/libraries/chain/include/eos/chain/message.hpp +++ b/libraries/chain/include/eos/chain/message.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace eos { namespace chain { @@ -11,7 +11,7 @@ namespace eos { namespace chain { * -- all events and actions which take place in the chain are * recorded as messages. Messages are sent from one account * (@ref sender) to another account (@ref recipient), and are - * optionally also delivered to several other accounts (@ref notify_accounts). + * optionally also delivered to several other accounts (@ref notify). * * A message has a header that defines who sent it and who will * be processing it. The message content is a binary blob, @@ -29,9 +29,9 @@ struct message { vector notify; /** - * Every contract defines the set of types that it accepts, these types are - * scoped according to the recipient. This means two contracts can can define - * two different types with the same name. + * Every contract defines the set of types that it accepts, these types are + * scoped according to the recipient. This means two contracts can can define + * two different types with the same name. */ message_type type; diff --git a/libraries/chain/include/eos/chain/node_property_object.hpp b/libraries/chain/include/eos/chain/node_property_object.hpp index afa61079f9051a4dd641bd49dd6ef85f95680cbd..9c943cee1de99cc4a25010c8472c31c38c26b9bb 100644 --- a/libraries/chain/include/eos/chain/node_property_object.hpp +++ b/libraries/chain/include/eos/chain/node_property_object.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include namespace eos { namespace chain { diff --git a/libraries/chain/include/eos/chain/producer_object.hpp b/libraries/chain/include/eos/chain/producer_object.hpp index ad2c620c9e6690cb23b6ed82590516670e7f3b67..7668e17de2f815903d5ac920a4ec74438188af47 100644 --- a/libraries/chain/include/eos/chain/producer_object.hpp +++ b/libraries/chain/include/eos/chain/producer_object.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include "multi_index_includes.hpp" diff --git a/libraries/chain/include/eos/chain/protocol/config.hpp b/libraries/chain/include/eos/chain/protocol.hpp similarity index 97% rename from libraries/chain/include/eos/chain/protocol/config.hpp rename to libraries/chain/include/eos/chain/protocol.hpp index 4053f5957a1d91d270bba354b3acd565a64e7cd8..ecaf7f7a30a4ea3533508ab8c0d3c217dfd7dab5 100644 --- a/libraries/chain/include/eos/chain/protocol/config.hpp +++ b/libraries/chain/include/eos/chain/protocol.hpp @@ -22,4 +22,4 @@ * THE SOFTWARE. */ #pragma once -#include +#include diff --git a/libraries/chain/include/eos/chain/protocol/protocol.hpp b/libraries/chain/include/eos/chain/protocol/protocol.hpp deleted file mode 100644 index 2f60451cc7ec52d87d16a68e220f040680862dd0..0000000000000000000000000000000000000000 --- a/libraries/chain/include/eos/chain/protocol/protocol.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2017, Respective Authors. - * - * The MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#pragma once -#include diff --git a/libraries/chain/include/eos/chain/protocol/transaction.hpp b/libraries/chain/include/eos/chain/transaction.hpp similarity index 99% rename from libraries/chain/include/eos/chain/protocol/transaction.hpp rename to libraries/chain/include/eos/chain/transaction.hpp index e840280d91c277e75f70780f013bab185b62deef..0659432941e271d2aeea38b32dbd44dad46b8473 100644 --- a/libraries/chain/include/eos/chain/protocol/transaction.hpp +++ b/libraries/chain/include/eos/chain/transaction.hpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #pragma once -#include +#include #include #include diff --git a/libraries/chain/include/eos/chain/transaction_object.hpp b/libraries/chain/include/eos/chain/transaction_object.hpp index 7cbebf275f58d5d8df68dcca10c9455408a2ac48..ff005b205c0839597858876da09cd3db34a06cd0 100644 --- a/libraries/chain/include/eos/chain/transaction_object.hpp +++ b/libraries/chain/include/eos/chain/transaction_object.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include #include #include diff --git a/libraries/chain/include/eos/chain/protocol/types.hpp b/libraries/chain/include/eos/chain/types.hpp similarity index 99% rename from libraries/chain/include/eos/chain/protocol/types.hpp rename to libraries/chain/include/eos/chain/types.hpp index 2f4b87f5a25d3f49dd4b6c249ce36c6fe8f0878c..83c2beaa3a7da4a1beaa24be688a8ee90add1976 100644 --- a/libraries/chain/include/eos/chain/protocol/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include diff --git a/libraries/chain/protocol/transaction.cpp b/libraries/chain/transaction.cpp similarity index 100% rename from libraries/chain/protocol/transaction.cpp rename to libraries/chain/transaction.cpp diff --git a/libraries/chain/protocol/types.cpp b/libraries/chain/types.cpp similarity index 98% rename from libraries/chain/protocol/types.cpp rename to libraries/chain/types.cpp index e4f6f0461da86511e67bfc859cdb85eea227648b..bea7650f3094e570d91965fd70c407e3e9f3dfed 100644 --- a/libraries/chain/protocol/types.cpp +++ b/libraries/chain/types.cpp @@ -22,7 +22,7 @@ * THE SOFTWARE. */ #include -#include +#include #include #include diff --git a/libraries/egenesis/egenesis_brief.cpp.tmpl b/libraries/egenesis/egenesis_brief.cpp.tmpl index 03420696cad5a7b31a29a242ec00bd8a06cf6c8f..afdcf599e81da67404577b83bce158854563989b 100644 --- a/libraries/egenesis/egenesis_brief.cpp.tmpl +++ b/libraries/egenesis/egenesis_brief.cpp.tmpl @@ -17,7 +17,7 @@ ${generated_file_banner} * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include namespace eos { namespace egenesis { diff --git a/libraries/egenesis/egenesis_full.cpp.tmpl b/libraries/egenesis/egenesis_full.cpp.tmpl index 19b86ab343222e67f0feee64e23e2d16e55beb42..28d92e7a925898c604ccd91f0ff4b182d4093491 100644 --- a/libraries/egenesis/egenesis_full.cpp.tmpl +++ b/libraries/egenesis/egenesis_full.cpp.tmpl @@ -17,7 +17,7 @@ ${generated_file_banner} * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include namespace eos { namespace egenesis { diff --git a/libraries/egenesis/embed_genesis.cpp b/libraries/egenesis/embed_genesis.cpp index fd8faf1ed83f3739fc30edabbbfecd85c1cae1c2..c58ec9665fb4965af952b967611cbf37e6c1615b 100644 --- a/libraries/egenesis/embed_genesis.cpp +++ b/libraries/egenesis/embed_genesis.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include using namespace eos::chain; diff --git a/libraries/egenesis/include/eos/egenesis/egenesis.hpp b/libraries/egenesis/include/eos/egenesis/egenesis.hpp index 84deb83a94fc4a1480514c467b726e54a6817a6a..556d1295e578537305a5aac437208aee28839ba1 100644 --- a/libraries/egenesis/include/eos/egenesis/egenesis.hpp +++ b/libraries/egenesis/include/eos/egenesis/egenesis.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include namespace eos { namespace egenesis { diff --git a/libraries/net/include/eos/net/core_messages.hpp b/libraries/net/include/eos/net/core_messages.hpp index fa1f08b4ab32e0f6fc16920eeeb5548a31407a5e..5916ca208820cc3871264092b4819eec4a1e3cd1 100644 --- a/libraries/net/include/eos/net/core_messages.hpp +++ b/libraries/net/include/eos/net/core_messages.hpp @@ -24,7 +24,7 @@ #pragma once #include -#include +#include #include #include diff --git a/libraries/net/include/eos/net/node.hpp b/libraries/net/include/eos/net/node.hpp index 5d95f8484190603451d5898045e444f1531c65ff..066de1126d6d88f27bf0073fffd9d2b5d1fda0e7 100644 --- a/libraries/net/include/eos/net/node.hpp +++ b/libraries/net/include/eos/net/node.hpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include diff --git a/plugins/chain_api_plugin/chain_api_plugin.cpp b/plugins/chain_api_plugin/chain_api_plugin.cpp index e8a41761d56ea93782084005266a8f8445d673c8..bcf0362b0767bcdfec45a470a7bcf2c2325e0310 100644 --- a/plugins/chain_api_plugin/chain_api_plugin.cpp +++ b/plugins/chain_api_plugin/chain_api_plugin.cpp @@ -24,7 +24,8 @@ void chain_api_plugin::set_program_options(options_description&, options_descrip void chain_api_plugin::plugin_initialize(const variables_map&) {} #define CALL(api_name, api_handle, api_namespace, call_name) \ -{std::string("/v1/" #api_name "/" #call_name), [this, api_handle](string, string body, url_response_callback cb) { \ +{std::string("/v1/" #api_name "/" #call_name), \ + [this, api_handle](string, string body, url_response_callback cb) mutable { \ try { \ if (body.empty()) body = "{}"; \ auto result = api_handle.call_name(fc::json::from_string(body).as()); \ @@ -39,13 +40,17 @@ void chain_api_plugin::plugin_initialize(const variables_map&) {} }} #define CHAIN_RO_CALL(call_name) CALL(chain, ro_api, chain_apis::read_only, call_name) +#define CHAIN_RW_CALL(call_name) CALL(chain, rw_api, chain_apis::read_write, call_name) void chain_api_plugin::plugin_startup() { auto ro_api = app().get_plugin().get_read_only_api(); + auto rw_api = app().get_plugin().get_read_write_api(); app().get_plugin().add_api({ CHAIN_RO_CALL(get_info), - CHAIN_RO_CALL(get_block) + CHAIN_RO_CALL(get_block), + CHAIN_RW_CALL(push_block), + CHAIN_RW_CALL(push_transaction) }); } diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 446be877b0363d56ba15a59ad19fee02a56853c8..236683608b02e2ab4a1b1806ed36daf5c7867499 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -173,5 +173,13 @@ read_only::get_block_results read_only::get_block(const read_only::get_block_par "Could not find block: ${block}", ("block", params.block_num_or_id)); } +read_write::push_block_results read_write::push_block(const read_write::push_block_params& params) { + db.push_block(params); +} + +read_write::push_transaction_results read_write::push_transaction(const read_write::push_transaction_params& params) { + db.push_transaction(params); +} + } // namespace chain_apis } // namespace eos diff --git a/plugins/chain_plugin/include/eos/chain_plugin/chain_plugin.hpp b/plugins/chain_plugin/include/eos/chain_plugin/chain_plugin.hpp index cf31b3da83853d7f70ff336dc4ccc1840c93636b..e470f18e06b5c3061cff939d8fbeb20ca27c6cdc 100644 --- a/plugins/chain_plugin/include/eos/chain_plugin/chain_plugin.hpp +++ b/plugins/chain_plugin/include/eos/chain_plugin/chain_plugin.hpp @@ -34,6 +34,20 @@ public: using get_block_results = chain::signed_block; get_block_results get_block(const get_block_params& params) const; }; + +class read_write { + database& db; +public: + read_write(database& db) : db(db) {} + + using push_block_params = chain::signed_block; + using push_block_results = empty; + push_block_results push_block(const push_block_params& params); + + using push_transaction_params = chain::signed_transaction; + using push_transaction_results = empty; + push_transaction_results push_transaction(const push_transaction_params& params); +}; } // namespace chain_apis class chain_plugin : public plugin { @@ -49,9 +63,8 @@ public: void plugin_startup(); void plugin_shutdown(); - chain_apis::read_only get_read_only_api() const { - return chain_apis::read_only(db()); - } + chain_apis::read_only get_read_only_api() const { return chain_apis::read_only(db()); } + chain_apis::read_write get_read_write_api() { return chain_apis::read_write(db()); } bool accept_block(const chain::signed_block& block, bool currently_syncing); void accept_transaction(const chain::signed_transaction& trx); diff --git a/plugins/native_system_contract_plugin/include/eos/native_system_contract_plugin/native_system_contract_plugin.hpp b/plugins/native_system_contract_plugin/include/eos/native_system_contract_plugin/native_system_contract_plugin.hpp index 018ae24e57ef72318bb9ed51484f708fbd7140a3..8cd1762d1cfae67e27c42bbabe5fecf3257ccfb5 100644 --- a/plugins/native_system_contract_plugin/include/eos/native_system_contract_plugin/native_system_contract_plugin.hpp +++ b/plugins/native_system_contract_plugin/include/eos/native_system_contract_plugin/native_system_contract_plugin.hpp @@ -3,8 +3,8 @@ #include -#include -#include +#include +#include namespace eos { using namespace appbase; diff --git a/plugins/net_plugin/include/eos/net_plugin/protocol.hpp b/plugins/net_plugin/include/eos/net_plugin/protocol.hpp index 3fe1de04bb45de2d7e44c9913db0001b7aa20508..cd441883fbc95e3f00df6683e63a11f068b78d3f 100644 --- a/plugins/net_plugin/include/eos/net_plugin/protocol.hpp +++ b/plugins/net_plugin/include/eos/net_plugin/protocol.hpp @@ -1,6 +1,6 @@ #pragma once -#include -#include +#include +#include namespace eos { using namespace chain; diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index debe4d893b64fe1315f93f23aaa9df0a9a066d63..f067832e834f60c8b5f60fbd7a398c84efde1355 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include