class EthereumContractABI::Contract
Public Class Methods
new(functions, events)
click to toggle source
# File lib/ethereum-contract-abi/contract.rb, line 10 def initialize(functions, events) @functions = functions.to_h { |func| [func.name, func]} @events = events functions.each do |f| self.class.send(:define_method, f.name) { function(f.name) } end end
Public Instance Methods
function(name)
click to toggle source
# File lib/ethereum-contract-abi/contract.rb, line 23 def function(name) @functions.dig(name) end
function_exists?(name)
click to toggle source
# File lib/ethereum-contract-abi/contract.rb, line 27 def function_exists?(name) @functions.key? name end
functions()
click to toggle source
# File lib/ethereum-contract-abi/contract.rb, line 19 def functions @functions.values end
has_function?(func)
click to toggle source
# File lib/ethereum-contract-abi/contract.rb, line 44 def has_function?(func) return false unless function_exists?(func.name) contract_func = function(func.name) return false unless contract_func.inputs.size == func.inputs.size return false unless contract_func.outputs.size == func.outputs.size input_type_strings = contract_func.inputs.map {|i| i.type.to_s } expected_input_type_strings = func.inputs.map {|i| i.type.to_s } output_type_string = contract_func.outputs.map {|i| i.type.to_s } expected_output_type_string = func.outputs.map {|i| i.type.to_s } Set.new(expected_input_type_strings) == Set.new(input_type_strings) && Set.new(expected_output_type_string) == Set.new(output_type_string) end
implements_interface(identifier)
click to toggle source
# File lib/ethereum-contract-abi/contract.rb, line 31 def implements_interface(identifier) case identifier when EIP::ERC721_METADATA_ID EIP::ERC721MetadataInterface.is_implemented_by?(self) when EIP::ERC721_ENUMERABLE_ID EIP::ERC721EnumerableInterface.is_implemented_by?(self) when EIP::ERC1155_METADATA_ID EIP::ERC1155MetadataInterface.is_implemented_by?(self) else raise ArgumentError.new('Unknown interface identifier') end end