2020-09-18 21:20:53 +00:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/cbor"
|
2020-09-18 21:59:27 +00:00
|
|
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-09-19 03:46:03 +00:00
|
|
|
builtin1 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
2020-09-18 21:20:53 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
|
|
|
switch act.Code {
|
2020-09-18 21:59:27 +00:00
|
|
|
case builtin0.AccountActorCodeID:
|
|
|
|
out := state0{store: store}
|
2020-09-18 21:20:53 +00:00
|
|
|
err := store.Get(store.Context(), act.Head, &out)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &out, nil
|
2020-09-19 03:46:03 +00:00
|
|
|
case builtin1.AccountActorCodeID:
|
|
|
|
out := state1{store: store}
|
|
|
|
err := store.Get(store.Context(), act.Head, &out)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &out, nil
|
2020-09-18 21:20:53 +00:00
|
|
|
}
|
|
|
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
type State interface {
|
|
|
|
cbor.Marshaler
|
|
|
|
|
|
|
|
PubkeyAddress() (address.Address, error)
|
|
|
|
}
|