web3-utils#AbiInput TypeScript Examples

The following examples show how to use web3-utils#AbiInput. 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: EventBuilder.ts    From compound-protocol with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
function buildArg(contractName: string, name: string, input: AbiInput): Arg<Value> {
  let { getter } = typeMappings()[input.type] || {};

  if (!getter) {
    throw new Error(`Unknown ABI Input Type: ${input.type} of \`${name}\` in ${contractName}`);
  }

  return new Arg(name, getter);
}
Example #2
Source File: Logs.ts    From perpetual with Apache License 2.0 5 votes vote down vote up
private parseArgs(inputs: AbiInput[], eventArgs: any): any {
    const parsedObject: any = {};
    for (const input of inputs) {
      const { name } = input;
      parsedObject[name] = this.parseValue(input, eventArgs[name]);
    }
    return parsedObject;
  }
Example #3
Source File: Logs.ts    From perpetual with Apache License 2.0 5 votes vote down vote up
private parseValue(input: AbiInput, argValue: any): any {
    if (input.type === 'bytes32') {
      switch (input.name) {
        case 'balance':
        case 'makerBalance':
        case 'takerBalance':
          return this.parseBalance(argValue);
        case 'index':
          return this.parseIndex(argValue);
        case 'flags':
          return this.parseOrderFlags(argValue);
        case 'fundingRate':
          return this.parseFundingRate(argValue);
      }
    }

    if (input.type === 'uint256') {
      switch (input.name) {
        case 'fee':
          return Fee.fromSolidity(argValue);
        case 'price':
        case 'oraclePrice':
        case 'settlementPrice':
        case 'triggerPrice':
          return Price.fromSolidity(argValue);
      }
    }

    if (input.type === 'address') {
      return argValue;
    }
    if (input.type === 'bool') {
      return argValue;
    }
    if (input.type.match(/^bytes[0-9]*$/)) {
      return argValue;
    }
    if (input.type.match(/^uint[0-9]*$/)) {
      return new BigNumber(argValue);
    }
    if (input.type === 'tuple') {
      return this.parseTuple(input, argValue);
    }
    throw new Error(`Unknown event arg type ${input.type}`);
  }