Class: BlockGiven::Abi::CustomError

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

Overview

Solidity custom error (error InsufficientBalance(uint256 available, uint256 required)).

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#inputsObject (readonly)

Returns the value of attribute inputs.



7
8
9
# File 'lib/block_given/abi/custom_error.rb', line 7

def inputs
  @inputs
end

#nameObject (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

#inspectObject



26
# File 'lib/block_given/abi/custom_error.rb', line 26

def inspect = "#<BlockGiven::Abi::CustomError #{signature}>"

#selectorObject



16
# File 'lib/block_given/abi/custom_error.rb', line 16

def selector = @selector ||= Utils.keccak256(signature)[0, 10]

#signatureObject



15
# File 'lib/block_given/abi/custom_error.rb', line 15

def signature = "#{name}(#{inputs.map(&:type).join(',')})"