Skip to content

Commit

Permalink
fix: address as query
Browse files Browse the repository at this point in the history
  • Loading branch information
notanatol committed Mar 7, 2024
1 parent d72bad4 commit 053ba7e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
14 changes: 7 additions & 7 deletions pkg/api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}

Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 053ba7e

Please sign in to comment.