This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
Remove OrderWatcher in-memory state #905
Labels
tech debt
A code quality issue is not urgent but could cause problems down the line if not addressed
The switch from LevelDB to using SQL and Dexie.js makes it possible to remove all in-memory state from
orderwatch.Watcher
. There are currently still some pieces of in-memory state remaining.addAssetDataAddressToEventDecoder
adds an entry toknownERC20Addresses
,knownERC721Addresses
, etc. insidedecoder.Decoder
. This was designed to tackle a specific problem: we need to know the contract ABI (depends on the type of the token) in order to properly decode contract events, but some events have the same signature and cannot be easily differentiated. To solve this problem, we keep track of every unique asset data that we see and store the token type (based on the asset data prefix) in a map. A different way to work around this problem is to sequentially try to decode the event for each token type (e.g. ERC20, ERC721, ERC1155), until we find one that decodes without an error. This would allow us to eliminate some complicated and error-prone code that maintains the map of asset data to token type.Currently,
Decoder.Decode
looks like this:It can be re-written to something like this:
knownERC20Addresses
,knownERC721Addresses
, etc. are also used inhandleBlockEvents
to find orders in the database that were potentially affected by a given event. Specifically, the logic takes place inDecoder.FindEventType
. Instead of using a map of asset data to token type here, we can leverage the new database features to simply query for each possible token type/asset data prefix. To do this efficiently, we may need to combine one or more query. So for example if we cannot determine the token type based on the event itself, but we know the token address, we first look for orders with the asset dataerc20AssetDataPrefix + tokenAddress
, then we look for orders with the asset dataerc721AssetDataPrefix + tokenAddress
, and so on.The text was updated successfully, but these errors were encountered: