-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chain actors: codegen templates for all actors
- Loading branch information
Showing
49 changed files
with
2,647 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cron | ||
|
||
import ( | ||
builtin{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin" | ||
) | ||
|
||
var ( | ||
Address = builtin{{.latestVersion}}.CronActorAddr | ||
Methods = builtin{{.latestVersion}}.MethodsCron | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package init | ||
|
||
import ( | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/cbor" | ||
"github.com/ipfs/go-cid" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||
"github.com/filecoin-project/lotus/chain/actors/builtin" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/node/modules/dtypes" | ||
{{range .versions}} | ||
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"{{end}} | ||
) | ||
|
||
func init() { | ||
{{range .versions}} builtin.RegisterActorState(builtin{{.}}.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { | ||
return load{{.}}(store, root) | ||
}) | ||
{{end}}} | ||
|
||
var ( | ||
Address = builtin{{.latestVersion}}.InitActorAddr | ||
Methods = builtin{{.latestVersion}}.MethodsInit | ||
) | ||
|
||
func Load(store adt.Store, act *types.Actor) (State, error) { | ||
switch act.Code { | ||
{{range .versions}} case builtin{{.}}.InitActorCodeID: | ||
return load{{.}}(store, act.Head) | ||
{{end}} } | ||
return nil, xerrors.Errorf("unknown actor code %s", act.Code) | ||
} | ||
|
||
type State interface { | ||
cbor.Marshaler | ||
|
||
ResolveAddress(address address.Address) (address.Address, bool, error) | ||
MapAddressToNewID(address address.Address) (address.Address, error) | ||
NetworkName() (dtypes.NetworkName, error) | ||
|
||
ForEachActor(func(id abi.ActorID, address address.Address) error) error | ||
|
||
// Remove exists to support tooling that manipulates state for testing. | ||
// It should not be used in production code, as init actor entries are | ||
// immutable. | ||
Remove(addrs ...address.Address) error | ||
|
||
// Sets the network's name. This should only be used on upgrade/fork. | ||
SetNetworkName(name string) error | ||
|
||
addressMap() (adt.Map, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package init | ||
|
||
import ( | ||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
{{if (ge .v 3)}} builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" | ||
{{end}} "github.com/ipfs/go-cid" | ||
cbg "github.com/whyrusleeping/cbor-gen" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||
"github.com/filecoin-project/lotus/node/modules/dtypes" | ||
|
||
init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init" | ||
adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" | ||
) | ||
|
||
var _ State = (*state{{.v}})(nil) | ||
|
||
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { | ||
out := state{{.v}}{store: store} | ||
err := store.Get(store.Context(), root, &out) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &out, nil | ||
} | ||
|
||
type state{{.v}} struct { | ||
init{{.v}}.State | ||
store adt.Store | ||
} | ||
|
||
func (s *state{{.v}}) ResolveAddress(address address.Address) (address.Address, bool, error) { | ||
return s.State.ResolveAddress(s.store, address) | ||
} | ||
|
||
func (s *state{{.v}}) MapAddressToNewID(address address.Address) (address.Address, error) { | ||
return s.State.MapAddressToNewID(s.store, address) | ||
} | ||
|
||
func (s *state{{.v}}) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { | ||
addrs, err := adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) | ||
if err != nil { | ||
return err | ||
} | ||
var actorID cbg.CborInt | ||
return addrs.ForEach(&actorID, func(key string) error { | ||
addr, err := address.NewFromBytes([]byte(key)) | ||
if err != nil { | ||
return err | ||
} | ||
return cb(abi.ActorID(actorID), addr) | ||
}) | ||
} | ||
|
||
func (s *state{{.v}}) NetworkName() (dtypes.NetworkName, error) { | ||
return dtypes.NetworkName(s.State.NetworkName), nil | ||
} | ||
|
||
func (s *state{{.v}}) SetNetworkName(name string) error { | ||
s.State.NetworkName = name | ||
return nil | ||
} | ||
|
||
func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) { | ||
m, err := adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) | ||
if err != nil { | ||
return err | ||
} | ||
for _, addr := range addrs { | ||
if err = m.Delete(abi.AddrKey(addr)); err != nil { | ||
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err) | ||
} | ||
} | ||
amr, err := m.Root() | ||
if err != nil { | ||
return xerrors.Errorf("failed to get address map root: %w", err) | ||
} | ||
s.State.AddressMap = amr | ||
return nil | ||
} | ||
|
||
func (s *state{{.v}}) addressMap() (adt.Map, error) { | ||
return adt{{.v}}.AsMap(s.store, s.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) | ||
} |
Oops, something went wrong.