2022-09-21 19:51:28 +00:00
|
|
|
package datacap
|
|
|
|
|
|
|
|
import (
|
2022-11-16 22:32:59 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2022-09-21 19:51:28 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
2022-09-22 20:25:51 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-09-21 19:51:28 +00:00
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
2023-07-07 09:56:30 +00:00
|
|
|
builtin12 "github.com/filecoin-project/go-state-types/builtin"
|
2022-09-21 19:51:28 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
2022-12-13 23:02:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/manifest"
|
2022-09-21 19:51:28 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-07-07 09:56:30 +00:00
|
|
|
Address = builtin12.DatacapActorAddr
|
|
|
|
Methods = builtin12.MethodsDatacap
|
2022-09-21 19:51:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
|
|
|
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
|
2022-12-15 00:02:43 +00:00
|
|
|
if name != manifest.DatacapKey {
|
2022-09-21 19:51:28 +00:00
|
|
|
return nil, xerrors.Errorf("actor code is not datacap: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch av {
|
|
|
|
|
|
|
|
case actorstypes.Version9:
|
|
|
|
return load9(store, act.Head)
|
|
|
|
|
2022-11-08 04:55:56 +00:00
|
|
|
case actorstypes.Version10:
|
|
|
|
return load10(store, act.Head)
|
|
|
|
|
2023-03-29 16:05:42 +00:00
|
|
|
case actorstypes.Version11:
|
|
|
|
return load11(store, act.Head)
|
|
|
|
|
2023-07-07 09:56:30 +00:00
|
|
|
case actorstypes.Version12:
|
|
|
|
return load12(store, act.Head)
|
|
|
|
|
2022-09-21 19:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeState(store adt.Store, av actorstypes.Version, governor address.Address, bitwidth uint64) (State, error) {
|
|
|
|
switch av {
|
|
|
|
|
|
|
|
case actorstypes.Version9:
|
|
|
|
return make9(store, governor, bitwidth)
|
|
|
|
|
2022-11-08 04:55:56 +00:00
|
|
|
case actorstypes.Version10:
|
|
|
|
return make10(store, governor, bitwidth)
|
|
|
|
|
2023-03-29 16:05:42 +00:00
|
|
|
case actorstypes.Version11:
|
|
|
|
return make11(store, governor, bitwidth)
|
|
|
|
|
2023-07-07 09:56:30 +00:00
|
|
|
case actorstypes.Version12:
|
|
|
|
return make12(store, governor, bitwidth)
|
|
|
|
|
2022-09-21 19:51:28 +00:00
|
|
|
default:
|
|
|
|
return nil, xerrors.Errorf("datacap actor only valid for actors v9 and above, got %d", av)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type State interface {
|
|
|
|
cbor.Marshaler
|
|
|
|
|
2022-11-16 22:32:59 +00:00
|
|
|
Code() cid.Cid
|
|
|
|
ActorKey() string
|
|
|
|
ActorVersion() actorstypes.Version
|
|
|
|
|
2022-09-22 20:25:51 +00:00
|
|
|
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
|
|
|
|
VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error)
|
2022-09-21 19:51:28 +00:00
|
|
|
Governor() (address.Address, error)
|
|
|
|
GetState() interface{}
|
|
|
|
}
|
2022-11-16 22:32:59 +00:00
|
|
|
|
|
|
|
func AllCodes() []cid.Cid {
|
|
|
|
return []cid.Cid{
|
|
|
|
(&state9{}).Code(),
|
2022-11-22 18:03:02 +00:00
|
|
|
(&state10{}).Code(),
|
2023-03-29 16:05:42 +00:00
|
|
|
(&state11{}).Code(),
|
2023-07-07 09:56:30 +00:00
|
|
|
(&state12{}).Code(),
|
2022-11-16 22:32:59 +00:00
|
|
|
}
|
|
|
|
}
|