lotus/chain/types/vmcontext.go

99 lines
2.3 KiB
Go
Raw Normal View History

package types
import (
2019-10-13 09:08:34 +00:00
"context"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-amt-ipld"
"github.com/filecoin-project/lotus/chain/actors/aerrors"
2019-09-12 04:12:35 +00:00
cid "github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld"
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
Ipld() *hamt.CborIpldStore
Send(to address.Address, method uint64, value BigInt, params []byte) ([]byte, aerrors.ActorError)
BlockHeight() uint64
GasUsed() BigInt
Storage() Storage
StateTree() (StateTree, aerrors.ActorError)
VerifySignature(sig *Signature, from address.Address, data []byte) aerrors.ActorError
ChargeGas(uint64) aerrors.ActorError
GetRandomness(height uint64) ([]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
const CommitmentBytesLen = 32
type PublicSectorInfo struct {
SectorID uint64
CommR [CommitmentBytesLen]byte
}
type Candidate struct {
SectorID uint64
PartialTicket [32]byte
Ticket [32]byte
SectorChallengeIndex uint64
}
type VMSyscalls struct {
2020-01-13 20:47:27 +00:00
ValidatePoRep func(context.Context, address.Address, uint64, []byte, []byte, []byte, []byte, []byte, uint64) (bool, aerrors.ActorError)
VerifyFallbackPost func(ctx context.Context,
sectorSize uint64,
sectorInfo []PublicSectorInfo,
2020-01-13 20:47:27 +00:00
challengeSeed []byte,
proof []byte,
candidates []Candidate,
2020-01-13 20:47:27 +00:00
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
}
func WrapStorage(s Storage) amt.Blocks {
return &storageWrapper{s}
}