Class: EthereumContractABI::ContractInterface::Parsers::ContractParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ethereum-contract-abi/contract/parsers/contract_parser.rb

Class Method Summary collapse

Class Method Details

.from_json(json_string) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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