class EthereumContractABI::ContractInterface::Parsers::ContractParser

Public Class Methods

from_json(json_string) click to toggle source
# File lib/ethereum-contract-abi/contract/parsers/contract_parser.rb, line 11
def self.from_json(json_string)
  parsed = JSON.parse(json_string)
  functions = parsed.select { |interface| interface["type"] === "function"}
    .map { |f_hash| f_hash.transform_keys(&:to_sym) }
    .filter_map do |f_hash|
      begin
        FunctionParser.from_hash(f_hash)
      rescue ArgumentError
        # Error parsing contract function, all ABI types are not yet implemented
        nil
      end
    end
  events = parsed.select { |interface| interface["type"] === "event"}
  EthereumContractABI::Contract.new(functions, events)
end