I have a smart contract that has a multi-index table called reservations - account, time, date, entity. From the code I am trying to use get_table_rows to get all reservations related to a given account. The problem is, with the rpc call that I am using I get all possible reservations not only the ones that are related to a given user. So, my questions are:
- How can I achieve my goal in the most optimized way with the current implementation?
- Do I need a second index in the reservations table?
- If yes, would I be able to use it in the way I described above?
static async getAllReservationsByUser(reservationAccount) {
try {
// const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch });
const resp = await rpc.get_table_rows({
json: true,
code: EOS_ACCOUNT, // contract who owns the table
scope: EOS_ACCOUNT, // scope of the table
table: 'reservations', // name of the table as specified by the contract
table_key: 'reservationAccount',
// lower_bound: userName,
limit: 100,
});
console.log('[getAllReservationsByUser]: response = ', resp);
return resp.rows;
} catch (err) {
console.log('[getAllReservationsByUser]: error = ', err);
}}
Thanks!