Class: Coinbase::StakingOperation
- Inherits:
-
Object
- Object
- Coinbase::StakingOperation
- Defined in:
- lib/coinbase/staking_operation.rb
Overview
A representation of a staking operation (stake, unstake, claim rewards, etc). It may have multiple steps with some being transactions to sign, and others to wait.
Instance Attribute Summary collapse
-
#status ⇒ Symbol
readonly
Returns the status of the Staking Operation.
-
#transactions ⇒ Array<Coinbase::Transaction>
readonly
The list of current transactions associated with the operation.
Class Method Summary collapse
-
.fetch(network_id, address_id, id) ⇒ Coinbase::StakingOperation
Fetch the StakingOperation with the provided network, address and staking operation ID.
Instance Method Summary collapse
-
#address_id ⇒ String
Returns the Address ID of the Staking Operation.
-
#id ⇒ String
Returns the Staking Operation ID.
-
#initialize(model) ⇒ StakingOperation
constructor
Returns a new StakingOperation object.
-
#network_id ⇒ Symbol
Returns the Network ID of the Staking Operation.
-
#reload ⇒ Coinbase::StakingOperation
Reloads the staking_operation from the service.
-
#sign(key) ⇒ Object
Signs the Open Transactions with the provided key.
-
#signed_voluntary_exit_messages ⇒ Array<string>
Fetches the presigned_voluntary exit messages for the staking operation.
-
#wait!(interval_seconds = 5, timeout_seconds = 3600) ⇒ StakingOperation
Waits until the Staking Operation is completed or failed by polling its status at the given interval.
Constructor Details
#initialize(model) ⇒ StakingOperation
Returns a new StakingOperation object.
14 15 16 |
# File 'lib/coinbase/staking_operation.rb', line 14 def initialize(model) from_model(model) end |
Instance Attribute Details
#status ⇒ Symbol (readonly)
Returns the status of the Staking Operation.
9 10 11 |
# File 'lib/coinbase/staking_operation.rb', line 9 def status @status end |
#transactions ⇒ Array<Coinbase::Transaction> (readonly)
The list of current transactions associated with the operation.
9 10 11 |
# File 'lib/coinbase/staking_operation.rb', line 9 def transactions @transactions end |
Class Method Details
.fetch(network_id, address_id, id) ⇒ Coinbase::StakingOperation
Fetch the StakingOperation with the provided network, address and staking operation ID.
70 71 72 73 74 75 76 |
# File 'lib/coinbase/staking_operation.rb', line 70 def self.fetch(network_id, address_id, id) staking_operation_model = Coinbase.call_api do stake_api.get_external_staking_operation(network_id, address_id, id) end from_model(staking_operation_model) end |
Instance Method Details
#address_id ⇒ String
Returns the Address ID of the Staking Operation.
32 33 34 |
# File 'lib/coinbase/staking_operation.rb', line 32 def address_id @model.address_id end |
#id ⇒ String
Returns the Staking Operation ID.
20 21 22 |
# File 'lib/coinbase/staking_operation.rb', line 20 def id @model.id end |
#network_id ⇒ Symbol
Returns the Network ID of the Staking Operation.
26 27 28 |
# File 'lib/coinbase/staking_operation.rb', line 26 def network_id Coinbase.to_sym(@model.network_id) end |
#reload ⇒ Coinbase::StakingOperation
Reloads the staking_operation from the service
88 89 90 91 92 93 94 |
# File 'lib/coinbase/staking_operation.rb', line 88 def reload @model = Coinbase.call_api do stake_api.get_external_staking_operation(network_id, address_id, id) end from_model(@model) end |
#sign(key) ⇒ Object
Signs the Open Transactions with the provided key
80 81 82 83 84 |
# File 'lib/coinbase/staking_operation.rb', line 80 def sign(key) transactions.each do |transaction| transaction.sign(key) unless transaction.signed? end end |
#signed_voluntary_exit_messages ⇒ Array<string>
Fetches the presigned_voluntary exit messages for the staking operation
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/coinbase/staking_operation.rb', line 98 def return [] unless @model. = [] @model..each do || decoded_string = Base64.decode64(.signed_voluntary_exit) .push(decoded_string) end end |
#wait!(interval_seconds = 5, timeout_seconds = 3600) ⇒ StakingOperation
Waits until the Staking Operation is completed or failed by polling its status at the given interval. Raises a Timeout::Error if the Staking Operation takes longer than the given timeout.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/coinbase/staking_operation.rb', line 48 def wait!(interval_seconds = 5, timeout_seconds = 3600) start_time = Time.now loop do reload # Wait for the Staking Operation to be in a terminal state. break if status == 'complete' raise Timeout::Error, 'Staking Operation timed out' if Time.now - start_time > timeout_seconds self.sleep interval_seconds end self end |