Skip to content

Commit

Permalink
webui/search: case insensitive search
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavSood committed Jun 15, 2024
1 parent bf0cee3 commit 2f341dc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions webui/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webui
import (
"fmt"
"net/http"
"strings"

"github.com/RaghavSood/btcsupply/address"
"github.com/RaghavSood/btcsupply/templates"
Expand All @@ -12,23 +13,24 @@ import (

func (w *WebUI) Search(c *gin.Context) {
q := c.Query("q")
lowerQ := strings.ToLower(q)

// Check if query is a block number or hash
block, err := w.db.GetBlock(q)
block, err := w.db.GetBlock(lowerQ)
if err == nil {
c.Redirect(302, fmt.Sprintf("/block/%d", block.BlockHeight))
return
}

// Check if query is a transaction ID
tx, err := w.db.GetTransaction(q)
tx, err := w.db.GetTransaction(lowerQ)
if err == nil {
c.Redirect(302, fmt.Sprintf("/transaction/%s", tx.TxID))
return
}

// Check if query is a script
burnScript, err := w.db.GetBurnScript(q)
burnScript, err := w.db.GetBurnScript(lowerQ)
if err == nil {
c.Redirect(302, fmt.Sprintf("/script/%s", burnScript.Script))
return
Expand Down

0 comments on commit 2f341dc

Please sign in to comment.