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

return flat_multimap from transaction::validate_and_extract_extensions #7703

Merged
merged 2 commits into from
Jul 30, 2019
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
10 changes: 7 additions & 3 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,14 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
if( control.is_builtin_activated( builtin_protocol_feature_t::no_duplicate_deferred_id ) ) {
auto exts = trx.validate_and_extract_extensions();
if( exts.size() > 0 ) {
EOS_ASSERT( exts.size() == 1, invalid_transaction_extension,
"only one extension is currently supported for deferred transactions"
auto itr = exts.lower_bound( deferred_transaction_generation_context::extension_id() );

EOS_ASSERT( exts.size() == 1 && itr != exts.end(), invalid_transaction_extension,
"only the deferred_transaction_generation_context extension is currently supported for deferred transactions"
);
const auto& context = exts.front().get<deferred_transaction_generation_context>();

const auto& context = itr->second.get<deferred_transaction_generation_context>();

EOS_ASSERT( context.sender == receiver, ill_formed_deferred_transaction_generation_context,
"deferred transaction generaction context contains mismatching sender",
("expected", receiver)("actual", context.sender)
Expand Down
6 changes: 1 addition & 5 deletions libraries/chain/block_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ namespace eosio { namespace chain {
}

flat_multimap<uint16_t, block_header_extensions> block_header::validate_and_extract_header_extensions()const {
using block_header_extensions_t = block_header_extension_types::block_header_extensions_t;
using decompose_t = block_header_extension_types::decompose_t;

static_assert( std::is_same<block_header_extensions_t, block_header_extensions>::value,
"block_header_extensions is not setup as expected" );

flat_multimap<uint16_t, block_header_extensions> results;

uint16_t id_type_lower_bound = 0;
Expand All @@ -52,7 +48,7 @@ namespace eosio { namespace chain {
std::forward_as_tuple()
);

auto match = decompose_t::extract<block_header_extensions_t>( id, e.second, iter->second );
auto match = decompose_t::extract<block_header_extensions>( id, e.second, iter->second );
EOS_ASSERT( match, invalid_block_header_extension,
"Block header extension with id type ${id} is not supported",
("id", id)
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace eosio { namespace chain {
bool allow_duplicate_keys = false) const;

uint32_t total_actions()const { return context_free_actions.size() + actions.size(); }

account_name first_authorizer()const {
for( const auto& a : actions ) {
for( const auto& u : a.authorization )
Expand All @@ -108,7 +108,7 @@ namespace eosio { namespace chain {
return account_name();
}

vector<eosio::chain::transaction_extensions> validate_and_extract_extensions()const;
flat_multimap<uint16_t, eosio::chain::transaction_extensions> validate_and_extract_extensions()const;
};

struct signed_transaction : public transaction
Expand Down
15 changes: 7 additions & 8 deletions libraries/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,10 @@ fc::microseconds transaction::get_signature_keys( const vector<signature_type>&
return sig_cpu_usage;
} FC_CAPTURE_AND_RETHROW() }

vector<transaction_extensions> transaction::validate_and_extract_extensions()const {
using transaction_extensions_t = transaction_extension_types::transaction_extensions_t;
flat_multimap<uint16_t, transaction_extensions> transaction::validate_and_extract_extensions()const {
using decompose_t = transaction_extension_types::decompose_t;

static_assert( std::is_same<transaction_extensions_t, eosio::chain::transaction_extensions>::value,
"transaction_extensions is not setup as expected" );

vector<transaction_extensions_t> results;
flat_multimap<uint16_t, eosio::chain::transaction_extensions> results;

uint16_t id_type_lower_bound = 0;

Expand All @@ -163,9 +159,12 @@ vector<transaction_extensions> transaction::validate_and_extract_extensions()con
"Transaction extensions are not in the correct order (ascending id types required)"
);

results.emplace_back();
auto iter = results.emplace(std::piecewise_construct,
std::forward_as_tuple(id),
std::forward_as_tuple()
);

auto match = decompose_t::extract<transaction_extensions_t>( id, e.second, results.back() );
auto match = decompose_t::extract<eosio::chain::transaction_extensions>( id, e.second, iter->second );
arhag marked this conversation as resolved.
Show resolved Hide resolved
EOS_ASSERT( match, invalid_transaction_extension,
"Transaction extension with id type ${id} is not supported",
("id", id)
Expand Down