Class: Platon::Abi

Inherits:
Object
  • Object
show all
Defined in:
lib/platon/abi.rb

Class Method Summary collapse

Class Method Details

.parse_abi(abi) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/platon/abi.rb', line 4

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

.parse_array_type(type) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/platon/abi.rb', line 22

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

.parse_type(type) ⇒ Object

Raises:

  • (NotImplementedError)


16
17
18
19
20
# File 'lib/platon/abi.rb', line 16

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