Exception: BlockGiven::RpcError
- Defined in:
- lib/block_given/errors.rb
Overview
JSON-RPC error object returned by the node.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#rpc_method ⇒ Object
readonly
Returns the value of attribute rpc_method.
Class Method Summary collapse
-
.extract_revert_data(data) ⇒ Object
Providers disagree on where the revert bytes live: Alchemy/geth put them in
data, Hardhat/Anvil nest them underdata.data. -
.from_payload(error, rpc_method: nil) ⇒ Object
Builds the most specific error for a JSON-RPC error payload.
Instance Method Summary collapse
-
#initialize(message, code: nil, data: nil, rpc_method: nil) ⇒ RpcError
constructor
A new instance of RpcError.
Constructor Details
#initialize(message, code: nil, data: nil, rpc_method: nil) ⇒ RpcError
Returns a new instance of RpcError.
33 34 35 36 37 38 |
# File 'lib/block_given/errors.rb', line 33 def initialize(, code: nil, data: nil, rpc_method: nil) super() @code = code @data = data @rpc_method = rpc_method end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
31 32 33 |
# File 'lib/block_given/errors.rb', line 31 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
31 32 33 |
# File 'lib/block_given/errors.rb', line 31 def data @data end |
#rpc_method ⇒ Object (readonly)
Returns the value of attribute rpc_method.
31 32 33 |
# File 'lib/block_given/errors.rb', line 31 def rpc_method @rpc_method end |
Class Method Details
.extract_revert_data(data) ⇒ Object
Providers disagree on where the revert bytes live: Alchemy/geth put them in
data, Hardhat/Anvil nest them under data.data.
58 59 60 61 62 63 |
# File 'lib/block_given/errors.rb', line 58 def self.extract_revert_data(data) case data when String then data.start_with?("0x") ? data : nil when Hash then extract_revert_data(data["data"] || data[:data]) end end |
.from_payload(error, rpc_method: nil) ⇒ Object
Builds the most specific error for a JSON-RPC error payload. Reverts carry ABI-encoded data that we surface as a ContractRevertError.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/block_given/errors.rb', line 42 def self.from_payload(error, rpc_method: nil) error = { "message" => error.to_s } unless error.is_a?(Hash) code = error["code"] = error["message"].to_s data = error["data"] revert_data = extract_revert_data(data) if revert_data || .match?(/revert/i) ContractRevertError.new(, code: code, data: data, rpc_method: rpc_method, revert_data: revert_data) else new(, code: code, data: data, rpc_method: rpc_method) end end |