Sha256: 9ae04a3e31ae9753a7904bbd1c48e07af75cd42042860989cc5fe2c62b22f790

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

require 'digest'

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

      attr_reader :provider, :signer

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

      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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zilliqa-0.1.7 lib/zilliqa/contract/contract_factory.rb
zilliqa-0.1.6 lib/zilliqa/contract/contract_factory.rb
zilliqa-0.1.5 lib/zilliqa/contract/contract_factory.rb
zilliqa-0.1.4 lib/zilliqa/contract/contract_factory.rb
zilliqa-0.1.3 lib/zilliqa/contract/contract_factory.rb
zilliqa-0.1.2 lib/zilliqa/contract/contract_factory.rb
zilliqa-0.1.1 lib/zilliqa/contract/contract_factory.rb