Getting the Error 3160003: Invalid table iterator error while trying to execute:
cleos push action voting.debug debug '[ 0 ]' -p user@active
I have a simple voting contract (full code) where I'm trying to print candidate by id.
Here is a chunk of code which probably doesn't work:
/// @abi action
void debug( uint64_t id ) {
print("Hello, ", name{getcandidate(id)});
}
/// @abi action
account_name getcandidate( uint64_t id ) const {
Candidates candidates( _self, _self );
auto element = candidates.find( id );
return element->name;
}
The struct which is stored in multi-index table candidates:
struct candidate {
uint64_t id;
account_name name;
auto primary_key() const { return id; }
};
...
typedef eosio::multi_index<N(candidates), candidate> Candidates;
Appreciate any help and advice. I'm using eos 1.1.0.