Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: create incorrect signer type #150

Merged
merged 3 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/clients/sign_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 5 additions & 18 deletions cmd/venus-market/main.go
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"
Expand All @@ -33,10 +33,6 @@ var (
ExtractApiKey = builder.NextInvoke()
)

type contextKey string

const contextKeyMarketConfig = contextKey("market-config")

var (
RepoFlag = &cli.StringFlag{
Name: "repo",
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
10 changes: 5 additions & 5 deletions cmd/venus-market/pool-run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ 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
if len(cfg.AuthNode.Url) == 0 {
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)

Expand Down
10 changes: 5 additions & 5 deletions cmd/venus-market/solo-run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
9 changes: 8 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down