diff --git a/contracts/eoslib/chain.h b/contracts/eoslib/chain.h index a15e6f4d463fe1b0a0fd1b341ec70d57c8e9a1af..af3757235387a7e957658e003aa80f57036954cc 100644 --- a/contracts/eoslib/chain.h +++ b/contracts/eoslib/chain.h @@ -21,19 +21,19 @@ extern "C" { /** - * @brief Return the set of active producers - * @details Return the set of active producers - * - * @param producers - location to store the active producers + * Return the set of active producers + * @param producers - a pointer to an buffer of account_names + * @param datalen - byte length of buffer + * @return the number of bytes actually populated * * Example: * @code * account_name producers[21]; - * get_active_producers(producers, sizeof(account_name)*21); + * uint32_t bytes_populated = get_active_producers(producers, sizeof(account_name)*21); * @endcode */ - void get_active_producers( account_name* producers, uint32_t datalen ); + uint32_t get_active_producers( account_name* producers, uint32_t datalen ); ///@ } chaincapi } diff --git a/libraries/chain/apply_context.cpp b/libraries/chain/apply_context.cpp index 54c68ccc385295bd82dd7a589b8ccc0dc7967954..e0fbeb3a1549450bf11a15dba620d0a523a4cc88 100644 --- a/libraries/chain/apply_context.cpp +++ b/libraries/chain/apply_context.cpp @@ -224,15 +224,16 @@ const contracts::table_id_object& apply_context::find_or_create_table( name scop }); } -void apply_context::get_active_producers(account_name* producers, size_t datalen) { +size_t apply_context::get_active_producers(account_name* producers, size_t len) { const auto& gpo = controller.get_global_properties(); int index = 0; for(const auto& producer : gpo.active_producers.producers) { *(producers + index) = producer.producer_name; - if (++index >= datalen) + if (++index >= len) break; } + return index; } } } /// eosio::chain diff --git a/libraries/chain/include/eosio/chain/apply_context.hpp b/libraries/chain/include/eosio/chain/apply_context.hpp index eaf67dc9b5b9fc78a8732776dd2a859b2df1709d..06c6d5c4e4a19bde6d2eb8b62eb5dcaae1e47680 100644 --- a/libraries/chain/include/eosio/chain/apply_context.hpp +++ b/libraries/chain/include/eosio/chain/apply_context.hpp @@ -94,7 +94,7 @@ class apply_context { bool all_authorizations_used()const; vector unused_authorizations()const; - void get_active_producers(account_name* producers, size_t len); + size_t get_active_producers(account_name* producers, size_t len); const chain_controller& controller; const chainbase::database& db; ///< database where state is stored diff --git a/libraries/chain/wasm_interface.cpp b/libraries/chain/wasm_interface.cpp index 4e5df22df94b13c29c219d8d3971edc91721948d..468d392f323641e6dedd3e3fdd2bf2e16c77d905 100644 --- a/libraries/chain/wasm_interface.cpp +++ b/libraries/chain/wasm_interface.cpp @@ -448,8 +448,9 @@ class producer_api : public context_aware_api { public: using context_aware_api::context_aware_api; - void get_active_producers(array_ptr producers, size_t datalen) { - context.get_active_producers(producers, datalen); + int get_active_producers(array_ptr producers, size_t datalen) { + auto actual_num_prod = context.get_active_producers(producers, datalen / sizeof(chain::account_name)); + return actual_num_prod * sizeof(chain::account_name); } }; @@ -742,7 +743,7 @@ class transaction_api : public context_aware_api { }; REGISTER_INTRINSICS(producer_api, - (get_active_producers, void(int, int)) + (get_active_producers, int(int, int)) ); REGISTER_INTRINSICS(crypto_api,