PizzaDAO / pizza-smartcontract

Repository for Rare Pizzas smart contracts
GNU General Public License v3.0
17 stars 4 forks source link

Scan Contracts for Missing Pizzas #86

Open AddressXception opened 1 year ago

AddressXception commented 1 year ago

When a box is redeemed, a series of events fire on-chain that are supposed to be picked up by the server infrastructure for rendering. When a redemption request gets stuck it will appear in the OrderAPIConsumer pendingRequests collection. The contract also emits ChainlinkRequested and ChainlinkFulfilled requests. The pendingRequests can also be thought of as the difference between requested and fulfilled.

In order to propagate the requests through the system, we need to create a few functions that can scan the contract and determine which requests have not yet been fulfilled.

This issue is to create two functions that do the following:

findPendingRequestIds

The findPendingRequests function looks at all log messages emitted from the OrderAPIConsumer contract since it was deployed.

OrderAPIConsumer Deployment Tx

We should filter the events for ChainlinkRequested and ChainlinkFulfilled and extract the requestId from each. We should build an array of requestId that is in the ChainlinkRequested collection but not the ChainlinkFulfilled collection. The collection can be printed out the console so it can be shared externally, but it will be used in the next function.

findPendingRequests

this function should accept the array of requerstIds from the previous function and it should scan the log messages of the oracle contract and filter on the OracleRequest event. The OracleRequest event includes all of the data necessary for the backend services to complete the request.

OrderAPIOracle Deployment Tx

once the collection of oracle requests are found, they should be saved out in json format to be parsed by the backend services.

The data structure should follow the structure of the request, including a named parameter for each parameter in the event call, and a data buffer for the data field. The data field is encoded as CBOR and should be decoded in the json file so it can be easily read by a human and parsed by the server. We are most interested int he token id and the recipe id in the request, but we need the other metadata to hash back so that the oracle contract will accept the response after the pizza is rendered.

Implementation details

These functions should be stored in this repository, they should be written in typescript, and they should not have any dependencies on the hardhat ecosystem because we intend to reuse them as part of a node.js blockchain follower in a separate ticket.

Acceptance Criteria

  1. a list of pending requests and all of the corresponding data is exported for easy consumption by an arbitrary REST API.
  2. there are clear test steps in the pull request and there is a demonstration of how it wokrs