lotus/chain/types/vmcontext.go

74 lines
1.9 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-02-08 02:18:32 +00:00
"github.com/filecoin-project/specs-actors/actors/abi"
2020-02-12 23:52:36 +00:00
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/specs-actors/actors/runtime"
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)
2020-02-17 21:11:03 +00:00
ActorCodeCID(address.Address) (cid.Cid, error)
2020-02-21 16:57:40 +00:00
LookupID(address.Address) (address.Address, error)
2020-02-12 23:52:36 +00:00
VerifySignature(sig *crypto.Signature, from address.Address, data []byte) aerrors.ActorError
ChargeGas(uint64) aerrors.ActorError
2020-02-23 20:00:47 +00:00
GetRandomness(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) ([]byte, aerrors.ActorError)
2019-09-12 04:12:35 +00:00
GetBalance(address.Address) (BigInt, aerrors.ActorError)
Sys() runtime.Syscalls
2019-10-13 09:08:34 +00:00
Context() context.Context
}
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
}