diff --git a/cmd/bee/cmd/cmd.go b/cmd/bee/cmd/cmd.go index 525e1eeaee9..67920adb7b0 100644 --- a/cmd/bee/cmd/cmd.go +++ b/cmd/bee/cmd/cmd.go @@ -305,7 +305,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) { cmd.Flags().Uint64(optionNameStateStoreCacheCapacity, 100_000, "lru memory caching capacity in number of statestore entries") cmd.Flags().String(optionNameTargetNeighborhood, "", "neighborhood to target in binary format (ex: 111111001) for mining the initial overlay") cmd.Flags().String(optionNameNeighborhoodSuggester, "https://api.swarmscan.io/v1/network/neighborhoods/suggestion", "suggester for target neighborhood") - cmd.Flags().String(optionNameWhitelistedWithdrawalAddress, "", "Withdrawal target address") + cmd.Flags().StringSlice(optionNameWhitelistedWithdrawalAddress, []string{}, "withdrawal target addresses") } func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) { diff --git a/pkg/api/router.go b/pkg/api/router.go index f6f75e348ea..bfc6d9a9f11 100644 --- a/pkg/api/router.go +++ b/pkg/api/router.go @@ -491,7 +491,7 @@ func (s *Service) mountBusinessDebug(restricted bool) { handle("/wallet", jsonhttp.MethodHandler{ "GET": http.HandlerFunc(s.walletHandler), }) - handle("/wallet/withdraw/{coin}/{addr}", jsonhttp.MethodHandler{ + handle("/wallet/withdraw/{coin}", jsonhttp.MethodHandler{ "POST": web.ChainHandlers( s.gasConfigMiddleware("wallet withdraw"), web.FinalHandlerFunc(s.walletWithdrawHandler), diff --git a/pkg/api/wallet.go b/pkg/api/wallet.go index c5e31a68734..51ff775a74b 100644 --- a/pkg/api/wallet.go +++ b/pkg/api/wallet.go @@ -62,7 +62,8 @@ func (s *Service) walletWithdrawHandler(w http.ResponseWriter, r *http.Request) logger := s.logger.WithName("post_wallet_withdraw").Build() queries := struct { - Amount *big.Int `map:"amount" validate:"required"` + Amount *big.Int `map:"amount" validate:"required"` + Address *common.Address `map:"address" validate:"required"` }{} if response := s.mapStructure(r.URL.Query(), &queries); response != nil { @@ -71,8 +72,7 @@ func (s *Service) walletWithdrawHandler(w http.ResponseWriter, r *http.Request) } path := struct { - Coin *string `map:"coin" validate:"required"` - Address *common.Address `map:"address" validate:"required"` + Coin *string `map:"coin" validate:"required"` }{} if response := s.mapStructure(mux.Vars(r), &path); response != nil { @@ -84,9 +84,9 @@ func (s *Service) walletWithdrawHandler(w http.ResponseWriter, r *http.Request) var bzz bool // check if coin is xdai or bzz - if !slices.Contains(s.whitelistedWithdrawalAddress, *path.Address) { + if !slices.Contains(s.whitelistedWithdrawalAddress, *queries.Address) { logger.Error(nil, "provided address not whitelisted") - jsonhttp.InternalServerError(w, "provided address not whitelisted") + jsonhttp.BadRequest(w, "provided address not whitelisted") return } @@ -104,7 +104,7 @@ func (s *Service) walletWithdrawHandler(w http.ResponseWriter, r *http.Request) return } - txHash, err := s.erc20Service.Withdraw(ctx, *path.Address, queries.Amount) + txHash, err := s.erc20Service.Withdraw(ctx, *queries.Address, queries.Amount) if err != nil { logger.Error(err, "unable to transfer") jsonhttp.InternalServerError(w, "unable to transfer amount") @@ -128,7 +128,7 @@ func (s *Service) walletWithdrawHandler(w http.ResponseWriter, r *http.Request) return } - txHash, err := withdraw(ctx, s.chainBackend, *path.Address, queries.Amount) + txHash, err := withdraw(ctx, s.chainBackend, *queries.Address, queries.Amount) if err != nil { logger.Error(err, "withdraw") jsonhttp.InternalServerError(w, "withdraw")