Exception: BlockGiven::ContractRevertError
- Defined in:
- lib/block_given/errors.rb
Overview
eth_call / eth_estimateGas / eth_sendRawTransaction rejected by the EVM.
Constant Summary collapse
- ERROR_STRING_SELECTOR =
"0x08c379a0"- PANIC_SELECTOR =
"0x4e487b71"- PANIC_REASONS =
{ 0x00 => "generic compiler inserted panic", 0x01 => "assertion failed", 0x11 => "arithmetic overflow or underflow", 0x12 => "division or modulo by zero", 0x21 => "invalid enum conversion", 0x22 => "incorrectly encoded storage byte array", 0x31 => "pop() on an empty array", 0x32 => "array index out of bounds", 0x41 => "too much memory allocated or array too large", 0x51 => "call to a zero-initialized variable of internal function type" }.freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#error_name ⇒ Object
readonly
Returns the value of attribute error_name.
-
#revert_data ⇒ Object
readonly
Returns the value of attribute revert_data.
Attributes inherited from RpcError
Instance Method Summary collapse
- #custom_error? ⇒ Boolean
-
#decode_with(interface) ⇒ Object
Returns a copy of this error enriched with a custom error decoded from the given ABI interface, or self when the interface does not know the selector.
-
#initialize(message, code: nil, data: nil, rpc_method: nil, revert_data: nil, error_name: nil, args: nil) ⇒ ContractRevertError
constructor
A new instance of ContractRevertError.
-
#reason ⇒ Object
Human readable revert reason when it can be decoded (Error(string) / Panic).
- #selector ⇒ Object
Methods inherited from RpcError
extract_revert_data, from_payload
Constructor Details
#initialize(message, code: nil, data: nil, rpc_method: nil, revert_data: nil, error_name: nil, args: nil) ⇒ ContractRevertError
Returns a new instance of ContractRevertError.
85 86 87 88 89 90 |
# File 'lib/block_given/errors.rb', line 85 def initialize(, code: nil, data: nil, rpc_method: nil, revert_data: nil, error_name: nil, args: nil) @revert_data = revert_data @error_name = error_name @args = args super((), code: code, data: data, rpc_method: rpc_method) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
83 84 85 |
# File 'lib/block_given/errors.rb', line 83 def args @args end |
#error_name ⇒ Object (readonly)
Returns the value of attribute error_name.
83 84 85 |
# File 'lib/block_given/errors.rb', line 83 def error_name @error_name end |
#revert_data ⇒ Object (readonly)
Returns the value of attribute revert_data.
83 84 85 |
# File 'lib/block_given/errors.rb', line 83 def revert_data @revert_data end |
Instance Method Details
#custom_error? ⇒ Boolean
103 104 105 |
# File 'lib/block_given/errors.rb', line 103 def custom_error? !selector.nil? && ![ERROR_STRING_SELECTOR, PANIC_SELECTOR].include?(selector) end |
#decode_with(interface) ⇒ Object
Returns a copy of this error enriched with a custom error decoded from the given ABI interface, or self when the interface does not know the selector.
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/block_given/errors.rb', line 109 def decode_with(interface) return self unless custom_error? && interface custom = interface.error_by_selector(selector) return self unless custom decoded = custom.decode(revert_data) self.class.new( "#{custom.name}(#{decoded.values.map(&:inspect).join(', ')})", code: code, data: data, rpc_method: rpc_method, revert_data: revert_data, error_name: custom.name, args: decoded ) end |
#reason ⇒ Object
Human readable revert reason when it can be decoded (Error(string) / Panic).
93 94 95 96 97 |
# File 'lib/block_given/errors.rb', line 93 def reason return @reason if defined?(@reason) @reason = decode_builtin_reason end |
#selector ⇒ Object
99 100 101 |
# File 'lib/block_given/errors.rb', line 99 def selector revert_data && revert_data.length >= 10 ? revert_data[0, 10] : nil end |