add to the shim, get tests passing

This commit is contained in:
whyrusleeping 2020-01-28 10:38:39 -08:00
parent cd976ad79f
commit 8c169bb236
2 changed files with 44 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/filecoin-project/specs-actors/actors/abi"
samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
vmr "github.com/filecoin-project/specs-actors/actors/runtime" vmr "github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode" "github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
@ -161,14 +162,14 @@ func (rs *runtimeShim) Context() context.Context {
return rs.vmctx.Context() return rs.vmctx.Context()
} }
func (rs *runtimeShim) IpldGet(c cid.Cid, o vmr.CBORUnmarshalable) bool { func (rs *runtimeShim) IpldGet(c cid.Cid, o vmr.CBORUnmarshaler) bool {
if err := rs.vmctx.Storage().Get(c, o); err != nil { if err := rs.vmctx.Storage().Get(c, o); err != nil {
panic(err) // y o o o o o l l l l o o o o o panic(err) // y o o o o o l l l l o o o o o
} }
return true return true
} }
func (rs *runtimeShim) IpldPut(o vmr.CBORMarshalable) cid.Cid { func (rs *runtimeShim) IpldPut(o vmr.CBORMarshaler) cid.Cid {
c, err := rs.vmctx.Storage().Put(o) c, err := rs.vmctx.Storage().Put(o)
if err != nil { if err != nil {
panic(err) panic(err)
@ -184,6 +185,42 @@ func (rs *runtimeShim) AbortStateMsg(msg string) {
rs.Abort(101, msg) rs.Abort(101, msg)
} }
func (rs *runtimeShim) ValidateImmediateCallerType(...cid.Cid) {
log.Info("validate caller type is dumb")
}
func (rs *runtimeShim) CurrentBalance() abi.TokenAmount {
b, err := rs.vmctx.GetBalance(rs.vmctx.Message().From)
if err != nil {
rs.Abort(1, err.Error())
}
return abi.TokenAmount(b)
}
func (rs *runtimeShim) CurrEpoch() abi.ChainEpoch {
return abi.ChainEpoch(rs.vmctx.BlockHeight())
}
type dumbWrapperType struct {
val []byte
}
func (dwt *dumbWrapperType) Into(um vmr.CBORUnmarshaler) error {
return um.UnmarshalCBOR(bytes.NewReader(dwt.val))
}
func (rs *runtimeShim) Send(to address.Address, method abi.MethodNum, params abi.MethodParams, value abi.TokenAmount) (vmr.SendReturn, exitcode.ExitCode) {
ret, err := rs.vmctx.Send(to, uint64(method), types.BigInt(value), []byte(params))
if err != nil {
if err.IsFatal() {
panic(err)
}
return nil, exitcode.ExitCode(err.RetCode())
}
return &dumbWrapperType{ret}, 0
}
func (rs *runtimeShim) State() vmr.StateHandle { func (rs *runtimeShim) State() vmr.StateHandle {
return &shimStateHandle{rs: rs} return &shimStateHandle{rs: rs}
} }
@ -192,13 +229,13 @@ type shimStateHandle struct {
rs *runtimeShim rs *runtimeShim
} }
func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshalable) { func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshaler) {
if err := ssh.rs.vmctx.Storage().Get(ssh.rs.vmctx.Storage().GetHead(), obj); err != nil { if err := ssh.rs.vmctx.Storage().Get(ssh.rs.vmctx.Storage().GetHead(), obj); err != nil {
panic(err) panic(err)
} }
} }
func (ssh *shimStateHandle) Transaction(obj vmr.CBORAble, f func() interface{}) interface{} { func (ssh *shimStateHandle) Transaction(obj vmr.CBORer, f func() interface{}) interface{} {
head := ssh.rs.vmctx.Storage().GetHead() head := ssh.rs.vmctx.Storage().GetHead()
if err := ssh.rs.vmctx.Storage().Get(head, obj); err != nil { if err := ssh.rs.vmctx.Storage().Get(head, obj); err != nil {
panic(err) panic(err)
@ -217,7 +254,7 @@ func (ssh *shimStateHandle) Transaction(obj vmr.CBORAble, f func() interface{})
return out return out
} }
func (ssh *shimStateHandle) Construct(f func() vmr.CBORMarshalable) { func (ssh *shimStateHandle) Construct(f func() vmr.CBORMarshaler) {
out := f() out := f()
c, err := ssh.rs.vmctx.Storage().Put(out) c, err := ssh.rs.vmctx.Storage().Put(out)

2
go.sum
View File

@ -648,6 +648,8 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=