Солидность: возвращает отфильтрованный массив структур без 'pu sh' - PullRequest
1 голос
/ 10 марта 2020

У меня есть этот контракт с массивом структур:

pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;

contract Tickets {
  struct Ticket {
    uint id;
    int val;
  }

  Ticket[] tickets;

  function addTicket(uint id, int val) public returns(bool success) {
    Ticket memory newTicket;
    newTicket.id = id;
    newTicket.val = val;
    tickets.push(newTicket);

    return true;
  }

  function getTicket(uint id) public view returns(Ticket memory) {
    uint index;

    for(uint i = 0; i<tickets.length; i++){
      if (tickets[i].id == id) {
        index = i;
        break;
      }
    }

    Ticket memory t = tickets[index];

    return t;
  }

  function findTickets(int val) public view returns(Ticket[] memory) {
    Ticket[] memory result;

    for(uint i = 0; i<tickets.length; i++){
      if (tickets[i].val == val) {
        result.push(tickets[i]); // HERE IS THE ERROR
      }
    }

    return result;
  }
}

Мне нужно вернуть отфильтрованный по val массив, но когда я строю этот код: result.push(tickets[i].id); он выдает эту ошибку:

TypeError: Member "push" is not available in struct Tickets.Ticket memory[] memory outside of storage.

Как реализовать фильтр без использования push?

...