enviodev / hypersync-client-node

Mozilla Public License 2.0
17 stars 1 forks source link

feat: Allow 0x0000000000000000000000000000000000000000 to act as a wi… #10

Closed richtera closed 2 months ago

richtera commented 2 months ago

In order to get this to work inside of the envio indexer you have to currently set the address to 0x00000000, but then also modify the following routine inside of the generated code. Obviously this will be slightly different for different instances, but the generator could add the || ... section automatically.

function convertDecodedEvent(
  $$event,
  contractInterfaceManager,
  log,
  blockTimestamp,
  chainId,
  txOrigin
) {
  var contractName =
    ContractInterfaceManager.getContractNameFromAddress(
      contractInterfaceManager,
      log.address
    ) || // BEGIN: THIS SECTION ADDED TO READ THE WILDCARD CONTRACT IN ADDITION.
    ContractInterfaceManager.getContractNameFromAddress(
      contractInterfaceManager,
      "0x0000000000000000000000000000000000000000"
    ); // END: THIS SECTION ADDED TO READ THE WILDCARD CONTRACT IN ADDITION.
  if (contractName === undefined) {
    return {
      TAG: "Error",
      _0: {
        RE_EXN_ID: UnregisteredContract,
        _1: log.address,
      },
    };
  }
  var match = Types.eventTopicToEventName(
    contractName,
    Caml_array.get(log.topics, 0)
  );
  var $$event$1;
  $$event$1 =
    match === "LSPData_DataChanged"
      ? {
          TAG: "LSPDataContract_DataChanged",
          _0: makeEventLog(
            convertDataChangedDecodedEventParams($$event),
            log,
            blockTimestamp,
            chainId,
            txOrigin
          ),
        }
      : {
          TAG: "LSPDataContract_TokenIdDataChanged",
          _0: makeEventLog(
            convertTokenIdDataChangedDecodedEventParams($$event),
            log,
            blockTimestamp,
            chainId,
            txOrigin
          ),
        };
  return {
    TAG: "Ok",
    _0: $$event$1,
  };
}
ozgrakkurt commented 2 months ago

@richtera thanks!! Merged as temporary solution but I'll try to add a explicit option for adding a fallback abi for unknown addresses