Skip to content

Commit

Permalink
Change account and name from action_base to be const.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Oct 18, 2024
1 parent 816535a commit 986562e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/abi_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ namespace impl {
const variant_object& vo = v.get_object();
EOS_ASSERT(vo.contains("account"), packed_transaction_type_exception, "Missing account");
EOS_ASSERT(vo.contains("name"), packed_transaction_type_exception, "Missing name");
from_variant(vo["account"], act.account);
from_variant(vo["name"], act.name);
from_variant(vo["account"], const_cast<account_name&>(act.account));
from_variant(vo["name"], const_cast<action_name&>(act.name));

if (vo.contains("authorization")) {
from_variant(vo["authorization"], act.authorization);
Expand Down
32 changes: 28 additions & 4 deletions libraries/chain/include/eosio/chain/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <eosio/chain/types.hpp>
#include <eosio/chain/exceptions.hpp>

namespace eosio { namespace chain {
namespace eosio::chain {

struct permission_level {
account_name actor;
Expand Down Expand Up @@ -54,12 +54,30 @@ namespace eosio { namespace chain {
* were properly declared when it executes.
*/
struct action_base {
account_name account;
action_name name;
const account_name account;
const action_name name;
vector<permission_level> authorization;

action_base() = default;

action_base(action_base&&) = default;
action_base& operator=(action_base&& o) {
if (this != &o) {
std::destroy_at(this);
std::construct_at(this, std::move(o));
}
return *this;
}

action_base(const action_base&) = default;
action_base& operator=(const action_base& o) {
if (this != &o) {
std::destroy_at(this);
std::construct_at(this, o);
}
return *this;
}

action_base( account_name acnt, action_name act, const vector<permission_level>& auth )
: account(acnt), name(act), authorization(auth) {}
action_base( account_name acnt, action_name act, vector<permission_level>&& auth )
Expand All @@ -71,6 +89,12 @@ namespace eosio { namespace chain {

action() = default;

action(action&&) = default;
action& operator=(action&&) = default;

action(const action&) = default;
action& operator=(const action&) = default;

template<typename T, std::enable_if_t<std::is_base_of<bytes, T>::value, int> = 1>
action( vector<permission_level> auth, const T& value )
: action_base( T::get_account(), T::get_name(), std::move(auth) ) {
Expand Down Expand Up @@ -131,7 +155,7 @@ namespace eosio { namespace chain {
account_name receiver;
};

} } /// namespace eosio::chain
} /// namespace eosio::chain

FC_REFLECT( eosio::chain::permission_level, (actor)(permission) )
FC_REFLECT( eosio::chain::action_base, (account)(name)(authorization) )
Expand Down
6 changes: 6 additions & 0 deletions libraries/chain/include/eosio/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ namespace eosio { namespace chain {
vector<action> actions;
extensions_type transaction_extensions;

transaction() = default;
transaction(transaction&&) = default;
transaction(const transaction&) = default;
transaction& operator=(transaction&&) = default;
transaction& operator=(const transaction&) = default;

transaction_id_type id()const;
digest_type sig_digest( const chain_id_type& chain_id, const vector<bytes>& cfd = vector<bytes>() )const;
fc::microseconds get_signature_keys( const vector<signature_type>& signatures,
Expand Down

0 comments on commit 986562e

Please sign in to comment.