Class: Zilliqa::Contract::ContractFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/zilliqa/contract/contract_factory.rb

Overview

ContractFactory

individual ‘Contract` instances are instead obtained by calling `ContractFactory.at` (for an already-deployed contract) and `ContractFactory.new` (to deploy a new contract).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider, signer) ⇒ ContractFactory

Returns a new instance of ContractFactory.



14
15
16
17
# File 'lib/zilliqa/contract/contract_factory.rb', line 14

def initialize(provider, signer)
  @provider = provider
  @signer = signer
end

Instance Attribute Details

#providerObject (readonly)

Returns the value of attribute provider.



12
13
14
# File 'lib/zilliqa/contract/contract_factory.rb', line 12

def provider
  @provider
end

#signerObject (readonly)

Returns the value of attribute signer.



12
13
14
# File 'lib/zilliqa/contract/contract_factory.rb', line 12

def signer
  @signer
end

Class Method Details

.get_address_for_contract(tx) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/zilliqa/contract/contract_factory.rb', line 19

def self.get_address_for_contract(tx)
  sha256 = Digest::SHA256.new

  sender_address = Zilliqa::Crypto::KeyTool.get_address_from_public_key(tx.sender_pub_key)

  sha256 << Util.decode_hex(sender_address)

  nonce = 0
  if tx.nonce
    nonce = tx.nonce.to_i - 1
  end

  nonce_hex = [nonce].pack('Q>*')

  sha256 << nonce_hex

  sha256.hexdigest[24..-1]
end

Instance Method Details

#at_contract(address, code, init, abi) ⇒ Object



42
43
44
# File 'lib/zilliqa/contract/contract_factory.rb', line 42

def at_contract(address, code, init, abi)
  Contract.new(self, code, abi, address, init, nil)
end

#new_contract(code, init, abi) ⇒ Object



38
39
40
# File 'lib/zilliqa/contract/contract_factory.rb', line 38

def new_contract(code, init, abi)
  Contract.new(self, code, abi, nil, init, nil)
end