Move more logic into statemanager

This commit is contained in:
Łukasz Magiera 2019-09-17 10:00:38 +02:00
parent 3f32b75b74
commit 567ae92ff2
2 changed files with 19 additions and 14 deletions

View File

@ -2,6 +2,7 @@ package stmgr
import (
"context"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/address"
@ -104,3 +105,20 @@ func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr add
return mpow, tpow, nil
}
func GetMinerPeerID(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (peer.ID, error) {
recp, err := sm.Call(ctx, &types.Message{
To: maddr,
From: maddr,
Method: actors.MAMethods.GetWorkerAddr,
}, ts)
if err != nil {
return "", xerrors.Errorf("callRaw failed: %w", err)
}
if recp.ExitCode != 0 {
return "", xerrors.Errorf("getting miner peer ID failed (exit code %d)", recp.ExitCode)
}
return peer.IDFromBytes(recp.Return)
}

View File

@ -187,20 +187,7 @@ func (a *StateAPI) StateMinerWorker(ctx context.Context, m address.Address, ts *
}
func (a *StateAPI) StateMinerPeerID(ctx context.Context, m address.Address, ts *types.TipSet) (peer.ID, error) {
ret, err := a.StateManager.Call(ctx, &types.Message{
From: m,
To: m,
Method: actors.MAMethods.GetPeerID,
}, ts)
if err != nil {
return "", xerrors.Errorf("failed to get miner worker addr: %w", err)
}
if ret.ExitCode != 0 {
return "", xerrors.Errorf("failed to get miner worker addr (exit code %d)", ret.ExitCode)
}
return peer.IDFromBytes(ret.Return)
return stmgr.GetMinerPeerID(ctx, a.StateManager, ts, m)
}
func (a *StateAPI) StateCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {