2022-09-21 19:51:28 +00:00
|
|
|
package datacap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2022-11-16 22:32:59 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
2022-09-21 19:51:28 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
|
|
|
builtin{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin"
|
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-11-07 20:34:19 +00:00
|
|
|
Address = builtin{{.latestVersion}}.DatacapActorAddr
|
|
|
|
Methods = builtin{{.latestVersion}}.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 {
|
|
|
|
if name != actors.DatacapKey {
|
|
|
|
return nil, xerrors.Errorf("actor code is not datacap: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch av {
|
|
|
|
{{range .versions}}
|
|
|
|
case actorstypes.Version{{.}}:
|
|
|
|
return load{{.}}(store, act.Head)
|
|
|
|
{{end}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
{{range .versions}}
|
|
|
|
case actorstypes.Version{{.}}:
|
|
|
|
return make{{.}}(store, governor, bitwidth)
|
|
|
|
{{end}}
|
2022-11-08 04:55:26 +00:00
|
|
|
default: return nil, xerrors.Errorf("datacap actor only valid for actors v9 and above, got %d", av)
|
2022-09-21 19:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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{ {{range .versions}}
|
|
|
|
(&state{{.}}{}).Code(),
|
|
|
|
{{- end}}
|
|
|
|
}
|
|
|
|
}
|