Class: BlockGiven::Abi::CustomError
- Inherits:
-
Object
- Object
- BlockGiven::Abi::CustomError
- Defined in:
- lib/block_given/abi/custom_error.rb
Overview
Solidity custom error (error InsufficientBalance(uint256 available, uint256 required)).
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#decode(revert_data) ⇒ Object
Returns a Hash of decoded arguments keyed by snake_case names.
-
#initialize(definition) ⇒ CustomError
constructor
A new instance of CustomError.
- #inspect ⇒ Object
- #selector ⇒ Object
- #signature ⇒ Object
Constructor Details
#initialize(definition) ⇒ CustomError
Returns a new instance of CustomError.
9 10 11 12 13 |
# File 'lib/block_given/abi/custom_error.rb', line 9 def initialize(definition) definition = definition.transform_keys(&:to_s) @name = definition["name"].to_s @inputs = Array(definition["inputs"]).each_with_index.map { |i, idx| Parameter.new(i, index: idx) } end |
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
7 8 9 |
# File 'lib/block_given/abi/custom_error.rb', line 7 def inputs @inputs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/block_given/abi/custom_error.rb', line 7 def name @name end |
Instance Method Details
#decode(revert_data) ⇒ Object
Returns a Hash of decoded arguments keyed by snake_case names.
19 20 21 22 23 24 |
# File 'lib/block_given/abi/custom_error.rb', line 19 def decode(revert_data) payload = "0x#{Utils.strip_hex(revert_data)[8..]}" return {} if inputs.empty? inputs.map(&:ruby_name).zip(Coder.decode(inputs, payload)).to_h end |
#inspect ⇒ Object
26 |
# File 'lib/block_given/abi/custom_error.rb', line 26 def inspect = "#<BlockGiven::Abi::CustomError #{signature}>" |
#selector ⇒ Object
16 |
# File 'lib/block_given/abi/custom_error.rb', line 16 def selector = @selector ||= Utils.keccak256(signature)[0, 10] |
#signature ⇒ Object
15 |
# File 'lib/block_given/abi/custom_error.rb', line 15 def signature = "#{name}(#{inputs.map(&:type).join(',')})" |