Class: EvmClient::Deployment
- Inherits:
-
Object
- Object
- EvmClient::Deployment
- Defined in:
- lib/evm_client/deployment.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
300.seconds
- DEFAULT_STEP =
5.seconds
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#contract_address ⇒ Object
Returns the value of attribute contract_address.
-
#deployed ⇒ Object
Returns the value of attribute deployed.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mined ⇒ Object
Returns the value of attribute mined.
-
#valid_deployment ⇒ Object
readonly
Returns the value of attribute valid_deployment.
Instance Method Summary collapse
- #check_deployed ⇒ Object
- #deployed? ⇒ Boolean
-
#initialize(txid, connection) ⇒ Deployment
constructor
A new instance of Deployment.
- #mined? ⇒ Boolean
- #wait_for_deployment(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP) ⇒ Object
Constructor Details
#initialize(txid, connection) ⇒ Deployment
Returns a new instance of Deployment.
11 12 13 14 15 16 17 |
# File 'lib/evm_client/deployment.rb', line 11 def initialize(txid, connection) @id = txid @connection = connection @deployed = false @contract_address = nil @valid_deployment = false end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
8 9 10 |
# File 'lib/evm_client/deployment.rb', line 8 def connection @connection end |
#contract_address ⇒ Object
Returns the value of attribute contract_address.
8 9 10 |
# File 'lib/evm_client/deployment.rb', line 8 def contract_address @contract_address end |
#deployed ⇒ Object
Returns the value of attribute deployed.
8 9 10 |
# File 'lib/evm_client/deployment.rb', line 8 def deployed @deployed end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/evm_client/deployment.rb', line 8 def id @id end |
#mined ⇒ Object
Returns the value of attribute mined.
8 9 10 |
# File 'lib/evm_client/deployment.rb', line 8 def mined @mined end |
#valid_deployment ⇒ Object (readonly)
Returns the value of attribute valid_deployment.
9 10 11 |
# File 'lib/evm_client/deployment.rb', line 9 def valid_deployment @valid_deployment end |
Instance Method Details
#check_deployed ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/evm_client/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
34 35 36 |
# File 'lib/evm_client/deployment.rb', line 34 def deployed? @valid_deployment ||= check_deployed end |
#mined? ⇒ Boolean
19 20 21 22 23 |
# File 'lib/evm_client/deployment.rb', line 19 def mined? return true if @mined @mined = @connection.eth_get_transaction_by_hash(@id)["result"]["blockNumber"].present? @mined ||= false end |
#wait_for_deployment(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/evm_client/deployment.rb', line 38 def wait_for_deployment(timeout: DEFAULT_TIMEOUT, step: DEFAULT_STEP) start_time = Time.now loop do raise "Transaction #{@id} timed out." if ((Time.now - start_time) > timeout) yield if block_given? return true if deployed? sleep step end end |