Class: Ethereum::Deployment
- Inherits:
-
Object
- Object
- Ethereum::Deployment
- Defined in:
- lib/ethereum/deployment.rb
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
Returns the value of attribute valid_deployment.
Instance Method Summary collapse
- #deployed? ⇒ Boolean
- #has_address? ⇒ Boolean
-
#initialize(txid, connection) ⇒ Deployment
constructor
A new instance of Deployment.
- #mined? ⇒ Boolean
- #wait_for_deployment(timeout = 1500.seconds) ⇒ Object
Constructor Details
#initialize(txid, connection) ⇒ 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
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/ethereum/deployment.rb', line 5 def connection @connection end |
#contract_address ⇒ Object
Returns the value of attribute contract_address.
5 6 7 |
# File 'lib/ethereum/deployment.rb', line 5 def contract_address @contract_address end |
#deployed ⇒ Object
Returns the value of attribute deployed.
5 6 7 |
# File 'lib/ethereum/deployment.rb', line 5 def deployed @deployed end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/ethereum/deployment.rb', line 5 def id @id end |
#mined ⇒ Object
Returns the value of attribute mined.
5 6 7 |
# File 'lib/ethereum/deployment.rb', line 5 def mined @mined end |
#valid_deployment ⇒ Object
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
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
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
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 |