diff --git a/api/clients/sign_client.go b/api/clients/sign_client.go index cd9bc3c5..8e5919b2 100644 --- a/api/clients/sign_client.go +++ b/api/clients/sign_client.go @@ -53,9 +53,9 @@ func NewISignerClient(mctx metrics.MetricsCtx, lc fx.Lifecycle, params SignerPar var closer jsonrpc.ClientCloser var err error switch params.SignerCfg.SignerType { - case "wallet": + case config.SignerTypeWallet: signer, closer, err = newWalletClient(context.Background(), params.SignerCfg.Token, params.SignerCfg.Url) - case "gateway": + case config.SignerTypeGateway: signer, closer, err = newGatewayWalletClient(context.Background(), params.Mgr, params.SignerCfg) default: return nil, fmt.Errorf("unsupport sign type %s", params.SignerCfg.SignerType) diff --git a/cmd/venus-market/main.go b/cmd/venus-market/main.go index 498d0ffc..bf7c128b 100644 --- a/cmd/venus-market/main.go +++ b/cmd/venus-market/main.go @@ -1,12 +1,13 @@ package main import ( - "context" "fmt" "log" "os" "strings" + "github.com/filecoin-project/venus-market/v2/cmd" + logging "github.com/ipfs/go-log/v2" "github.com/urfave/cli/v2" @@ -15,7 +16,6 @@ import ( "github.com/ipfs-force-community/venus-common-utils/builder" cli2 "github.com/filecoin-project/venus-market/v2/cli" - cmd "github.com/filecoin-project/venus-market/v2/cmd" "github.com/filecoin-project/venus-market/v2/config" _ "github.com/filecoin-project/venus-market/v2/network" "github.com/filecoin-project/venus-market/v2/version" @@ -33,10 +33,6 @@ var ( ExtractApiKey = builder.NextInvoke() ) -type contextKey string - -const contextKeyMarketConfig = contextKey("market-config") - var ( RepoFlag = &cli.StringFlag{ Name: "repo", @@ -158,9 +154,9 @@ func main() { } } -func prepare(cctx *cli.Context) (*config.MarketConfig, error) { +func prepare(cctx *cli.Context, defSignerType config.SignerType) (*config.MarketConfig, error) { if !cctx.IsSet(HidenSignerTypeFlag.Name) { - if err := cctx.Set(HidenSignerTypeFlag.Name, "wallet"); err != nil { + if err := cctx.Set(HidenSignerTypeFlag.Name, defSignerType); err != nil { return nil, fmt.Errorf("set %s with wallet failed %v", HidenSignerTypeFlag.Name, err) } } @@ -196,7 +192,7 @@ func prepare(cctx *cli.Context) (*config.MarketConfig, error) { } else { return nil, err } - return cfg, nil + return cfg, cmd.FetchAndLoadBundles(cctx.Context, cfg.Node) } func flagData(cctx *cli.Context, cfg *config.MarketConfig) error { @@ -287,12 +283,3 @@ func flagData(cctx *cli.Context, cfg *config.MarketConfig) error { } return nil } - -var beforeCmdRun = func(cctx *cli.Context) error { - cfg, err := prepare(cctx) - if err != nil { - return err - } - cctx.Context = context.WithValue(cctx.Context, contextKeyMarketConfig, cfg) - return cmd.FetchAndLoadBundles(cctx.Context, cfg.Node) -} diff --git a/cmd/venus-market/pool-run.go b/cmd/venus-market/pool-run.go index 526eabdb..3af67eca 100644 --- a/cmd/venus-market/pool-run.go +++ b/cmd/venus-market/pool-run.go @@ -50,16 +50,14 @@ var poolRunCmd = &cli.Command{ MinerListFlag, PaymentAddressFlag, }, - Before: beforeCmdRun, Action: poolDaemon, } func poolDaemon(cctx *cli.Context) error { utils.SetupLogLevels() - ctx := cctx.Context - cfg, ok := cctx.Context.Value(contextKeyMarketConfig).(*config.MarketConfig) - if !ok { - return fmt.Errorf("market config not exists") + cfg, err := prepare(cctx, config.SignerTypeGateway) + if err != nil { + return fmt.Errorf("prepare pool run failed:%w", err) } // venus-auth is must in 'pool' mode @@ -67,6 +65,8 @@ func poolDaemon(cctx *cli.Context) error { return fmt.Errorf("auth-url is required in 'pool' mode") } + ctx := cctx.Context + // 'NewAuthClient' never returns an error, no needs to check authClient, _ := jwtclient.NewAuthClient(cfg.AuthNode.Url) diff --git a/cmd/venus-market/solo-run.go b/cmd/venus-market/solo-run.go index b4199d95..9a53dd33 100644 --- a/cmd/venus-market/solo-run.go +++ b/cmd/venus-market/solo-run.go @@ -47,16 +47,16 @@ var soloRunCmd = &cli.Command{ PaymentAddressFlag, }, Action: soloDaemon, - Before: beforeCmdRun, } func soloDaemon(cctx *cli.Context) error { utils.SetupLogLevels() - ctx := cctx.Context - cfg, ok := cctx.Context.Value(contextKeyMarketConfig).(*config.MarketConfig) - if !ok { - return fmt.Errorf("market config not exists") + + cfg, err := prepare(cctx, config.SignerTypeWallet) + if err != nil { + return fmt.Errorf("prepare solo run failed:%w", err) } + ctx := cctx.Context resAPI := &impl.MarketNodeImpl{} shutdownChan := make(chan struct{}) diff --git a/config/config.go b/config/config.go index eb143cb7..e3ad86dc 100644 --- a/config/config.go +++ b/config/config.go @@ -50,8 +50,15 @@ type Common struct { Libp2p Libp2p } +type SignerType = string + +const ( + SignerTypeWallet = "wallet" + SignerTypeGateway = "gateway" +) + type Signer struct { - SignerType string `toml:"Type"` // wallet/gateway + SignerType SignerType `toml:"Type"` // wallet/gateway Url string Token string }