mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-01-12 08:34:28 +08:00
fix: unescape query id (#58)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package httphandler
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/common/errs"
|
||||
"github.com/gaze-network/indexer-network/modules/runes/internal/entity"
|
||||
@@ -22,13 +24,20 @@ const (
|
||||
getBalancesDefaultLimit = 100
|
||||
)
|
||||
|
||||
func (r getBalancesRequest) Validate() error {
|
||||
func (r *getBalancesRequest) Validate() error {
|
||||
var errList []error
|
||||
if r.Wallet == "" {
|
||||
errList = append(errList, errors.New("'wallet' is required"))
|
||||
}
|
||||
if r.Id != "" && !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.New("'id' is not valid rune id or rune name"))
|
||||
if r.Id != "" {
|
||||
id, err := url.QueryUnescape(r.Id)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
r.Id = id
|
||||
if !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.Errorf("id '%s' is not valid rune id or rune name", r.Id))
|
||||
}
|
||||
}
|
||||
if r.Limit < 0 {
|
||||
errList = append(errList, errors.New("'limit' must be non-negative"))
|
||||
|
||||
@@ -40,7 +40,7 @@ func (r getBalancesBatchRequest) Validate() error {
|
||||
errList = append(errList, errors.Errorf("queries[%d]: 'wallet' is required", i))
|
||||
}
|
||||
if query.Id != "" && !isRuneIdOrRuneName(query.Id) {
|
||||
errList = append(errList, errors.Errorf("queries[%d]: 'id' is not valid rune id or rune name", i))
|
||||
errList = append(errList, errors.Errorf("queries[%d]: id '%s' is not valid rune id or rune name", i, query.Id))
|
||||
}
|
||||
if query.Limit < 0 {
|
||||
errList = append(errList, errors.Errorf("queries[%d]: 'limit' must be non-negative", i))
|
||||
|
||||
@@ -3,6 +3,7 @@ package httphandler
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
"slices"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
@@ -24,10 +25,15 @@ const (
|
||||
getHoldersMaxLimit = 1000
|
||||
)
|
||||
|
||||
func (r getHoldersRequest) Validate() error {
|
||||
func (r *getHoldersRequest) Validate() error {
|
||||
var errList []error
|
||||
id, err := url.QueryUnescape(r.Id)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
r.Id = id
|
||||
if !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.New("'id' is not valid rune id or rune name"))
|
||||
errList = append(errList, errors.Errorf("id '%s' is not valid rune id or rune name", r.Id))
|
||||
}
|
||||
if r.Limit < 0 {
|
||||
errList = append(errList, errors.New("'limit' must be non-negative"))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package httphandler
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"slices"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
@@ -17,10 +18,15 @@ type getTokenInfoRequest struct {
|
||||
BlockHeight uint64 `query:"blockHeight"`
|
||||
}
|
||||
|
||||
func (r getTokenInfoRequest) Validate() error {
|
||||
func (r *getTokenInfoRequest) Validate() error {
|
||||
var errList []error
|
||||
id, err := url.QueryUnescape(r.Id)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
r.Id = id
|
||||
if !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.New("'id' is not valid rune id or rune name"))
|
||||
errList = append(errList, errors.Errorf("id '%s' is not valid rune id or rune name", r.Id))
|
||||
}
|
||||
return errs.WithPublicMessage(errors.Join(errList...), "validation error")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"cmp"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"slices"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
@@ -27,10 +28,17 @@ const (
|
||||
getTransactionsMaxLimit = 3000
|
||||
)
|
||||
|
||||
func (r getTransactionsRequest) Validate() error {
|
||||
func (r *getTransactionsRequest) Validate() error {
|
||||
var errList []error
|
||||
if r.Id != "" && !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.New("'id' is not valid rune id or rune name"))
|
||||
if r.Id != "" {
|
||||
id, err := url.QueryUnescape(r.Id)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
r.Id = id
|
||||
if !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.Errorf("id '%s' is not valid rune id or rune name", r.Id))
|
||||
}
|
||||
}
|
||||
if r.FromBlock < -1 {
|
||||
errList = append(errList, errors.Errorf("invalid fromBlock range"))
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package httphandler
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/common/errs"
|
||||
@@ -22,13 +24,20 @@ const (
|
||||
getUTXOsMaxLimit = 3000
|
||||
)
|
||||
|
||||
func (r getUTXOsRequest) Validate() error {
|
||||
func (r *getUTXOsRequest) Validate() error {
|
||||
var errList []error
|
||||
if r.Wallet == "" {
|
||||
errList = append(errList, errors.New("'wallet' is required"))
|
||||
}
|
||||
if r.Id != "" && !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.New("'id' is not valid rune id or rune name"))
|
||||
if r.Id != "" {
|
||||
id, err := url.QueryUnescape(r.Id)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
r.Id = id
|
||||
if !isRuneIdOrRuneName(r.Id) {
|
||||
errList = append(errList, errors.Errorf("id '%s' is not valid rune id or rune name", r.Id))
|
||||
}
|
||||
}
|
||||
if r.Limit < 0 {
|
||||
errList = append(errList, errors.New("'limit' must be non-negative"))
|
||||
|
||||
Reference in New Issue
Block a user