Class: Ethereum::Deployment

Inherits:
Object
  • Object
show all
Defined in:
lib/ethereum/deployment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txid, connection) ⇒ Deployment

Returns a new instance of Deployment.


7
8
9
10
11
12
13
# File 'lib/ethereum/deployment.rb', line 7

def initialize(txid, connection)
  @id = txid
  @connection = connection
  @deployed = false
  @contract_address = nil
  @valid_deployment = false
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection


5
6
7
# File 'lib/ethereum/deployment.rb', line 5

def connection
  @connection
end

#contract_addressObject

Returns the value of attribute contract_address


5
6
7
# File 'lib/ethereum/deployment.rb', line 5

def contract_address
  @contract_address
end

#deployedObject

Returns the value of attribute deployed


5
6
7
# File 'lib/ethereum/deployment.rb', line 5

def deployed
  @deployed
end

#idObject

Returns the value of attribute id


5
6
7
# File 'lib/ethereum/deployment.rb', line 5

def id
  @id
end

#minedObject

Returns the value of attribute mined


5
6
7
# File 'lib/ethereum/deployment.rb', line 5

def mined
  @mined
end

#valid_deploymentObject

Returns the value of attribute valid_deployment


5
6
7
# File 'lib/ethereum/deployment.rb', line 5

def valid_deployment
  @valid_deployment
end

Instance Method Details

#deployed?Boolean

Returns:

  • (Boolean)

28
29
30
31
32
# File 'lib/ethereum/deployment.rb', line 28

def deployed?
  return true if @valid_deployment
  return false unless self.has_address?
  @valid_deployment = @connection.get_code(@contract_address)["result"] != "0x"
end

#has_address?Boolean

Returns:

  • (Boolean)

21
22
23
24
25
26
# File 'lib/ethereum/deployment.rb', line 21

def has_address?
  return true if @contract_address.present?
  return false unless self.mined? 
  @contract_address ||= @connection.get_transaction_receipt(@id)["result"]["contractAddress"] 
  return @contract_address.present?
end

#mined?Boolean

Returns:

  • (Boolean)

15
16
17
18
19
# File 'lib/ethereum/deployment.rb', line 15

def mined?
  return true if @mined
  @mined = @connection.get_transaction_by_hash(@id)["result"]["blockNumber"].present? rescue nil
  @mined ||= false
end

#wait_for_deployment(timeout = 1500.seconds) ⇒ Object


34
35
36
37
38
39
40
41
# File 'lib/ethereum/deployment.rb', line 34

def wait_for_deployment(timeout = 1500.seconds)
  start_time = Time.now
  while self.deployed? == false
    raise "Transaction #{@id} timed out." if ((Time.now - start_time) > timeout) 
    sleep 5 
    return true if self.deployed? 
  end
end