2019-07-12 10:43:15 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2019-09-12 04:12:35 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
2019-09-10 19:58:45 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
2019-07-12 10:43:15 +00:00
|
|
|
)
|
|
|
|
|
2019-07-12 03:59:55 +00:00
|
|
|
type Storage interface {
|
2019-09-10 19:58:45 +00:00
|
|
|
Put(cbg.CBORMarshaler) (cid.Cid, aerrors.ActorError)
|
|
|
|
Get(cid.Cid, cbg.CBORUnmarshaler) aerrors.ActorError
|
2019-07-12 03:59:55 +00:00
|
|
|
|
|
|
|
GetHead() cid.Cid
|
|
|
|
|
|
|
|
// Commit sets the new head of the actors state as long as the current
|
|
|
|
// state matches 'oldh'
|
2019-07-22 16:08:54 +00:00
|
|
|
Commit(oldh cid.Cid, newh cid.Cid) aerrors.ActorError
|
2019-07-12 03:59:55 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 16:40:58 +00:00
|
|
|
type StateTree interface {
|
2019-07-22 18:17:42 +00:00
|
|
|
SetActor(addr address.Address, act *Actor) error
|
2020-02-18 18:10:42 +00:00
|
|
|
// GetActor returns the actor from any type of `addr` provided.
|
2019-07-22 18:17:42 +00:00
|
|
|
GetActor(addr address.Address) (*Actor, error)
|
2019-07-12 16:40:58 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 00:01:46 +00:00
|
|
|
type storageWrapper struct {
|
|
|
|
s Storage
|
|
|
|
}
|
|
|
|
|
2019-11-22 16:41:09 +00:00
|
|
|
func (sw *storageWrapper) Put(i cbg.CBORMarshaler) (cid.Cid, error) {
|
|
|
|
c, err := sw.s.Put(i)
|
2019-08-29 00:01:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return cid.Undef, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2019-11-22 16:41:09 +00:00
|
|
|
func (sw *storageWrapper) Get(c cid.Cid, out cbg.CBORUnmarshaler) error {
|
|
|
|
if err := sw.s.Get(c, out); err != nil {
|
2019-08-29 00:01:46 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|