Skip to content

Commit

Permalink
fix(runes): handling latest block not found
Browse files Browse the repository at this point in the history
Co-authored-by: Gaze <[email protected]>
  • Loading branch information
gazenw and gazenw committed Apr 22, 2024
1 parent 05b044e commit 9a3c608
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion modules/runes/api/httphandler/get_current_block.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
package httphandler

import (
"github.com/Cleverse/go-utilities/utils"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/cockroachdb/errors"
"github.com/gaze-network/indexer-network/common"
"github.com/gaze-network/indexer-network/common/errs"
"github.com/gaze-network/indexer-network/core/types"
"github.com/gofiber/fiber/v2"
)

var startingBlockHeader = map[common.Network]types.BlockHeader{
common.NetworkMainnet: {
Height: 839999,
Hash: *utils.Must(chainhash.NewHashFromStr("0000000000000000000172014ba58d66455762add0512355ad651207918494ab")),
PrevBlock: *utils.Must(chainhash.NewHashFromStr("00000000000000000001dcce6ce7c8a45872cafd1fb04732b447a14a91832591")),
},
common.NetworkTestnet: {
Height: 2583200,
Hash: *utils.Must(chainhash.NewHashFromStr("000000000006c5f0dfcd9e0e81f27f97a87aef82087ffe69cd3c390325bb6541")),
PrevBlock: *utils.Must(chainhash.NewHashFromStr("00000000000668f3bafac992f53424774515440cb47e1cb9e73af3f496139e28")),
},
}

type getCurrentBlockResult struct {
Hash string `json:"hash"`
Height int64 `json:"height"`
Expand All @@ -15,7 +33,10 @@ type getCurrentBlockResponse = HttpResponse[getCurrentBlockResult]
func (h *HttpHandler) GetCurrentBlock(ctx *fiber.Ctx) (err error) {
blockHeader, err := h.usecase.GetLatestBlock(ctx.UserContext())
if err != nil {
return errors.Wrap(err, "error during GetLatestBlock")
if !errors.Is(err, errs.NotFound) {
return errors.Wrap(err, "error during GetLatestBlock")
}
blockHeader = startingBlockHeader[h.network]
}

resp := getCurrentBlockResponse{
Expand Down

0 comments on commit 9a3c608

Please sign in to comment.