2019-07-12 10:43:15 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2019-10-13 09:08:34 +00:00
|
|
|
"context"
|
|
|
|
|
2019-09-12 04:12:35 +00:00
|
|
|
amt "github.com/filecoin-project/go-amt-ipld"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/address"
|
2019-09-12 04:12:35 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
|
|
|
hamt "github.com/ipfs/go-hamt-ipld"
|
2019-09-10 19:58:45 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
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
|
|
|
|
GetActor(addr address.Address) (*Actor, error)
|
2019-07-12 16:40:58 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 10:43:15 +00:00
|
|
|
type VMContext interface {
|
|
|
|
Message() *Message
|
2019-07-16 16:40:25 +00:00
|
|
|
Origin() address.Address
|
2019-07-12 10:43:15 +00:00
|
|
|
Ipld() *hamt.CborIpldStore
|
2019-07-22 16:08:54 +00:00
|
|
|
Send(to address.Address, method uint64, value BigInt, params []byte) ([]byte, aerrors.ActorError)
|
2019-07-12 10:43:15 +00:00
|
|
|
BlockHeight() uint64
|
|
|
|
GasUsed() BigInt
|
2019-07-12 03:59:55 +00:00
|
|
|
Storage() Storage
|
2019-07-22 16:08:54 +00:00
|
|
|
StateTree() (StateTree, aerrors.ActorError)
|
2019-08-09 21:41:50 +00:00
|
|
|
VerifySignature(sig *Signature, from address.Address, data []byte) aerrors.ActorError
|
2019-08-15 16:23:28 +00:00
|
|
|
ChargeGas(uint64) aerrors.ActorError
|
2019-09-19 13:32:00 +00:00
|
|
|
GetRandomness(height uint64) ([]byte, aerrors.ActorError)
|
2019-09-12 04:12:35 +00:00
|
|
|
GetBalance(address.Address) (BigInt, aerrors.ActorError)
|
2019-10-13 09:08:34 +00:00
|
|
|
|
|
|
|
Context() context.Context
|
2019-07-12 10:43:15 +00:00
|
|
|
}
|
2019-08-29 00:01:46 +00:00
|
|
|
|
|
|
|
type storageWrapper struct {
|
|
|
|
s Storage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sw *storageWrapper) Put(i interface{}) (cid.Cid, error) {
|
2019-09-10 19:58:45 +00:00
|
|
|
c, err := sw.s.Put(i.(cbg.CBORMarshaler))
|
2019-08-29 00:01:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return cid.Undef, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sw *storageWrapper) Get(c cid.Cid, out interface{}) error {
|
2019-09-10 19:58:45 +00:00
|
|
|
if err := sw.s.Get(c, out.(cbg.CBORUnmarshaler)); err != nil {
|
2019-08-29 00:01:46 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func WrapStorage(s Storage) amt.Blocks {
|
|
|
|
return &storageWrapper{s}
|
|
|
|
}
|