Eos: a simple question~Why are the method return values all void?

Created on 28 Aug 2018  路  3Comments  路  Source: EOSIO/eos

struct bal_detail {
      uint64_t id;
      account_name user_account;
      account_name com_account;
      uint128_t balance;
      uint128_t frozen_balance;
      bool is_fronzen;

      auto primary_key()const { return id; }
      account_name get_user_name()const { return user_account; }
      EOSLIB_SERIALIZE( bal_detail, (id)(user_account)(com_account)(balance)(frozen_balance)(is_fronzen) )
};

    typedef eosio::multi_index<N(bal_detail), bal_detail, indexed_by<N(by_user_name), const_mem_fun<bal_detail, account_name, &bal_detail::get_user_name> > > balance_detail_index;
public:
        uint_128_t get_balance( const account_name account )
        {
             ......
             return balance;
        }

I tried to define a method with a return value of uint128_t in the public of the class but failed. If there is no way to define a method with a return value, how can I query the custom structure data?

Most helpful comment

You just can't. Return values are not allowed in contract actions.

If you need to query data on other contracts, use the multi_index or singleton construct instead, with the code parameter set to the target contract instead of _self. Then, query the table like you would with your own tables.

All 3 comments

You just can't. Return values are not allowed in contract actions.

If you need to query data on other contracts, use the multi_index or singleton construct instead, with the code parameter set to the target contract instead of _self. Then, query the table like you would with your own tables.

@xJonathanLEI thanks
In this case, can the scope and code of multi_index be set to owner? It is the _self of the deployment contract because I don't seem to have different code requirements.

This is the current design. You can put the resulting information into the multi_index table if you really need it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IvanYakimov picture IvanYakimov  路  3Comments

christola picture christola  路  3Comments

yashbhavsar007 picture yashbhavsar007  路  3Comments

toonsevrin picture toonsevrin  路  3Comments

ResponsiveWebApps picture ResponsiveWebApps  路  3Comments