提交 6e813776 编写于 作者: B Brian Johnson

Fixed get_active_producers for c API passing buffer byte length and added...

Fixed get_active_producers for c API passing buffer byte length and added returning the number of bytes written, so user knows how many bytes were populated.
上级 7c7b4d3d
...@@ -21,19 +21,19 @@ ...@@ -21,19 +21,19 @@
extern "C" { extern "C" {
/** /**
* @brief Return the set of active producers * Return the set of active producers
* @details Return the set of active producers * @param producers - a pointer to an buffer of account_names
* * @param datalen - byte length of buffer
* @param producers - location to store the active producers * @return the number of bytes actually populated
* *
* Example: * Example:
* @code * @code
* account_name producers[21]; * 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 * @endcode
*/ */
void get_active_producers( account_name* producers, uint32_t datalen ); uint32_t get_active_producers( account_name* producers, uint32_t datalen );
///@ } chaincapi ///@ } chaincapi
} }
...@@ -224,15 +224,16 @@ const contracts::table_id_object& apply_context::find_or_create_table( name scop ...@@ -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(); const auto& gpo = controller.get_global_properties();
int index = 0; int index = 0;
for(const auto& producer : gpo.active_producers.producers) for(const auto& producer : gpo.active_producers.producers)
{ {
*(producers + index) = producer.producer_name; *(producers + index) = producer.producer_name;
if (++index >= datalen) if (++index >= len)
break; break;
} }
return index;
} }
} } /// eosio::chain } } /// eosio::chain
...@@ -94,7 +94,7 @@ class apply_context { ...@@ -94,7 +94,7 @@ class apply_context {
bool all_authorizations_used()const; bool all_authorizations_used()const;
vector<permission_level> unused_authorizations()const; vector<permission_level> 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 chain_controller& controller;
const chainbase::database& db; ///< database where state is stored const chainbase::database& db; ///< database where state is stored
......
...@@ -448,8 +448,9 @@ class producer_api : public context_aware_api { ...@@ -448,8 +448,9 @@ class producer_api : public context_aware_api {
public: public:
using context_aware_api::context_aware_api; using context_aware_api::context_aware_api;
void get_active_producers(array_ptr<chain::account_name> producers, size_t datalen) { int get_active_producers(array_ptr<chain::account_name> producers, size_t datalen) {
context.get_active_producers(producers, 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 { ...@@ -742,7 +743,7 @@ class transaction_api : public context_aware_api {
}; };
REGISTER_INTRINSICS(producer_api, REGISTER_INTRINSICS(producer_api,
(get_active_producers, void(int, int)) (get_active_producers, int(int, int))
); );
REGISTER_INTRINSICS(crypto_api, REGISTER_INTRINSICS(crypto_api,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册