Class: Coinbase::StakingReward
- Inherits:
 - 
      Object
      
        
- Object
 - Coinbase::StakingReward
 
 
- Defined in:
 - lib/coinbase/staking_reward.rb
 
Overview
A representation of a staking reward earned on a network for a given asset.
Class Method Summary collapse
- 
  
    
      .list(network_id, asset_id, address_ids, start_time: DateTime.now.prev_month(1), end_time: DateTime.now, format: :usd)  ⇒ Enumerable<Coinbase::StakingReward> 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a list of StakingRewards for the provided network, asset, and addresses.
 - .list_page(network_id, asset_id, address_ids, start_time, end_time, page, format) ⇒ Object
 - .stake_api ⇒ Object
 
Instance Method Summary collapse
- 
  
    
      #address_id  ⇒ Time 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the onchain address of the StakingReward.
 - 
  
    
      #amount  ⇒ BigDecimal 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the amount of the StakingReward.
 - 
  
    
      #date  ⇒ Time 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the date of the StakingReward.
 - 
  
    
      #initialize(model, asset, format)  ⇒ StakingReward 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Returns a new StakingReward object.
 - 
  
    
      #inspect  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Same as to_s.
 - 
  
    
      #to_s  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Returns a string representation of the StakingReward.
 - 
  
    
      #usd_conversion_price  ⇒ BigDecimal 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the USD conversion price of the StakingReward.
 - 
  
    
      #usd_conversion_time  ⇒ Time 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the USD conversion time of the StakingReward.
 - 
  
    
      #usd_value  ⇒ BigDecimal 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the USD value of the StakingReward.
 
Constructor Details
#initialize(model, asset, format) ⇒ StakingReward
Returns a new StakingReward object.
      30 31 32 33 34  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 30 def initialize(model, asset, format) @model = model @asset = asset @format = format end  | 
  
Class Method Details
.list(network_id, asset_id, address_ids, start_time: DateTime.now.prev_month(1), end_time: DateTime.now, format: :usd) ⇒ Enumerable<Coinbase::StakingReward>
Returns a list of StakingRewards for the provided network, asset, and addresses.
      16 17 18 19 20 21 22 23 24 25 26  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 16 def self.list(network_id, asset_id, address_ids, start_time: DateTime.now.prev_month(1), end_time: DateTime.now, format: :usd) asset = Coinbase.call_api do Asset.fetch(network_id, asset_id) end Coinbase::Pagination.enumerate( ->(page) { list_page(network_id, asset_id, address_ids, start_time, end_time, page, format) } ) do |staking_reward| new(staking_reward, asset, format) end end  | 
  
.list_page(network_id, asset_id, address_ids, start_time, end_time, page, format) ⇒ Object
      90 91 92 93 94 95 96 97 98 99 100 101  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 90 def self.list_page(network_id, asset_id, address_ids, start_time, end_time, page, format) req = { network_id: Coinbase.normalize_network(network_id), asset_id: asset_id, address_ids: address_ids, start_time: start_time.iso8601, end_time: end_time.iso8601, format: format, next_page: page } stake_api.fetch_staking_rewards(req) end  | 
  
.stake_api ⇒ Object
      86 87 88  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 86 def self.stake_api Coinbase::Client::StakeApi.new(Coinbase.configuration.api_client) end  | 
  
Instance Method Details
#address_id ⇒ Time
Returns the onchain address of the StakingReward.
      52 53 54  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 52 def address_id @model.address_id end  | 
  
#amount ⇒ BigDecimal
Returns the amount of the StakingReward.
      38 39 40 41 42  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 38 def amount return BigDecimal(@model.amount.to_i) / BigDecimal(100) if @format == :usd @asset.from_atomic_amount(@model.amount.to_i) end  | 
  
#date ⇒ Time
Returns the date of the StakingReward.
      46 47 48  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 46 def date @model.date end  | 
  
#inspect ⇒ String
Same as to_s.
      82 83 84  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 82 def inspect to_s end  | 
  
#to_s ⇒ String
Returns a string representation of the StakingReward.
      76 77 78  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 76 def to_s "Coinbase::StakingReward{date: '#{date}' address_id: '#{address_id}' amount: '#{amount.to_f}'}" end  | 
  
#usd_conversion_price ⇒ BigDecimal
Returns the USD conversion price of the StakingReward.
      64 65 66  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 64 def usd_conversion_price BigDecimal(@model.usd_value.conversion_price.to_i) end  | 
  
#usd_conversion_time ⇒ Time
Returns the USD conversion time of the StakingReward.
      70 71 72  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 70 def usd_conversion_time @model.usd_value.conversion_time end  | 
  
#usd_value ⇒ BigDecimal
Returns the USD value of the StakingReward.
      58 59 60  | 
    
      # File 'lib/coinbase/staking_reward.rb', line 58 def usd_value BigDecimal(@model.usd_value.amount.to_i) / BigDecimal(100) end  |