onflow / kitty-items

Kitty Items: CryptoKitties Sample App
https://kitty-items.onflow.org
Apache License 2.0
409 stars 214 forks source link

bug: unable to list newly purchased kittyitem #254

Closed MrDSGC closed 2 years ago

MrDSGC commented 2 years ago
MrDSGC commented 2 years ago

Looks really good! Very clean code ✨

I'm still worried about another edge case (copied below from a previous message). However, I think we should verify + fix that case in a separate PR.

Example scenario:

  • ListingAvailable event is detected in block 19.
  • This calls StorefrontService.addListing, which in turn executes the get_listing_item.cdc Cadence script on the emulator. It calls this script because it only has the listing ID -- it needs more information about the listing to insert into the database.
  • This uses fcl.query, which by default executes the script against the state from the current latest block.
  • The kicker is: by this point, the latest block is 20, which is the block at which that listing was removed. The script returns empty because the listing no longer exists at that version of the blockchain state.

So if this is a problem (I'm just guessing at this point), one possible solution would be to make the event processors "block height aware". i.e. If a ListingAvailable event is detected at block 19, then the script to fetch the listing is also executed at block 19.

new ticket to address this created https://app.zenhub.com/workspaces/flow-developer-experience-6052fcad2959f80011fda14b/issues/onflow/kitty-items/259