- 
                Notifications
    You must be signed in to change notification settings 
- Fork 384
Closed
subquery/subql-ethereum
#397Labels
Description
Description
We allow user put event definition in the topic0 filter, and then encode it via keccak256. It worked well except for custom types in the event parameters.
- enum type
- custom struct
Details
We will need to load the abi to understand what kind the custom type is.
- For enum, we need to replace it to uint8
- For struct we need to replace it with nested form of basic type tuples. see here
- For unknown type, we can warn user and exit.
Example
Smart Contract
Sample code that shows an enum and struct in events
struct MoreData
{
        bytes32 id1;
        bytes32 id2;
}
enum DisputeType {
        POI,
        Query
    }
event Deposit(
        address indexed _from,
        bytes32 indexed _id,
        uint _value,
        MoreData _moreData
    );
event DisputeOpen(
        uint256 indexed disputeId,
        address fisherman,
        address runner,
        DisputeType _type
    );
A snippet of a subquery manifest with the desired filters
options:
      abi: disputeManager
      address: '0xd82a8f11645f6FEF2b863CEe19755bA22decD42a'
    mapping:
      file: ./dist/index.js
      handlers:
        - handler: handleDisputeOpen
          kind: ethereum/LogHandler
          filter:
            topics:
              # DisputeType should be resolved to uint8 before keccak256 encoding
              - DisputeOpen(uint256 indexed disputeId, address fisherman, address indexer, DisputeType _type)
        - handler: handleDeposit
          kind: ethereum/LogHandler
          filter:
            topics:
              # MoreData  should be resolved to (bytes32, bytes32) before keccak256 encoding
              - Deposit(address indexed _from, bytes32 indexed _id, uint _value, MoreData _moreData)Other requirements
- Documentation should be updated to include the feature
- Changes should have test coverage of 80% on the relevant code changes