Class: BlockGiven::Abi::Parameter
- Inherits:
-
Object
- Object
- BlockGiven::Abi::Parameter
- Defined in:
- lib/block_given/abi/parameter.rb
Overview
One ABI input/output. Knows its canonical Solidity type ("(uint256,address)[]").
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#indexed ⇒ Object
readonly
Returns the value of attribute indexed.
-
#internal_type ⇒ Object
readonly
Returns the value of attribute internal_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raw_type ⇒ Object
readonly
Returns the value of attribute raw_type.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #dynamic? ⇒ Boolean
-
#element ⇒ Object
Base type without the outermost array dimension.
- #indexed? ⇒ Boolean
-
#initialize(definition, index: 0) ⇒ Parameter
constructor
A new instance of Parameter.
- #ruby_name ⇒ Object
- #to_h ⇒ Object
- #tuple? ⇒ Boolean
-
#type ⇒ Object
"tuple" with components -> "(uint256,address)[]".
- #unnamed? ⇒ Boolean
Constructor Details
#initialize(definition, index: 0) ⇒ Parameter
Returns a new instance of Parameter.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/block_given/abi/parameter.rb', line 9 def initialize(definition, index: 0) definition = definition.transform_keys(&:to_s) @name = definition["name"].to_s @name = "arg#{index}" if @name.empty? @unnamed = definition["name"].to_s.empty? @raw_type = definition["type"].to_s @indexed = definition["indexed"] ? true : false @internal_type = definition["internalType"] @components = Array(definition["components"]).each_with_index.map { |c, i| Parameter.new(c, index: i) } end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
7 8 9 |
# File 'lib/block_given/abi/parameter.rb', line 7 def components @components end |
#indexed ⇒ Object (readonly)
Returns the value of attribute indexed.
7 8 9 |
# File 'lib/block_given/abi/parameter.rb', line 7 def indexed @indexed end |
#internal_type ⇒ Object (readonly)
Returns the value of attribute internal_type.
7 8 9 |
# File 'lib/block_given/abi/parameter.rb', line 7 def internal_type @internal_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/block_given/abi/parameter.rb', line 7 def name @name end |
#raw_type ⇒ Object (readonly)
Returns the value of attribute raw_type.
7 8 9 |
# File 'lib/block_given/abi/parameter.rb', line 7 def raw_type @raw_type end |
Instance Method Details
#array? ⇒ Boolean
25 |
# File 'lib/block_given/abi/parameter.rb', line 25 def array? = raw_type.end_with?("]") |
#dynamic? ⇒ Boolean
44 45 46 47 |
# File 'lib/block_given/abi/parameter.rb', line 44 def dynamic? raw_type == "string" || raw_type == "bytes" || raw_type.end_with?("[]") || (tuple? && components.any?(&:dynamic?)) || (array? && element.dynamic?) end |
#element ⇒ Object
Base type without the outermost array dimension.
35 36 37 38 39 40 41 42 |
# File 'lib/block_given/abi/parameter.rb', line 35 def element return nil unless array? Parameter.new( { "name" => name, "type" => raw_type.sub(/\[\d*\]\z/, ""), "components" => components.map(&:to_h) } ) end |
#indexed? ⇒ Boolean
21 |
# File 'lib/block_given/abi/parameter.rb', line 21 def indexed? = indexed |
#ruby_name ⇒ Object
22 |
# File 'lib/block_given/abi/parameter.rb', line 22 def ruby_name = Utils.snake_case(name).to_sym |
#to_h ⇒ Object
49 50 51 52 53 54 |
# File 'lib/block_given/abi/parameter.rb', line 49 def to_h h = { "name" => unnamed? ? "" : name, "type" => raw_type } h["components"] = components.map(&:to_h) if tuple? h["indexed"] = indexed if indexed h end |
#tuple? ⇒ Boolean
24 |
# File 'lib/block_given/abi/parameter.rb', line 24 def tuple? = raw_type.start_with?("tuple") |
#type ⇒ Object
"tuple" with components -> "(uint256,address)[]"
28 29 30 31 32 |
# File 'lib/block_given/abi/parameter.rb', line 28 def type return raw_type unless tuple? raw_type.sub("tuple", "(#{components.map(&:type).join(',')})") end |
#unnamed? ⇒ Boolean
20 |
# File 'lib/block_given/abi/parameter.rb', line 20 def unnamed? = @unnamed |