35562bd2f9
Also, correctly handle multiple ADT versions.
88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
package power
|
|
|
|
import (
|
|
"github.com/filecoin-project/go-address"
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
|
|
|
adt1 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
|
power1 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power"
|
|
)
|
|
|
|
var _ State = (*state1)(nil)
|
|
|
|
type state1 struct {
|
|
power1.State
|
|
store adt.Store
|
|
}
|
|
|
|
func (s *state1) TotalLocked() (abi.TokenAmount, error) {
|
|
return s.TotalPledgeCollateral, nil
|
|
}
|
|
|
|
func (s *state1) TotalPower() (Claim, error) {
|
|
return Claim{
|
|
RawBytePower: s.TotalRawBytePower,
|
|
QualityAdjPower: s.TotalQualityAdjPower,
|
|
}, nil
|
|
}
|
|
|
|
// Committed power to the network. Includes miners below the minimum threshold.
|
|
func (s *state1) TotalCommitted() (Claim, error) {
|
|
return Claim{
|
|
RawBytePower: s.TotalBytesCommitted,
|
|
QualityAdjPower: s.TotalQABytesCommitted,
|
|
}, nil
|
|
}
|
|
|
|
func (s *state1) MinerPower(addr address.Address) (Claim, bool, error) {
|
|
claims, err := adt1.AsMap(s.store, s.Claims)
|
|
if err != nil {
|
|
return Claim{}, false, err
|
|
}
|
|
var claim power1.Claim
|
|
ok, err := claims.Get(abi.AddrKey(addr), &claim)
|
|
if err != nil {
|
|
return Claim{}, false, err
|
|
}
|
|
return Claim{
|
|
RawBytePower: claim.RawBytePower,
|
|
QualityAdjPower: claim.QualityAdjPower,
|
|
}, ok, nil
|
|
}
|
|
|
|
func (s *state1) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) {
|
|
return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a)
|
|
}
|
|
|
|
func (s *state1) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
|
|
return builtin.FromV1FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil
|
|
}
|
|
|
|
func (s *state1) MinerCounts() (uint64, uint64, error) {
|
|
return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil
|
|
}
|
|
|
|
func (s *state1) ListAllMiners() ([]address.Address, error) {
|
|
claims, err := adt1.AsMap(s.store, s.Claims)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var miners []address.Address
|
|
err = claims.ForEach(nil, func(k string) error {
|
|
a, err := address.NewFromBytes([]byte(k))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
miners = append(miners, a)
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return miners, nil
|
|
}
|