web3-core#Log TypeScript Examples

The following examples show how to use web3-core#Log. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Logs.ts    From perpetual with Apache License 2.0 6 votes vote down vote up
private parseLog(log: Log): any {
    const logAddress = log.address.toLowerCase();

    // Check if the logs are coming from the proxy ABI.
    if (addressesAreEqual(logAddress, this.contracts.perpetualProxy.options.address)) {
      const parsedLog = this.parseLogWithContract(this.contracts.perpetualProxy, log);
      if (parsedLog) {
        return parsedLog;
      }
    }

    // PBTC-USDC: Check if the logs are coming from old contracts.
    if (this.contracts.market === PerpetualMarket.PBTC_USDC) {
      if (OLD_LIQUIDATION_ADDRESSES.includes(logAddress.toLowerCase())) {
        const parsedLog = this.parseLogWithContract(this.contracts.p1Liquidation, log);
        if (parsedLog) {
          return parsedLog;
        }
      }
      if (OLD_LIQUIDATOR_PROXY_ADDRESSES.includes(logAddress.toLowerCase())) {
        const parsedLog = this.parseLogWithContract(this.contracts.p1LiquidatorProxy, log);
        if (parsedLog) {
          return parsedLog;
        }
      }
    }

    if (logAddress in this.contractsByAddress) {
      return this.parseLogWithContract(this.contractsByAddress[logAddress], log);
    }

    return null;
  }
Example #2
Source File: Logs.ts    From perpetual with Apache License 2.0 6 votes vote down vote up
private parseLogWithContract(contract: Contract, log: Log): any {
    const events = contract.options.jsonInterface.filter(
      (e: AbiItem) => e.type === 'event',
    );

    const eventJson = events.find(
      (e: any) => e.signature.toLowerCase() === log.topics[0].toLowerCase(),
    );

    if (!eventJson) {
      return null;
    }

    const eventArgs = this.web3.eth.abi.decodeLog(
      eventJson.inputs,
      log.data,
      log.topics.slice(1),
    );

    return {
      ...log,
      name: eventJson.name,
      args: this.parseArgs(eventJson.inputs, eventArgs),
    };
  }