Class: Casper::Entity::AuctionState

Inherits:
Object
  • Object
show all
Defined in:
lib/entity/auction_state.rb

Overview

Data structure summarizing auction contract data.

Instance Method Summary collapse

Constructor Details

#initialize(state_root_hash, block_height, era_validators, bids) ⇒ AuctionState

Returns a new instance of AuctionState.

Parameters:

  • state_root_hash (String)
  • block_height (Integer)
  • era_validators (Array<Hash>)
  • bids (Array<Hash>)

Options Hash (era_validators):

  • :era_id (Integer)
  • :validator_weights (Array<Hash>)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/entity/auction_state.rb', line 11

def initialize(state_root_hash, block_height, era_validators, bids)
  @state_root_hash = state_root_hash
  @block_height = block_height

  @era_validators = []
  era_validators.each do |era_validator|
    @validators_weights = []
    era_validator[:validator_weights].each do |validator_weight|
      @validators_weights << Casper::Entity::ValidatorWeight.new(validator_weight[:public_key], validator_weight[:weight])
    end
    @era_validators << Casper::Entity::EraValidator.new(era_validator[:era_id], @validators_weights)
    @validators_weights = []
    # puts Casper::Entity::EraValidator.new(era_validator[:era_id], @validators_weights).get_era_id
    # puts Casper::Entity::EraValidator.new(era_validator[:era_id], @validators_weights).get_validator_weights
  end

  # @era_validators.each do |era_validator| 
  #   puts era_validator.get_validator_weights[0].get_era_id
  #   puts era_validator.get_validator_weights[0].get_weight
  # end

  @bids = bids
  @bids_list = []
  
  bids.each do |bid|
    bid_info = bid[:bid]
    @delegators_list = []
    delegators = bid_info[:delegators]

    delegators.each do |delegator| 
      @delegators_list << Casper::Entity::Delegator.new(
        delegator[:public_key], 
        delegator[:staked_amount], 
        delegator[:bonding_purse], 
        delegator[:delegatee]
        )
      # puts delegator
      # puts delegator[:public_key]
    end
    
    bid_info = Casper::Entity::BidInfo.new(
      bid_info[:bonding_purse], 
      bid_info[:staked_amount], 
      bid_info[:delegation_rate],
      bid_info[:vesting_schedule],
      # bid_info[:delegators],
      @delegators_list,
      bid_info[:inactive]
      )
    @bids_list << Casper::Entity::Bid.new(bid[:public_key], bid_info)
  end
end

Instance Method Details

#get_bidsArray<Bid>

Returns array of Bid.

Returns:

  • (Array<Bid>)

    array of Bid



80
81
82
# File 'lib/entity/auction_state.rb', line 80

def get_bids
  @bids_list
end

#get_block_heightInteger

Returns block height as an Integer.

Returns:

  • (Integer)

    block height as an Integer



70
71
72
# File 'lib/entity/auction_state.rb', line 70

def get_block_height
  @block_height
end

#get_era_validatorsArray<EraValidator>

Returns array of EraValidator.

Returns:



75
76
77
# File 'lib/entity/auction_state.rb', line 75

def get_era_validators
  @era_validators
end

#get_state_root_hashString

Returns state root hash as a String.

Returns:

  • (String)

    state root hash as a String



65
66
67
# File 'lib/entity/auction_state.rb', line 65

def get_state_root_hash
  @state_root_hash
end