lotus/chain/types/vmcontext.go

82 lines
2.2 KiB
Go
Raw Normal View History

package types
import (
2019-10-13 09:08:34 +00:00
"context"
2020-01-22 21:29:19 +00:00
2020-01-13 20:47:27 +00:00
"github.com/filecoin-project/go-sectorbuilder"
2020-02-08 02:18:32 +00:00
"github.com/filecoin-project/specs-actors/actors/abi"
2019-10-13 09:08:34 +00:00
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/actors/aerrors"
2019-09-12 04:12:35 +00:00
cid "github.com/ipfs/go-cid"
2020-02-04 22:19:05 +00:00
cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen"
)
type Storage interface {
Put(cbg.CBORMarshaler) (cid.Cid, aerrors.ActorError)
Get(cid.Cid, cbg.CBORUnmarshaler) aerrors.ActorError
GetHead() cid.Cid
// Commit sets the new head of the actors state as long as the current
// state matches 'oldh'
Commit(oldh cid.Cid, newh cid.Cid) aerrors.ActorError
}
type StateTree interface {
SetActor(addr address.Address, act *Actor) error
GetActor(addr address.Address) (*Actor, error)
}
type VMContext interface {
Message() *Message
Origin() address.Address
2020-02-04 22:19:05 +00:00
Ipld() cbor.IpldStore
Send(to address.Address, method abi.MethodNum, value BigInt, params []byte) ([]byte, aerrors.ActorError)
2020-02-08 02:18:32 +00:00
BlockHeight() abi.ChainEpoch
GasUsed() BigInt
Storage() Storage
StateTree() (StateTree, aerrors.ActorError)
VerifySignature(sig *Signature, from address.Address, data []byte) aerrors.ActorError
ChargeGas(uint64) aerrors.ActorError
2020-02-08 02:18:32 +00:00
GetRandomness(height abi.ChainEpoch) ([]byte, aerrors.ActorError)
2019-09-12 04:12:35 +00:00
GetBalance(address.Address) (BigInt, aerrors.ActorError)
Sys() *VMSyscalls
2019-10-13 09:08:34 +00:00
Context() context.Context
}
2019-08-29 00:01:46 +00:00
type VMSyscalls struct {
2020-02-08 02:18:32 +00:00
ValidatePoRep func(context.Context, address.Address, abi.SectorSize, []byte, []byte, []byte, []byte, []byte, abi.SectorNumber) (bool, aerrors.ActorError)
2020-01-13 20:47:27 +00:00
VerifyFallbackPost func(ctx context.Context,
2020-02-08 02:18:32 +00:00
sectorSize abi.SectorSize,
2020-01-13 20:47:27 +00:00
sectorInfo sectorbuilder.SortedPublicSectorInfo,
challengeSeed []byte,
proof []byte,
candidates []sectorbuilder.EPostCandidate,
proverID address.Address,
faults uint64) (bool, error)
}
2019-08-29 00:01:46 +00:00
type storageWrapper struct {
s Storage
}
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
}
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
}