aavegotchi / aavegotchi-realm-diamond

23 stars 9 forks source link

getCraftQueue() reverts #12

Closed mudgen closed 2 years ago

mudgen commented 2 years ago

The getCraftQueue() function will revert when called because no QueueItem[] value with length is assigned to the output_ variable. https://github.com/aavegotchi/aavegotchi-realm-diamond/blob/cee38d37307c49dc41cdb737a962d5d313c1cd4f/contracts/InstallationDiamond/facets/InstallationFacet.sol#L455-L463

This would work:

 function getCraftQueue(address _owner) external view returns (QueueItem[] memory output_) { 
   uint256 length = s.craftQueue.length;
   output_ = new QueueItem[](length);
   uint256 counter; 
   for (uint256 i; i < length; i++) { 
     if (s.craftQueue[i].owner == _owner) { 
       output_[counter] = s.craftQueue[i];        
       counter++; 
     }        
   }
   assembly {
      mstore(output_, counter)
   }
 } 
mudgen commented 2 years ago

Good