Class: Coinbase::ExternalAddress
- Defined in:
- lib/coinbase/address/external_address.rb
Overview
A representation of a blockchain Address that do not belong to a Coinbase::Wallet. External addresses can be used to fetch balances, request funds from the faucet, etc…, but cannot be used to sign transactions.
Instance Attribute Summary
Attributes inherited from Address
Instance Method Summary collapse
-
#build_claim_stake_operation(amount, asset_id, mode: :default, options: {}) ⇒ Coinbase::StakingOperation
Builds an claim_stake operation for the supplied asset.
-
#build_stake_operation(amount, asset_id, mode: :default, options: {}) ⇒ Coinbase::StakingOperation
Builds a stake operation for the supplied asset.
-
#build_unstake_operation(amount, asset_id, mode: :default, options: {}) ⇒ Coinbase::StakingOperation
Builds an unstake operation for the supplied asset.
-
#claimable_balance(asset_id, mode: :default, options: {}) ⇒ BigDecimal
Retreives the claimable balance for the supplied asset.
-
#stakeable_balance(asset_id, mode: :default, options: {}) ⇒ BigDecimal
Retreives the stakeable balance for the supplied asset.
-
#staking_balances(asset_id, mode: :default, options: {}) ⇒ Hash, BigDecimal
Retreives the balances used for staking for the supplied asset.
-
#staking_rewards(asset_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now, format: :usd) ⇒ Enumerable<Coinbase::StakingReward>
Lists the staking rewards for the address.
-
#unstakeable_balance(asset_id, mode: :default, options: {}) ⇒ BigDecimal
Retreives the unstakeable balance for the supplied asset.
Methods inherited from Address
#balance, #balances, #can_sign?, #faucet, #initialize, #inspect, #to_s
Constructor Details
This class inherits a constructor from Coinbase::Address
Instance Method Details
#build_claim_stake_operation(amount, asset_id, mode: :default, options: {}) ⇒ Coinbase::StakingOperation
Builds an claim_stake operation for the supplied asset.
41 42 43 44 45 |
# File 'lib/coinbase/address/external_address.rb', line 41 def build_claim_stake_operation(amount, asset_id, mode: :default, options: {}) validate_can_claim_stake!(amount, asset_id, mode, ) build_staking_operation(amount, asset_id, 'claim_stake', mode: mode, options: ) end |
#build_stake_operation(amount, asset_id, mode: :default, options: {}) ⇒ Coinbase::StakingOperation
Builds a stake operation for the supplied asset. The stake operation may take a few minutes to complete in the case when infrastructure is spun up.
17 18 19 20 21 |
# File 'lib/coinbase/address/external_address.rb', line 17 def build_stake_operation(amount, asset_id, mode: :default, options: {}) validate_can_stake!(amount, asset_id, mode, ) build_staking_operation(amount, asset_id, 'stake', mode: mode, options: ) end |
#build_unstake_operation(amount, asset_id, mode: :default, options: {}) ⇒ Coinbase::StakingOperation
Builds an unstake operation for the supplied asset.
29 30 31 32 33 |
# File 'lib/coinbase/address/external_address.rb', line 29 def build_unstake_operation(amount, asset_id, mode: :default, options: {}) validate_can_unstake!(amount, asset_id, mode, ) build_staking_operation(amount, asset_id, 'unstake', mode: mode, options: ) end |
#claimable_balance(asset_id, mode: :default, options: {}) ⇒ BigDecimal
Retreives the claimable balance for the supplied asset.
108 109 110 |
# File 'lib/coinbase/address/external_address.rb', line 108 def claimable_balance(asset_id, mode: :default, options: {}) staking_balances(asset_id, mode: mode, options: )[:claimable_balance] end |
#stakeable_balance(asset_id, mode: :default, options: {}) ⇒ BigDecimal
Retreives the stakeable balance for the supplied asset.
90 91 92 |
# File 'lib/coinbase/address/external_address.rb', line 90 def stakeable_balance(asset_id, mode: :default, options: {}) staking_balances(asset_id, mode: mode, options: )[:stakeable_balance] end |
#staking_balances(asset_id, mode: :default, options: {}) ⇒ Hash, BigDecimal
Retreives the balances used for staking for the supplied asset.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/coinbase/address/external_address.rb', line 55 def staking_balances(asset_id, mode: :default, options: {}) context_model = Coinbase.call_api do stake_api.get_staking_context( { asset_id: asset_id, network_id: Coinbase.normalize_network(network_id), address_id: id, options: { mode: mode }.merge() } ) end.context { stakeable_balance: Coinbase::Balance.from_model_and_asset_id( context_model.stakeable_balance, asset_id ).amount, unstakeable_balance: Coinbase::Balance.from_model_and_asset_id( context_model.unstakeable_balance, asset_id ).amount, claimable_balance: Coinbase::Balance.from_model_and_asset_id( context_model.claimable_balance, asset_id ).amount } end |
#staking_rewards(asset_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now, format: :usd) ⇒ Enumerable<Coinbase::StakingReward>
Lists the staking rewards for the address.
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/coinbase/address/external_address.rb', line 118 def staking_rewards(asset_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now, format: :usd) StakingReward.list( network_id, asset_id, [id], start_time: start_time, end_time: end_time, format: format ) end |
#unstakeable_balance(asset_id, mode: :default, options: {}) ⇒ BigDecimal
Retreives the unstakeable balance for the supplied asset.
99 100 101 |
# File 'lib/coinbase/address/external_address.rb', line 99 def unstakeable_balance(asset_id, mode: :default, options: {}) staking_balances(asset_id, mode: mode, options: )[:unstakeable_balance] end |