Class: Ethereum::Deployment

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

Constant Summary collapse

DEFAULT_TIMEOUT =
300.seconds
DEFAULT_STEP =
5.seconds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txid, connection) ⇒ Deployment

Returns a new instance of Deployment.



11
12
13
14
15
16
17
# File 'lib/ethereum/deployment.rb', line 11

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.



8
9
10
# File 'lib/ethereum/deployment.rb', line 8

def connection
  @connection
end

#contract_addressObject

Returns the value of attribute contract_address.



8
9
10
# File 'lib/ethereum/deployment.rb', line 8

def contract_address
  @contract_address
end

#deployedObject

Returns the value of attribute deployed.



8
9
10
# File 'lib/ethereum/deployment.rb', line 8

def deployed
  @deployed
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/ethereum/deployment.rb', line 8

def id
  @id
end

#minedObject

Returns the value of attribute mined.



8
9
10
# File 'lib/ethereum/deployment.rb', line 8

def mined
  @mined
end

#valid_deploymentObject (readonly)

Returns the value of attribute valid_deployment.



9
10
11
# File 'lib/ethereum/deployment.rb', line 9

def valid_deployment
  @valid_deployment
end

Instance Method Details

#check_deployedObject



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

def check_deployed
  return false unless @id
  contract_receipt = @connection.eth_get_transaction_receipt(@id)
  result = contract_receipt["result"]
  has_contract_address = result && result["contractAddress"]
  @contract_address ||= result["contractAddress"] if has_contract_address
  has_contract_address && result["blockNumber"]
end

#deployed?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ethereum/deployment.rb', line 34

def deployed?
  @valid_deployment ||= check_deployed
end

#mined?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/ethereum/deployment.rb', line 19

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 = DEFAULT_TIMEOUT, step: DEFAULT_STEP, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ethereum/deployment.rb', line 38

def wait_for_deployment(timeout = DEFAULT_TIMEOUT, step: DEFAULT_STEP, &block)
  start_time = Time.now
  while true
    raise "Transaction #{@id} timed out." if ((Time.now - start_time) > timeout) 
    sleep step
    yield if block_given?
    return true if deployed?
  end
end