Sha256: ffbaf33aa6dac3e904231fa37b78d78df5d7c655054ad06794c7cac56ba7e9ca

Contents?: true

Size: 963 Bytes

Versions: 4

Compression:

Stored size: 963 Bytes

Contents

module Platon

  class Transaction

    DEFAULT_TIMEOUT = 300.seconds
    DEFAULT_STEP = 5.seconds

    attr_accessor :id, :mined, :connection, :input, :input_parameters

    def initialize(id, connection, data, input_parameters = [])
      @mined = false
      @connection = connection
      @id = id
      @input = data
      @input_parameters = input_parameters
    end

    def address
      @id
    end

    def mined?
      return true if @mined
      tx = @connection.platon_get_transaction_by_hash(@id)
      @mined = !tx.nil? && tx["blockNumber"].present?
    end

    def wait_for_miner(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP)
      start_time = Time.now
      loop do
        raise Timeout::Error if ((Time.now - start_time) > timeout)
        return true if self.mined?
        sleep step
      end
    end

    def self.from_blockchain(address, connection = IpcClient.new)
      Transaction.new(address, connection, nil, nil)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
platon-1.0.1 lib/platon/transaction.rb
platon-1.0.0 lib/platon/transaction.rb
platon-0.2.9 lib/platon/transaction.rb
platon-0.2.7 lib/platon/transaction.rb