deals: use GetWorkerAddr
This commit is contained in:
parent
3c8ca25764
commit
9733e1f011
@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"math"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/wallet"
|
||||
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
||||
"github.com/filecoin-project/go-lotus/node/modules/dtypes"
|
||||
|
||||
@ -35,8 +35,8 @@ type MinerDeal struct {
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
w *wallet.Wallet
|
||||
sb *sectorbuilder.SectorBuilder
|
||||
sb *sectorbuilder.SectorBuilder
|
||||
full api.FullNode
|
||||
|
||||
// TODO: Use a custom protocol or graphsync in the future
|
||||
// TODO: GC
|
||||
@ -60,7 +60,7 @@ type dealUpdate struct {
|
||||
mut func(*MinerDeal)
|
||||
}
|
||||
|
||||
func NewHandler(w *wallet.Wallet, ds dtypes.MetadataDS, sb *sectorbuilder.SectorBuilder, dag dtypes.StagingDAG) (*Handler, error) {
|
||||
func NewHandler(ds dtypes.MetadataDS, sb *sectorbuilder.SectorBuilder, dag dtypes.StagingDAG, fullNode api.FullNode) (*Handler, error) {
|
||||
addr, err := ds.Get(datastore.NewKey("miner-address"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -71,9 +71,9 @@ func NewHandler(w *wallet.Wallet, ds dtypes.MetadataDS, sb *sectorbuilder.Sector
|
||||
}
|
||||
|
||||
return &Handler{
|
||||
w: w,
|
||||
sb: sb,
|
||||
dag: dag,
|
||||
full: fullNode,
|
||||
|
||||
conns: map[cid.Cid]inet.Stream{},
|
||||
|
||||
|
@ -1,13 +1,17 @@
|
||||
package deals
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/chain/actors"
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/lib/cborrpc"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
inet "github.com/libp2p/go-libp2p-core/network"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
inet "github.com/libp2p/go-libp2p-core/network"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
@ -68,18 +72,21 @@ func (h *Handler) sendSignedResponse(resp StorageDealResponse) error {
|
||||
return xerrors.Errorf("serializing response: %w", err)
|
||||
}
|
||||
|
||||
def, err := h.w.ListAddrs()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return xerrors.Errorf("listing wallet addresses: %w", err)
|
||||
getworker := &types.Message{
|
||||
To: h.actor,
|
||||
From: h.actor,
|
||||
Method: actors.MAMethods.GetWorkerAddr,
|
||||
}
|
||||
if len(def) != 1 {
|
||||
// NOTE: If this ever happens for a good reason, implement this with GetWorker on the miner actor
|
||||
// TODO: implement with GetWorker on the miner actor
|
||||
return xerrors.Errorf("expected only 1 address in wallet, got %d", len(def))
|
||||
r, err := h.full.ChainCall(context.TODO(), getworker, nil)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting worker address: %w", err)
|
||||
}
|
||||
worker, err := address.NewFromBytes(r.Return)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sig, err := h.w.Sign(def[0], msg)
|
||||
sig, err := h.full.WalletSign(context.TODO(), worker, msg)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to sign response message: %w", err)
|
||||
}
|
||||
|
@ -181,7 +181,6 @@ func Online() Option {
|
||||
libp2p(),
|
||||
|
||||
// common
|
||||
Override(new(*wallet.Wallet), wallet.NewWallet),
|
||||
|
||||
// Full node
|
||||
|
||||
@ -191,6 +190,7 @@ func Online() Option {
|
||||
Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages),
|
||||
|
||||
Override(new(*store.ChainStore), modules.ChainStore),
|
||||
Override(new(*wallet.Wallet), wallet.NewWallet),
|
||||
|
||||
Override(new(dtypes.ChainGCLocker), blockstore.NewGCLocker),
|
||||
Override(new(dtypes.ChainGCBlockstore), modules.ChainGCBlockstore),
|
||||
|
Loading…
Reference in New Issue
Block a user