0

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!

-1

Try this one

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 
    lower_bound: userName,
    upper_bound: userName,
    limit: 100,
  });
  console.log('[getAllReservationsByUser]: response = ', resp);
  return resp.rows;
} catch (err) {
  console.log('[getAllReservationsByUser]: error = ', err);
}}
  • Could you provide some more info about why did you upvote it. What is wrong with the answer in order for me to correct it – Lubo Kirov Dec 2 at 6:55

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.