module Eth::Abi::Function
def decode(interfaces, data)
-
(CallDescription, nil)
- a CallDescription object or nil if selector unknown.
Parameters:
-
data
(String
) -- transaction input data. -
interfaces
(Array
) -- function ABI types.
def decode(interfaces, data) data = Util.remove_hex_prefix(data) selector = Util.prefix_hex(data[0, 8]) payload = Util.prefix_hex(data[8..] || "") selector_to_interfaces = Hash[interfaces.map { |i| [selector(i), i] }] if (interface = selector_to_interfaces[selector]) inputs = interface.fetch("inputs", []) types = inputs.map { |i| type(i) } args = Abi.decode(types, payload) kwargs = {} inputs.each_with_index do |input, i| name = input.fetch("name", "") kwargs[name.to_sym] = args[i] unless name.empty? end CallDescription.new(interface, selector, args, kwargs) end end
def selector(interface)
-
(String)
- a hex-string selector.
Parameters:
-
interface
(Hash
) -- ABI function interface.
def selector(interface) sig = signature(interface) Util.prefix_hex(Util.bin_to_hex(Util.keccak256(sig))[0, 8]) end
def signature(interface)
-
(String)
- interface signature string.
Parameters:
-
interface
(Hash
) -- ABI function interface.
def signature(interface) name = interface.fetch("name") inputs = interface.fetch("inputs", []) types = inputs.map { |i| type(i) } "#{name}(#{types.join(",")})" end
def type(input)
-
(String)
- input type.
Parameters:
-
input
(Hash
) -- function input.
def type(input) if input["type"] == "tuple" "(#{input["components"].map { |c| type(c) }.join(",")})" elsif input["type"] == "enum" "uint8" else input["type"] end end