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

Commit 9895b08

Browse files
author
John DeBord
authored
Merge pull request #519 from EOSIO/feature/fix-inline-msig-abigen
ABI generation fixes for OOB Patch
2 parents 0ebd5f3 + 605fe7d commit 9895b08

File tree

2 files changed

+8
-204
lines changed

2 files changed

+8
-204
lines changed

contracts/eosio.msig/include/eosio.msig/eosio.msig.hpp

+5-201
Original file line numberDiff line numberDiff line change
@@ -6,204 +6,8 @@
66
#include <eosio/transaction.hpp>
77

88
namespace eosio {
9-
/**
10-
* Clone of `eosio::binary_extension` that includes `operator=` to avoid
11-
* bumping the `eosio.cdt` dependency version of the v1.8.x patch release of
12-
* `eosio.contracts`.
13-
*/
14-
template <typename T>
15-
class eosio_msig_binary_extension {
16-
public:
17-
using value_type = T;
18-
19-
constexpr eosio_msig_binary_extension() {}
20-
constexpr eosio_msig_binary_extension( const T& ext )
21-
:_has_value(true)
22-
{
23-
::new (&_data) T(ext);
24-
}
25-
constexpr eosio_msig_binary_extension( T&& ext )
26-
:_has_value(true)
27-
{
28-
::new (&_data) T(std::move(ext));
29-
}
30-
/** construct contained type in place */
31-
template <typename... Args>
32-
constexpr eosio_msig_binary_extension( std::in_place_t, Args&&... args )
33-
:_has_value(true)
34-
{
35-
::new (&_data) T(std::forward<Args>(args)...);
36-
}
37-
38-
constexpr eosio_msig_binary_extension( const eosio_msig_binary_extension& other )
39-
:_has_value(other._has_value)
40-
{
41-
if( other._has_value ) ::new (&_data) T( *other );
42-
}
43-
44-
constexpr eosio_msig_binary_extension( eosio_msig_binary_extension&& other )
45-
:_has_value(other._has_value)
46-
{
47-
if( other._has_value ) {
48-
::new (&_data) T( *std::move(other) );
49-
other._has_value = false;
50-
}
51-
}
52-
53-
/// @cond INTERNAL
54-
~eosio_msig_binary_extension() { reset(); }
55-
56-
/// @cond INTERNAL
57-
constexpr eosio_msig_binary_extension& operator= (const eosio_msig_binary_extension& other) {
58-
if (has_value())
59-
reset();
60-
61-
if (other.has_value()) {
62-
::new (&_data) T(*other);
63-
_has_value = true;
64-
}
65-
return *this;
66-
}
67-
68-
/// @cond INTERNAL
69-
constexpr eosio_msig_binary_extension& operator= (eosio_msig_binary_extension&& other) {
70-
if (has_value())
71-
reset();
72-
73-
if (other.has_value()) {
74-
::new (&_data) T(*other);
75-
_has_value = true;
76-
other._has_value = false;
77-
}
78-
return *this;
79-
}
80-
/** test if container is holding a value */
81-
constexpr explicit operator bool()const { return _has_value; }
82-
/** test if container is holding a value */
83-
constexpr bool has_value()const { return _has_value; }
84-
85-
/** get the contained value */
86-
constexpr T& value()& {
87-
if (!_has_value) {
88-
check(false, "cannot get value of empty eosio_msig_binary_extension");
89-
}
90-
return _get();
91-
}
92-
93-
/// @cond INTERNAL
94-
95-
/** get the contained value */
96-
constexpr const T& value()const & {
97-
if (!_has_value) {
98-
check(false, "cannot get value of empty eosio_msig_binary_extension");
99-
}
100-
return _get();
101-
}
102-
103-
/** get the contained value or a user specified default
104-
* @pre def should be convertible to type T
105-
* */
106-
template <typename U>
107-
constexpr auto value_or( U&& def ) -> std::enable_if_t<std::is_convertible<U, T>::value, T&>& {
108-
if (_has_value)
109-
return _get();
110-
return def;
111-
}
112-
113-
constexpr T value_or() const { return (_has_value) ? _get() : T{}; }
114-
115-
constexpr T* operator->() {
116-
return &_get();
117-
}
118-
constexpr const T* operator->()const {
119-
return &_get();
120-
}
121-
122-
constexpr T& operator*()& {
123-
return _get();
124-
}
125-
constexpr const T& operator*()const& {
126-
return _get();
127-
}
128-
constexpr const T&& operator*()const&& {
129-
return std::move(_get());
130-
}
131-
constexpr T&& operator*()&& {
132-
return std::move(_get());
133-
}
134-
135-
template<typename ...Args>
136-
T& emplace(Args&& ... args)& {
137-
if (_has_value) {
138-
reset();
139-
}
140-
141-
::new (&_data) T( std::forward<Args>(args)... );
142-
_has_value = true;
143-
144-
return _get();
145-
}
146-
147-
void reset() {
148-
if( _has_value ) {
149-
_get().~value_type();
150-
_has_value = false;
151-
}
152-
}
153-
154-
/// @endcond
155-
156-
private:
157-
bool _has_value = false;
158-
typename std::aligned_storage<sizeof(T), alignof(T)>::type _data;
159-
160-
constexpr T& _get() {
161-
return *reinterpret_cast<T*>(&_data);
162-
}
163-
164-
constexpr const T& _get()const {
165-
return *reinterpret_cast<const T*>(&_data);
166-
}
167-
};
168-
1699
/// @cond IMPLEMENTATIONS
17010

171-
/**
172-
* Serialize a eosio_msig_binary_extension into a stream
173-
*
174-
* @ingroup eosio_msig_binary_extension
175-
* @brief Serialize a eosio_msig_binary_extension
176-
* @param ds - The stream to write
177-
* @param opt - The value to serialize
178-
* @tparam DataStream - Type of datastream buffer
179-
* @return DataStream& - Reference to the datastream
180-
*/
181-
template<typename DataStream, typename T>
182-
inline DataStream& operator<<(DataStream& ds, const eosio::eosio_msig_binary_extension<T>& be) {
183-
ds << be.value_or();
184-
return ds;
185-
}
186-
187-
/**
188-
* Deserialize a eosio_msig_binary_extension from a stream
189-
*
190-
* @ingroup eosio_msig_binary_extension
191-
* @brief Deserialize a eosio_msig_binary_extension
192-
* @param ds - The stream to read
193-
* @param opt - The destination for deserialized value
194-
* @tparam DataStream - Type of datastream buffer
195-
* @return DataStream& - Reference to the datastream
196-
*/
197-
template<typename DataStream, typename T>
198-
inline DataStream& operator>>(DataStream& ds, eosio::eosio_msig_binary_extension<T>& be) {
199-
if( ds.remaining() ) {
200-
T val;
201-
ds >> val;
202-
be.emplace(val);
203-
}
204-
return ds;
205-
}
206-
20711
/**
20812
* 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.
20913
*
@@ -311,16 +115,16 @@ namespace eosio {
311115
using invalidate_action = eosio::action_wrapper<"invalidate"_n, &multisig::invalidate>;
312116
};
313117

314-
struct [[eosio::table]] proposal {
118+
struct [[eosio::table, eosio::contract("eosio.msig")]] proposal {
315119
name proposal_name;
316120
std::vector<char> packed_transaction;
317-
eosio::eosio_msig_binary_extension< std::optional<time_point> > earliest_exec_time;
121+
eosio::binary_extension< std::optional<time_point> > earliest_exec_time;
318122

319123
uint64_t primary_key()const { return proposal_name.value; }
320124
};
321125
typedef eosio::multi_index< "proposal"_n, proposal > proposals;
322126

323-
struct [[eosio::table]] old_approvals_info {
127+
struct [[eosio::table, eosio::contract("eosio.msig")]] old_approvals_info {
324128
name proposal_name;
325129
std::vector<permission_level> requested_approvals;
326130
std::vector<permission_level> provided_approvals;
@@ -334,7 +138,7 @@ namespace eosio {
334138
time_point time;
335139
};
336140

337-
struct [[eosio::table]] approvals_info {
141+
struct [[eosio::table, eosio::contract("eosio.msig")]] approvals_info {
338142
uint8_t version = 1;
339143
name proposal_name;
340144
//requested approval doesn't need to contain time, but we want requested approval
@@ -347,7 +151,7 @@ namespace eosio {
347151
};
348152
typedef eosio::multi_index< "approvals2"_n, approvals_info > approvals;
349153

350-
struct [[eosio::table]] invalidation {
154+
struct [[eosio::table, eosio::contract("eosio.msig")]] invalidation {
351155
name account;
352156
time_point last_invalidation_time;
353157

contracts/eosio.msig/src/eosio.msig.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void multisig::propose( name proposer,
7676
proptable.emplace( proposer, [&]( auto& prop ) {
7777
prop.proposal_name = proposal_name;
7878
prop.packed_transaction = pkd_trans;
79-
prop.earliest_exec_time = std::optional<time_point>{};
79+
prop.earliest_exec_time.emplace();
8080
});
8181

8282
approvals apptable( get_self(), proposer.value );
@@ -131,7 +131,7 @@ void multisig::approve( name proposer, name proposal_name, permission_level leve
131131
auto table_op = [](auto&&, auto&&){};
132132
if( trx_is_authorized(get_approvals_and_adjust_table(get_self(), proposer, proposal_name, table_op), prop.packed_transaction) ) {
133133
proptable.modify( prop, proposer, [&]( auto& p ) {
134-
p.earliest_exec_time = std::optional<time_point>{ current_time_point() + eosio::seconds(trx_header.delay_sec.value)};
134+
p.earliest_exec_time.emplace(time_point{ current_time_point() + eosio::seconds(trx_header.delay_sec.value)});
135135
});
136136
}
137137
}
@@ -171,7 +171,7 @@ void multisig::unapprove( name proposer, name proposal_name, permission_level le
171171
auto table_op = [](auto&&, auto&&){};
172172
if( !trx_is_authorized(get_approvals_and_adjust_table(get_self(), proposer, proposal_name, table_op), prop.packed_transaction) ) {
173173
proptable.modify( prop, proposer, [&]( auto& p ) {
174-
p.earliest_exec_time = std::optional<time_point>{};
174+
p.earliest_exec_time.emplace();
175175
});
176176
}
177177
}

0 commit comments

Comments
 (0)