Add GetPower
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
68a437d8b8
commit
6ee1b6fc84
@ -89,12 +89,24 @@ type StorageMinerConstructorParams struct {
|
|||||||
|
|
||||||
func (sma StorageMinerActor) Exports() []interface{} {
|
func (sma StorageMinerActor) Exports() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
sma.StorageMinerActor,
|
0: sma.StorageMinerConstructor,
|
||||||
sma.CommitSector,
|
1: sma.CommitSector,
|
||||||
|
//2: sma.SubmitPost,
|
||||||
|
//3: sma.SlashStorageFault,
|
||||||
|
//4: sma.GetCurrentProvingSet,
|
||||||
|
//5: sma.ArbitrateDeal,
|
||||||
|
//6: sma.DePledge,
|
||||||
|
//7: sma.GetOwner,
|
||||||
|
//8: sma.GetWorkerAddr,
|
||||||
|
9: sma.GetPower,
|
||||||
|
//10: sma.GetPeerID,
|
||||||
|
//11: sma.GetSectorSize,
|
||||||
|
//12: sma.UpdatePeerID,
|
||||||
|
//13: sma.ChangeWorker,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMinerActor) StorageMinerActor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) (types.InvokeRet, error) {
|
func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) (types.InvokeRet, error) {
|
||||||
var self StorageMinerActorState
|
var self StorageMinerActorState
|
||||||
self.Owner = params.Owner
|
self.Owner = params.Owner
|
||||||
self.Worker = params.Worker
|
self.Worker = params.Worker
|
||||||
@ -209,6 +221,17 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
|
|||||||
return types.InvokeRet{}, nil
|
return types.InvokeRet{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sma StorageMinerActor) GetPower(act *types.Actor, vmctx types.VMContext, params *struct{}) (types.InvokeRet, error) {
|
||||||
|
var self StorageMinerActorState
|
||||||
|
state := vmctx.Storage().GetHead()
|
||||||
|
if err := vmctx.Storage().Get(state, &self); err != nil {
|
||||||
|
return types.InvokeRet{}, err
|
||||||
|
}
|
||||||
|
return types.InvokeRet{
|
||||||
|
Result: self.Power.Bytes(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func SectorIsUnique(cst *hamt.CborIpldStore, sroot cid.Cid, sid types.BigInt) (bool, error) {
|
func SectorIsUnique(cst *hamt.CborIpldStore, sroot cid.Cid, sid types.BigInt) (bool, error) {
|
||||||
nd, err := hamt.LoadNode(context.TODO(), cst, sroot)
|
nd, err := hamt.LoadNode(context.TODO(), cst, sroot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,10 +19,14 @@ type StorageMarketActor struct{}
|
|||||||
|
|
||||||
func (sma StorageMarketActor) Exports() []interface{} {
|
func (sma StorageMarketActor) Exports() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
nil,
|
//0: sma.StorageMarketConstructor,
|
||||||
sma.CreateStorageMiner,
|
1: sma.CreateStorageMiner,
|
||||||
nil, // TODO: slash consensus fault
|
//2: sma.SlashConsensusFault,
|
||||||
sma.UpdateStorage,
|
3: sma.UpdateStorage,
|
||||||
|
4: sma.GetTotalStorage,
|
||||||
|
5: sma.PowerLookup,
|
||||||
|
//6: sma.IsMiner,
|
||||||
|
//7: sma.StorageCollateralForSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +127,7 @@ func (sma StorageMarketActor) UpdateStorage(act *types.Actor, vmctx types.VMCont
|
|||||||
return types.InvokeRet{}, nil
|
return types.InvokeRet{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sma StorageMarketActor) GetTotalStorage(act *types.Actor, vmctx types.VMContext, params struct{}) (types.InvokeRet, error) {
|
func (sma StorageMarketActor) GetTotalStorage(act *types.Actor, vmctx types.VMContext, params *struct{}) (types.InvokeRet, error) {
|
||||||
var self StorageMarketState
|
var self StorageMarketState
|
||||||
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil {
|
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &self); err != nil {
|
||||||
return types.InvokeRet{}, err
|
return types.InvokeRet{}, err
|
||||||
@ -151,7 +155,7 @@ func (sma StorageMarketActor) PowerLookup(act *types.Actor, vmctx types.VMContex
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, code, err := vmctx.Send(params.Miner, 9999, types.NewInt(0), nil)
|
ret, code, err := vmctx.Send(params.Miner, 9, types.NewInt(0), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.InvokeRet{}, err
|
return types.InvokeRet{}, err
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,8 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
|||||||
exports := instance.Exports()
|
exports := instance.Exports()
|
||||||
for i, m := range exports {
|
for i, m := range exports {
|
||||||
i := i
|
i := i
|
||||||
newErr := func(str string) error {
|
newErr := func(format string, args ...interface{}) error {
|
||||||
|
str := fmt.Sprintf(format, args)
|
||||||
return fmt.Errorf("transform(%s) export(%d): %s", itype.Name(), i, str)
|
return fmt.Errorf("transform(%s) export(%d): %s", itype.Name(), i, str)
|
||||||
}
|
}
|
||||||
if m == nil {
|
if m == nil {
|
||||||
@ -86,7 +87,8 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if t.In(2).Kind() != reflect.Ptr {
|
if t.In(2).Kind() != reflect.Ptr {
|
||||||
return nil, newErr("parameter has to be a pointer to parameter")
|
return nil, newErr("parameter has to be a pointer to parameter, is: %s",
|
||||||
|
t.In(2).Kind())
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.NumOut() != 2 {
|
if t.NumOut() != 2 {
|
||||||
|
Loading…
Reference in New Issue
Block a user