class Eth::Abi::Type
def parse(type, components = nil, component_name = nil)
-
(ParseError)
- if it fails to parse the type.
Returns:
-
(Eth::Abi::Type)
- a parsed Type object.
Parameters:
-
component_name
(String
) -- the tuple component's name. -
components
(Array
) -- the components attribute. -
type
(String
) -- a common Solidity type.
def parse(type, components = nil, component_name = nil) return type if type.is_a?(Type) _, base_type, sub_type, dimension = /([a-z]*)([0-9]*x?[0-9]*)((\[[0-9]*\])*)/.match(type).to_a # type dimension can only be numeric dims = dimension.scan(/\[[0-9]*\]/) raise ParseError, "Unknown characters found in array declaration" if dims.join != dimension # enforce base types validate_base_type base_type, sub_type # return a new Type (using konstructor) sub_type = sub_type.to_s @base_type = base_type @sub_type = sub_type @dimensions = dims.map { |x| x[1...-1].to_i } @components = components.map { |component| Abi::Type.parse(component["type"], component.dig("components"), component.dig("name")) } unless components.nil? @name = component_name end