Class: Coinbase::Validator

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

Overview

A representation of a staking validator.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ Validator

Returns a new Validator object.

Parameters:



8
9
10
# File 'lib/coinbase/validator.rb', line 8

def initialize(model)
  @model = model
end

Class Method Details

.fetch(network_id, asset_id, validator_id) ⇒ Coinbase::Validator

Returns a Validator for the provided network, asset, and validator.

Parameters:

  • network_id (Symbol)

    The network ID

  • asset_id (Symbol)

    The asset ID

  • validator_id (String)

    The validator ID

Returns:



30
31
32
33
34
35
36
37
38
39
# File 'lib/coinbase/validator.rb', line 30

def self.fetch(network_id, asset_id, validator_id)
  validator = Coinbase.call_api do
    validators_api.get_validator(
      network_id,
      asset_id,
      validator_id
    )
  end
  new(validator)
end

.list(network_id, asset_id, status: nil) ⇒ Enumerable<Coinbase::Validator>

Returns a list of Validators for the provided network and asset.

Parameters:

  • network_id (Symbol)

    The network ID

  • asset_id (Symbol)

    The asset ID

  • status (Symbol) (defaults to: nil)

    The status of the validator. Defaults to nil.

Returns:



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

def self.list(network_id, asset_id, status: nil)
  Coinbase::Pagination.enumerate(
    ->(page) { list_page(network_id, asset_id, status, page) }
  ) do |validator|
    new(validator)
  end
end

.list_page(network_id, asset_id, status, page) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/coinbase/validator.rb', line 65

def self.list_page(network_id, asset_id, status, page)
  Coinbase.call_api do
    validators_api.list_validators(
      network_id,
      asset_id,
      {
        status: status,
        page: page
      }
    )
  end
end

.validators_apiObject



78
79
80
# File 'lib/coinbase/validator.rb', line 78

def self.validators_api
  Coinbase::Client::ValidatorsApi.new(Coinbase.configuration.api_client)
end

Instance Method Details

#inspectString

Same as to_s.

Returns:

  • (String)

    a string representation of the Validator



61
62
63
# File 'lib/coinbase/validator.rb', line 61

def inspect
  to_s
end

#statusSymbol

Returns the status of the Validator.

Returns:

  • (Symbol)

    The status



49
50
51
# File 'lib/coinbase/validator.rb', line 49

def status
  @model.status
end

#to_sString

Returns a string representation of the Validator.

Returns:

  • (String)

    a string representation of the Validator



55
56
57
# File 'lib/coinbase/validator.rb', line 55

def to_s
  "Coinbase::Validator{id: '#{validator_id}' status: '#{status}'}"
end

#validator_idString

Returns the public identifiable id of the Validator.

Returns:

  • (String)

    The validator ID



43
44
45
# File 'lib/coinbase/validator.rb', line 43

def validator_id
  @model.validator_id
end