2
auto chain_plug = app().find_plugin<chain_plugin>();
eosio::chain_apis::read_only::get_table_by_scope_params param{N("eosio.token"), N("stat"), "EOS", "EOS", 1};
auto result = chain_plug->get_read_only_api().get_table_by_scope(param);
auto count = result.rows[0].count;

the nodeos just abort when runing above code,any way to get the table rows in plugin ?

0

The class get_table_by_scope_result is structured like this:

   struct get_table_by_scope_result {
      vector<get_table_by_scope_result_row> rows;
      string      more; ///< fill lower_bound with this value to fetch more rows
   };

So if you want to access the count for a particular scope, then you are doing it the correct way by saying result.rows[0].count, which will give you the number of rows in the first scope of the table.

I imagine the reason why you are getting an abort is because rows[0] doesn't exist, and then you are trying to deference a null pointer.

So trying wrapping your code like this:

uint32_t count(0);
if(!result.rows.empty())
{
  count = result.rows.at(0).count;
}

If you still get the error, then maybe post a bit more detail, and show or check that the stat table exists with the correct scope and rows as expected using something like cleos get table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.