Sha256: 67bf6f43adc20e120b12f2a0a3edc6f3f690e4a13778de0d62ca247d00886b9e

Contents?: true

Size: 946 Bytes

Versions: 4

Compression:

Stored size: 946 Bytes

Contents

module Platon
  class Abi

    def self.parse_abi(abi)
      constructor = abi.detect {|x| x["type"] == "constructor"}
      if constructor.present?
        constructor_inputs = constructor["inputs"].map { |input| Platon::FunctionInput.new(input) }
      else
        constructor_inputs = []
      end
      functions = abi.select {|x| x["type"] == "function" }.map { |fun| Platon::Function.new(fun) }
      events = abi.select {|x| x["type"] == "event" }.map { |evt| Platon::ContractEvent.new(evt) }
      [constructor_inputs, functions, events]
    end

    def self.parse_type(type)
      raise NotImplementedError if type.ends_with?("]")
      match = /(\D+)(\d.*)?/.match(type)
      [match[1], match[2]]
    end

    def self.parse_array_type(type)
      match = /(.+)\[(\d*)\]\z/.match(type)
      if match
        [true, match[2].present? ? match[2].to_i : nil, match[1]]
      else
        [false, nil, nil]
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
platon-1.0.1 lib/platon/abi.rb
platon-1.0.0 lib/platon/abi.rb
platon-0.2.9 lib/platon/abi.rb
platon-0.2.7 lib/platon/abi.rb