Class: ContractType::Proxy

Inherits:
Object
  • Object
show all
Extended by:
AttrPublicReadPrivateWrite
Includes:
ContractErrors
Defined in:
lib/0xfacet/typed/contract_type.rb

Instance Method Summary collapse

Methods included from AttrPublicReadPrivateWrite

attr_public_read_private_write

Constructor Details

#initialize(contract_type:, address:, contract_interface:) ⇒ Proxy

Returns a new instance of Proxy.



32
33
34
35
36
37
38
39
# File 'lib/0xfacet/typed/contract_type.rb', line 32

def initialize(contract_type:, address:, contract_interface:)
  self.uncast_address = address
  address = TypedVariable.create_or_validate(:address, address).value

  self.contract_type = contract_type
  self.address = address
  self.contract_interface = contract_interface
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/0xfacet/typed/contract_type.rb', line 41

def method_missing(name, *args, **kwargs, &block)
  computed_args = args.presence || kwargs
  
  super unless contract_interface
  
  known_function = contract_interface.public_abi[name]
  
  unless known_function && known_function.args.length == computed_args.length
    raise ContractError.new("Contract doesn't implement interface: #{contract_type}, #{name}")
  end
  
  TransactionContext.call_stack.execute_in_new_frame(
    to_contract_address: address,
    function: name,
    args: computed_args,
    type: :call
  )
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
28
29
30
# File 'lib/0xfacet/typed/contract_type.rb', line 25

def ==(other)
  return false unless other.is_a?(self.class)
  
  other.contract_type == contract_type &&
  other.address == address
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/0xfacet/typed/contract_type.rb', line 60

def respond_to_missing?(name, include_private = false)
  !!contract_interface.public_abi[name] || super
end