Skip to content

Commit

Permalink
Merge pull request EOSIO#176 from enumivo/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Enumivo authored Jun 1, 2018
2 parents f14e3b3 + 150a10d commit c9dc1ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
9 changes: 6 additions & 3 deletions contracts/enumivo.bios/enumivo.bios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ namespace enumivo {
void setprods( std::vector<enumivo::producer_key> schedule ) {
(void)schedule; // schedule argument just forces the deserialization of the action data into vector<producer_key> (necessary check)
require_auth( _self );
char buffer[action_data_size()];
read_action_data( buffer, sizeof(buffer) ); // should be the same data as enumivo::pack(schedule)
set_proposed_producers(buffer, sizeof(buffer));

constexpr size_t max_stack_buffer_size = 512;
size_t size = action_data_size();
char* buffer = (char*)( max_stack_buffer_size < size ? malloc(size) : alloca(size) );
read_action_data( buffer, size );
set_proposed_producers(buffer, size);
}

void reqauth( action_name from ) {
Expand Down
8 changes: 5 additions & 3 deletions contracts/enumivolib/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ namespace enumivo {
*/
template<typename T>
T unpack_action_data() {
char buffer[action_data_size()];
read_action_data( buffer, sizeof(buffer) );
return unpack<T>( buffer, sizeof(buffer) );
constexpr size_t max_stack_buffer_size = 512;
size_t size = action_data_size();
char* buffer = (char*)( max_stack_buffer_size < size ? malloc(size) : alloca(size) );
read_action_data( buffer, size );
return unpack<T>( buffer, size );
}

using ::require_auth;
Expand Down
14 changes: 8 additions & 6 deletions contracts/enumivolib/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ namespace enumivo {
* @return the indicated action
*/
inline action get_action( uint32_t type, uint32_t index ) {
auto size = ::get_action(type, index, nullptr, 0);
enumivo_assert( size > 0, "get_action size failed" );
char buf[size];
auto size2 = ::get_action(type, index, &buf[0], static_cast<size_t>(size) );
enumivo_assert( size == size2, "get_action failed" );
return enumivo::unpack<enumivo::action>(&buf[0], static_cast<size_t>(size));
constexpr size_t max_stack_buffer_size = 512;
int s = ::get_action( type, index, nullptr, 0 );
enumivo_assert( s > 0, "get_action size failed" );
size_t size = static_cast<size_t>(s);
char* buffer = (char*)( max_stack_buffer_size < size ? malloc(size) : alloca(size) );
auto size2 = ::get_action( type, index, buffer, size );
enumivo_assert( size == static_cast<size_t>(size2), "get_action failed" );
return enumivo::unpack<enumivo::action>( buffer, size );
}

///@} transactioncpp api
Expand Down

0 comments on commit c9dc1ea

Please sign in to comment.