Adapt to need changes in spec
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
1a1d2c8789
commit
d373f78326
@ -72,6 +72,7 @@ type StorageMinerActorState struct {
|
||||
}
|
||||
|
||||
type StorageMinerConstructorParams struct {
|
||||
Owner address.Address
|
||||
Worker address.Address
|
||||
SectorSize types.BigInt
|
||||
PeerID peer.ID
|
||||
@ -85,7 +86,7 @@ func (sma StorageMinerActor) Exports() []interface{} {
|
||||
|
||||
func (sma StorageMinerActor) StorageMinerActor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) (types.InvokeRet, error) {
|
||||
var self StorageMinerActorState
|
||||
self.Owner = vmctx.Message().From
|
||||
self.Owner = params.Owner
|
||||
self.Worker = params.Worker
|
||||
self.PeerID = params.PeerID
|
||||
self.SectorSize = params.SectorSize
|
||||
|
@ -30,6 +30,7 @@ type StorageMarketState struct {
|
||||
}
|
||||
|
||||
type CreateStorageMinerParams struct {
|
||||
Owner address.Address
|
||||
Worker address.Address
|
||||
SectorSize types.BigInt
|
||||
PeerID peer.ID
|
||||
@ -44,6 +45,7 @@ func (sma StorageMarketActor) CreateStorageMiner(act *types.Actor, vmctx types.V
|
||||
}
|
||||
|
||||
encoded, err := CreateExecParams(StorageMinerCodeCid, &StorageMinerConstructorParams{
|
||||
Owner: params.Owner,
|
||||
Worker: params.Worker,
|
||||
SectorSize: params.SectorSize,
|
||||
PeerID: params.PeerID,
|
||||
|
@ -21,7 +21,8 @@ func TestStorageMarketCreateMiner(t *testing.T) {
|
||||
GasPrice: types.NewInt(1),
|
||||
GasLimit: types.NewInt(1),
|
||||
Value: types.NewInt(0),
|
||||
Params: h.DumpObject(&StorageMinerConstructorParams{
|
||||
Params: h.DumpObject(&CreateStorageMinerParams{
|
||||
Owner: h.From,
|
||||
Worker: h.Third,
|
||||
SectorSize: types.NewInt(SectorSize),
|
||||
PeerID: "fakepeerid",
|
||||
|
@ -119,7 +119,9 @@ func TestVMInvokeHarness(t *testing.T) {
|
||||
Params: h.DumpObject(
|
||||
&ExecParams{
|
||||
Code: StorageMinerCodeCid,
|
||||
Params: h.DumpObject(&StorageMinerConstructorParams{}),
|
||||
Params: h.DumpObject(&StorageMinerConstructorParams{
|
||||
Owner: h.From,
|
||||
}),
|
||||
}),
|
||||
GasPrice: types.NewInt(1),
|
||||
GasLimit: types.NewInt(1),
|
||||
|
@ -24,6 +24,7 @@ type StateTree interface {
|
||||
|
||||
type VMContext interface {
|
||||
Message() *Message
|
||||
Origin() address.Address
|
||||
Ipld() *hamt.CborIpldStore
|
||||
Send(to address.Address, method uint64, value BigInt, params []byte) ([]byte, uint8, error)
|
||||
BlockHeight() uint64
|
||||
|
23
chain/vm.go
23
chain/vm.go
@ -27,6 +27,9 @@ type VMContext struct {
|
||||
// root cid of the state of the actor this invocation will be on
|
||||
sroot cid.Cid
|
||||
|
||||
// address that started invokation chain
|
||||
origin address.Address
|
||||
|
||||
storage types.Storage
|
||||
}
|
||||
|
||||
@ -72,18 +75,15 @@ func (vmc *VMContext) Ipld() *hamt.CborIpldStore {
|
||||
return vmc.cst
|
||||
}
|
||||
|
||||
func (vmc *VMContext) Origin() address.Address {
|
||||
return vmc.origin
|
||||
}
|
||||
|
||||
// Send allows the current execution context to invoke methods on other actors in the system
|
||||
func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt, params []byte) ([]byte, uint8, error) {
|
||||
|
||||
var from address.Address
|
||||
if method == 0 {
|
||||
// is constructor
|
||||
from = vmc.msg.From
|
||||
} else {
|
||||
from = vmc.msg.To
|
||||
}
|
||||
msg := &types.Message{
|
||||
From: from,
|
||||
From: vmc.msg.To,
|
||||
To: to,
|
||||
Method: method,
|
||||
Value: value,
|
||||
@ -95,7 +95,7 @@ func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
nvmctx := vmc.vm.makeVMContext(toAct.Head, msg)
|
||||
nvmctx := vmc.vm.makeVMContext(toAct.Head, vmc.origin, msg)
|
||||
|
||||
res, ret, err := vmc.vm.Invoke(toAct, nvmctx, method, params)
|
||||
if err != nil {
|
||||
@ -124,7 +124,7 @@ func (vmc *VMContext) StateTree() (types.StateTree, error) {
|
||||
return vmc.state, nil
|
||||
}
|
||||
|
||||
func (vm *VM) makeVMContext(sroot cid.Cid, msg *types.Message) *VMContext {
|
||||
func (vm *VM) makeVMContext(sroot cid.Cid, origin address.Address, msg *types.Message) *VMContext {
|
||||
cst := hamt.CSTFromBstore(vm.cs.bs)
|
||||
|
||||
return &VMContext{
|
||||
@ -132,6 +132,7 @@ func (vm *VM) makeVMContext(sroot cid.Cid, msg *types.Message) *VMContext {
|
||||
state: vm.cstate,
|
||||
sroot: sroot,
|
||||
msg: msg,
|
||||
origin: origin,
|
||||
height: vm.blockHeight,
|
||||
cst: cst,
|
||||
storage: &storage{
|
||||
@ -207,7 +208,7 @@ func (vm *VM) ApplyMessage(msg *types.Message) (*types.MessageReceipt, error) {
|
||||
}
|
||||
DepositFunds(toActor, msg.Value)
|
||||
|
||||
vmctx := vm.makeVMContext(toActor.Head, msg)
|
||||
vmctx := vm.makeVMContext(toActor.Head, msg.From, msg)
|
||||
|
||||
var errcode byte
|
||||
var ret []byte
|
||||
|
Loading…
Reference in New Issue
Block a user