Skip to content

Commit

Permalink
Merge pull request #127 from ipfs-force-community/opt/remove-flag
Browse files Browse the repository at this point in the history
opt: remove disable-address-verify flag
  • Loading branch information
hunjixin authored Apr 13, 2023
2 parents dbf95c9 + bc3f892 commit dffe5de
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 25 deletions.
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ type Config struct {
Metrics *metrics.MetricsConfig
Trace *metrics.TraceConfig
RateLimit *RateLimitCofnig

DisableAddressVeirfication bool
}

type APIConfig struct {
Expand Down Expand Up @@ -50,7 +48,6 @@ func DefaultConfig() *Config {
cfg.Metrics.Exporter.Graphite.Port = 4569
cfg.Trace.ServerName = "venus-gateway"
cfg.Trace.JaegerEndpoint = ""
cfg.DisableAddressVeirfication = false

return cfg
}
Expand Down
2 changes: 1 addition & 1 deletion integrate_test/mock_deamon.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func MockMain(ctx context.Context, validateMiner []address.Address, repoPath str
}
authClient := mocks.NewMockAuthClient()
authClient.AddMockUser(ctx, user...)
walletStream := walletevent.NewWalletEventStream(ctx, authClient, requestCfg, true)
walletStream := walletevent.NewWalletEventStream(ctx, authClient, requestCfg)

proofStream := proofevent.NewProofEventStream(ctx, minerValidator, requestCfg)
marketStream := marketevent.NewMarketEventStream(ctx, minerValidator, &types.RequestConfig{
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ var runCmd = &cli.Command{
&cli.Float64Flag{Name: "trace-sampler", EnvVars: []string{"VENUS_GATEWAY_TRACE_SAMPLER"}, Value: 1.0},
&cli.StringFlag{Name: "trace-node-name", Value: "venus-gateway"},
&cli.StringFlag{Name: "rate-limit-redis", Hidden: true},
&cli.BoolFlag{Name: "disable-address-verify", Usage: "disable wallet address veirfication"},
},
Action: func(cctx *cli.Context) error {
cfg := config.DefaultConfig()
Expand Down Expand Up @@ -164,8 +163,6 @@ func parseFlag(cctx *cli.Context, cfg *config.Config) {
if cctx.IsSet("rate-limit-redis") {
cfg.RateLimit.Redis = cctx.String("rate-limit-redis")
}

cfg.DisableAddressVeirfication = cctx.Bool("disable-address-verify")
}

func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error {
Expand All @@ -178,7 +175,7 @@ func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error {

minerValidator := validator.NewMinerValidator(remoteJwtCli)

walletStream := walletevent.NewWalletEventStream(ctx, remoteJwtCli, requestCfg, cfg.DisableAddressVeirfication)
walletStream := walletevent.NewWalletEventStream(ctx, remoteJwtCli, requestCfg)

proofStream := proofevent.NewProofEventStream(ctx, minerValidator, requestCfg)
marketStream := marketevent.NewMarketEventStream(ctx, minerValidator, &types.RequestConfig{
Expand Down
3 changes: 2 additions & 1 deletion testhelper/memwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ func (m *MemWallet) WalletSign(ctx context.Context, signer address.Address, toSi
if !ok {
return nil, fmt.Errorf("address %s not found", signer)
}
return vcrypto.Sign(toSign, keyInfo.Key(), vcrypto.SigTypeSecp256k1)

return vcrypto.Sign(toSign, keyInfo.Key(), sharedTypes.AddressProtocol2SignType(signer.Protocol()))
}
18 changes: 5 additions & 13 deletions walletevent/wallet_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ type WalletEventStream struct {
authClient jwtclient.IAuthClient
randBytes []byte
*types.BaseEventStream

disableVerifyWalletAddrs bool
}

func NewWalletEventStream(ctx context.Context, authClient jwtclient.IAuthClient, cfg *types.RequestConfig, diableVerifyWalletAddrs bool) *WalletEventStream {
func NewWalletEventStream(ctx context.Context, authClient jwtclient.IAuthClient, cfg *types.RequestConfig) *WalletEventStream {
walletEventStream := &WalletEventStream{
walletConnMgr: newWalletConnMgr(),
BaseEventStream: types.NewBaseEventStream(ctx, cfg),
cfg: cfg,
authClient: authClient,
disableVerifyWalletAddrs: diableVerifyWalletAddrs,
walletConnMgr: newWalletConnMgr(),
BaseEventStream: types.NewBaseEventStream(ctx, cfg),
cfg: cfg,
authClient: authClient,
}
var err error
walletEventStream.randBytes, err = ioutil.ReadAll(io.LimitReader(rand.Reader, 32))
Expand Down Expand Up @@ -328,11 +325,6 @@ func (w *WalletEventStream) getValidatedAddress(ctx context.Context, channel *ty
}

func (w *WalletEventStream) verifyAddress(ctx context.Context, addr address.Address, channel *types.ChannelInfo, signBytes []byte, walletAccount string) error {
if w.disableVerifyWalletAddrs {
log.Infof("skip verify account:%s, address: %s, wallet address verification is disabled.",
walletAccount, addr)
return nil
}
signData := GetSignData(w.randBytes, signBytes)
payload, err := json.Marshal(&sharedGatewayTypes.WalletSignRequest{
Signer: addr,
Expand Down
4 changes: 1 addition & 3 deletions walletevent/wallet_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,10 @@ func TestAddNewAddress(t *testing.T) {
ctx = jwtclient.CtxWithName(ctx, walletAccount)
// stm: @VENUSGATEWAY_WALLET_EVENT_ADD_NEW_ADDRESS_004
client.wallet.SetFail(ctx, true)
walletEvent.disableVerifyWalletAddrs = false
// verify address failed
err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1})
require.Contains(t, err.Error(), "verify address")
client.wallet.SetFail(ctx, false)
walletEvent.disableVerifyWalletAddrs = true

// stm: @VENUSGATEWAY_WALLET_EVENT_ADD_NEW_ADDRESS_001
err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1})
Expand Down Expand Up @@ -298,7 +296,7 @@ func setupWalletEvent(t *testing.T, walletAccount string, accounts ...string) *W
authClient := mocks.NewMockAuthClient()
authClient.AddMockUser(ctx, users...)

return NewWalletEventStream(ctx, authClient, types.DefaultConfig(), true)
return NewWalletEventStream(ctx, authClient, types.DefaultConfig())
}

func setupClient(t *testing.T, ctx context.Context, walletAccount string, supportAccounts []string, event *WalletEventStream) *mockClient {
Expand Down

0 comments on commit dffe5de

Please sign in to comment.