2021-03-12 01:35:31 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
2021-03-12 08:39:20 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/impl/full"
|
2021-03-12 01:35:31 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
|
|
|
"github.com/filecoin-project/lotus/paychmgr"
|
|
|
|
"github.com/ipfs/go-datastore"
|
|
|
|
"github.com/ipfs/go-datastore/namespace"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewManager(mctx helpers.MetricsCtx, lc fx.Lifecycle, sm stmgr.StateManagerAPI, pchstore *paychmgr.Store, api paychmgr.PaychAPI) *paychmgr.Manager {
|
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
|
|
ctx, shutdown := context.WithCancel(ctx)
|
|
|
|
|
|
|
|
return paychmgr.NewManager(ctx, shutdown, sm, pchstore, api)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPaychStore(ds dtypes.MetadataDS) *paychmgr.Store {
|
|
|
|
ds = namespace.Wrap(ds, datastore.NewKey("/paych/"))
|
|
|
|
return paychmgr.NewStore(ds)
|
|
|
|
}
|
|
|
|
|
2021-03-12 08:39:20 +00:00
|
|
|
type PaychAPI struct {
|
|
|
|
fx.In
|
|
|
|
|
|
|
|
full.MpoolAPI
|
|
|
|
full.StateAPI
|
|
|
|
}
|
|
|
|
|
2021-03-12 01:35:31 +00:00
|
|
|
// HandlePaychManager is called by dependency injection to set up hooks
|
|
|
|
func HandlePaychManager(lc fx.Lifecycle, pm *paychmgr.Manager) {
|
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStart: func(ctx context.Context) error {
|
|
|
|
return pm.Start()
|
|
|
|
},
|
|
|
|
OnStop: func(context.Context) error {
|
|
|
|
return pm.Stop()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|