From 605fe7df114e85a9d7cdef8a3e5f789c45a560a8 Mon Sep 17 00:00:00 2001 From: Bart Wyatt Date: Wed, 23 Sep 2020 14:38:47 -0400 Subject: [PATCH] added appropriate annotations and downgraded binary extension to the one present in 1.6.x series CDTs --- .../include/eosio.msig/eosio.msig.hpp | 206 +----------------- contracts/eosio.msig/src/eosio.msig.cpp | 6 +- 2 files changed, 8 insertions(+), 204 deletions(-) diff --git a/contracts/eosio.msig/include/eosio.msig/eosio.msig.hpp b/contracts/eosio.msig/include/eosio.msig/eosio.msig.hpp index 4bca57554..189ef8bb9 100644 --- a/contracts/eosio.msig/include/eosio.msig/eosio.msig.hpp +++ b/contracts/eosio.msig/include/eosio.msig/eosio.msig.hpp @@ -6,204 +6,8 @@ #include namespace eosio { - /** - * Clone of `eosio::binary_extension` that includes `operator=` to avoid - * bumping the `eosio.cdt` dependency version of the v1.8.x patch release of - * `eosio.contracts`. - */ - template - class eosio_msig_binary_extension { - public: - using value_type = T; - - constexpr eosio_msig_binary_extension() {} - constexpr eosio_msig_binary_extension( const T& ext ) - :_has_value(true) - { - ::new (&_data) T(ext); - } - constexpr eosio_msig_binary_extension( T&& ext ) - :_has_value(true) - { - ::new (&_data) T(std::move(ext)); - } - /** construct contained type in place */ - template - constexpr eosio_msig_binary_extension( std::in_place_t, Args&&... args ) - :_has_value(true) - { - ::new (&_data) T(std::forward(args)...); - } - - constexpr eosio_msig_binary_extension( const eosio_msig_binary_extension& other ) - :_has_value(other._has_value) - { - if( other._has_value ) ::new (&_data) T( *other ); - } - - constexpr eosio_msig_binary_extension( eosio_msig_binary_extension&& other ) - :_has_value(other._has_value) - { - if( other._has_value ) { - ::new (&_data) T( *std::move(other) ); - other._has_value = false; - } - } - - /// @cond INTERNAL - ~eosio_msig_binary_extension() { reset(); } - - /// @cond INTERNAL - constexpr eosio_msig_binary_extension& operator= (const eosio_msig_binary_extension& other) { - if (has_value()) - reset(); - - if (other.has_value()) { - ::new (&_data) T(*other); - _has_value = true; - } - return *this; - } - - /// @cond INTERNAL - constexpr eosio_msig_binary_extension& operator= (eosio_msig_binary_extension&& other) { - if (has_value()) - reset(); - - if (other.has_value()) { - ::new (&_data) T(*other); - _has_value = true; - other._has_value = false; - } - return *this; - } - /** test if container is holding a value */ - constexpr explicit operator bool()const { return _has_value; } - /** test if container is holding a value */ - constexpr bool has_value()const { return _has_value; } - - /** get the contained value */ - constexpr T& value()& { - if (!_has_value) { - check(false, "cannot get value of empty eosio_msig_binary_extension"); - } - return _get(); - } - - /// @cond INTERNAL - - /** get the contained value */ - constexpr const T& value()const & { - if (!_has_value) { - check(false, "cannot get value of empty eosio_msig_binary_extension"); - } - return _get(); - } - - /** get the contained value or a user specified default - * @pre def should be convertible to type T - * */ - template - constexpr auto value_or( U&& def ) -> std::enable_if_t::value, T&>& { - if (_has_value) - return _get(); - return def; - } - - constexpr T value_or() const { return (_has_value) ? _get() : T{}; } - - constexpr T* operator->() { - return &_get(); - } - constexpr const T* operator->()const { - return &_get(); - } - - constexpr T& operator*()& { - return _get(); - } - constexpr const T& operator*()const& { - return _get(); - } - constexpr const T&& operator*()const&& { - return std::move(_get()); - } - constexpr T&& operator*()&& { - return std::move(_get()); - } - - template - T& emplace(Args&& ... args)& { - if (_has_value) { - reset(); - } - - ::new (&_data) T( std::forward(args)... ); - _has_value = true; - - return _get(); - } - - void reset() { - if( _has_value ) { - _get().~value_type(); - _has_value = false; - } - } - - /// @endcond - - private: - bool _has_value = false; - typename std::aligned_storage::type _data; - - constexpr T& _get() { - return *reinterpret_cast(&_data); - } - - constexpr const T& _get()const { - return *reinterpret_cast(&_data); - } - }; - /// @cond IMPLEMENTATIONS - /** - * Serialize a eosio_msig_binary_extension into a stream - * - * @ingroup eosio_msig_binary_extension - * @brief Serialize a eosio_msig_binary_extension - * @param ds - The stream to write - * @param opt - The value to serialize - * @tparam DataStream - Type of datastream buffer - * @return DataStream& - Reference to the datastream - */ - template - inline DataStream& operator<<(DataStream& ds, const eosio::eosio_msig_binary_extension& be) { - ds << be.value_or(); - return ds; - } - - /** - * Deserialize a eosio_msig_binary_extension from a stream - * - * @ingroup eosio_msig_binary_extension - * @brief Deserialize a eosio_msig_binary_extension - * @param ds - The stream to read - * @param opt - The destination for deserialized value - * @tparam DataStream - Type of datastream buffer - * @return DataStream& - Reference to the datastream - */ - template - inline DataStream& operator>>(DataStream& ds, eosio::eosio_msig_binary_extension& be) { - if( ds.remaining() ) { - T val; - ds >> val; - be.emplace(val); - } - return ds; - } - /** * The `eosio.msig` system contract allows for creation of proposed transactions which require authorization from a list of accounts, approval of the proposed transactions by those accounts required to approve it, and finally, it also allows the execution of the approved transactions on the blockchain. * @@ -311,16 +115,16 @@ namespace eosio { using invalidate_action = eosio::action_wrapper<"invalidate"_n, &multisig::invalidate>; }; - struct [[eosio::table]] proposal { + struct [[eosio::table, eosio::contract("eosio.msig")]] proposal { name proposal_name; std::vector packed_transaction; - eosio::eosio_msig_binary_extension< std::optional > earliest_exec_time; + eosio::binary_extension< std::optional > earliest_exec_time; uint64_t primary_key()const { return proposal_name.value; } }; typedef eosio::multi_index< "proposal"_n, proposal > proposals; - struct [[eosio::table]] old_approvals_info { + struct [[eosio::table, eosio::contract("eosio.msig")]] old_approvals_info { name proposal_name; std::vector requested_approvals; std::vector provided_approvals; @@ -334,7 +138,7 @@ namespace eosio { time_point time; }; - struct [[eosio::table]] approvals_info { + struct [[eosio::table, eosio::contract("eosio.msig")]] approvals_info { uint8_t version = 1; name proposal_name; //requested approval doesn't need to contain time, but we want requested approval @@ -347,7 +151,7 @@ namespace eosio { }; typedef eosio::multi_index< "approvals2"_n, approvals_info > approvals; - struct [[eosio::table]] invalidation { + struct [[eosio::table, eosio::contract("eosio.msig")]] invalidation { name account; time_point last_invalidation_time; diff --git a/contracts/eosio.msig/src/eosio.msig.cpp b/contracts/eosio.msig/src/eosio.msig.cpp index 2795ea6cd..99d706d1e 100644 --- a/contracts/eosio.msig/src/eosio.msig.cpp +++ b/contracts/eosio.msig/src/eosio.msig.cpp @@ -76,7 +76,7 @@ void multisig::propose( name proposer, proptable.emplace( proposer, [&]( auto& prop ) { prop.proposal_name = proposal_name; prop.packed_transaction = pkd_trans; - prop.earliest_exec_time = std::optional{}; + prop.earliest_exec_time.emplace(); }); approvals apptable( get_self(), proposer.value ); @@ -131,7 +131,7 @@ void multisig::approve( name proposer, name proposal_name, permission_level leve auto table_op = [](auto&&, auto&&){}; if( trx_is_authorized(get_approvals_and_adjust_table(get_self(), proposer, proposal_name, table_op), prop.packed_transaction) ) { proptable.modify( prop, proposer, [&]( auto& p ) { - p.earliest_exec_time = std::optional{ current_time_point() + eosio::seconds(trx_header.delay_sec.value)}; + p.earliest_exec_time.emplace(time_point{ current_time_point() + eosio::seconds(trx_header.delay_sec.value)}); }); } } @@ -171,7 +171,7 @@ void multisig::unapprove( name proposer, name proposal_name, permission_level le auto table_op = [](auto&&, auto&&){}; if( !trx_is_authorized(get_approvals_and_adjust_table(get_self(), proposer, proposal_name, table_op), prop.packed_transaction) ) { proptable.modify( prop, proposer, [&]( auto& p ) { - p.earliest_exec_time = std::optional{}; + p.earliest_exec_time.emplace(); }); } }