2020-09-17 08:17:14 +00:00
|
|
|
package verifreg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2020-09-18 21:59:27 +00:00
|
|
|
verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
|
|
|
|
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
2020-09-17 08:17:14 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
)
|
|
|
|
|
2020-09-21 06:19:32 +00:00
|
|
|
var _ State = (*state0)(nil)
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
type state0 struct {
|
|
|
|
verifreg0.State
|
2020-09-17 08:17:14 +00:00
|
|
|
store adt.Store
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
func (s *state0) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) {
|
2020-09-17 08:17:14 +00:00
|
|
|
if addr.Protocol() != address.ID {
|
|
|
|
return false, big.Zero(), xerrors.Errorf("can only look up ID addresses")
|
|
|
|
}
|
|
|
|
|
2020-09-18 21:59:27 +00:00
|
|
|
vh, err := adt0.AsMap(s.store, s.VerifiedClients)
|
2020-09-17 08:17:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, big.Zero(), xerrors.Errorf("loading verified clients: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var dcap abi.StoragePower
|
|
|
|
if found, err := vh.Get(abi.AddrKey(addr), &dcap); err != nil {
|
|
|
|
return false, big.Zero(), xerrors.Errorf("looking up verified clients: %w", err)
|
|
|
|
} else if !found {
|
|
|
|
return false, big.Zero(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, dcap, nil
|
|
|
|
}
|