Class: Coinbase::StakingBalance

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/staking_balance.rb

Overview

A representation of a staking balance on a network for a given asset.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ StakingBalance

Returns a new StakingBalance object.

Parameters:



27
28
29
# File 'lib/coinbase/staking_balance.rb', line 27

def initialize(model)
  @model = model
end

Class Method Details

.list(network, asset_id, address_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now) ⇒ Enumerable<Coinbase::StakingBalance>

Returns a list of StakingBalance for the provided network, asset, and addresses.

Parameters:

  • network (Coinbase::Network, Symbol)

    The Network or Network ID

  • asset_id (Symbol)

    The asset ID

  • address_id (String)

    The address ID

  • start_time (Time) (defaults to: DateTime.now.prev_month(1))

    The start time. Defaults to one month ago.

  • end_time (Time) (defaults to: DateTime.now)

    The end time. Defaults to the current time.

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/coinbase/staking_balance.rb', line 15

def self.list(network, asset_id, address_id, start_time: DateTime.now.prev_month(1), end_time: DateTime.now)
  network = Coinbase::Network.from_id(network)

  Coinbase::Pagination.enumerate(
    ->(page) { list_page(network, asset_id, address_id, start_time, end_time, page) }
  ) do |staking_balance|
    new(staking_balance)
  end
end

Instance Method Details

#addressTime

Returns the onchain address of the StakingBalance.

Returns:

  • (Time)

    The onchain address



39
40
41
# File 'lib/coinbase/staking_balance.rb', line 39

def address
  @model.address
end

#bonded_stakeBalance

Returns the bonded stake as a Balance

Returns:



45
46
47
# File 'lib/coinbase/staking_balance.rb', line 45

def bonded_stake
  @bonded_stake ||= Balance.from_model(@model.bonded_stake)
end

#dateTime

Returns the date of the StakingBalance.

Returns:

  • (Time)

    The date



33
34
35
# File 'lib/coinbase/staking_balance.rb', line 33

def date
  @model.date
end

#inspectString

Same as to_s.

Returns:

  • (String)

    a string representation of the StakingBalance



69
70
71
# File 'lib/coinbase/staking_balance.rb', line 69

def inspect
  to_s
end

#participant_typeString

Returns the participant type of the StakingBalance.

Returns:

  • (String)

    The participant type



57
58
59
# File 'lib/coinbase/staking_balance.rb', line 57

def participant_type
  @model.participant_type
end

#to_sString

Returns a string representation of the StakingBalance.

Returns:

  • (String)

    a string representation of the StakingBalance



63
64
65
# File 'lib/coinbase/staking_balance.rb', line 63

def to_s
  "Coinbase::StakingBalance{date: '#{date}' address: '#{address}'}"
end

#unbonded_balanceBalance

Returns the unbonded balance as a Balance

Returns:

  • (Balance)

    The unbonded balance



51
52
53
# File 'lib/coinbase/staking_balance.rb', line 51

def unbonded_balance
  @unbonded_balance ||= Balance.from_model(@model.unbonded_balance)
end