Skip to content

Commit cb8b426

Browse files
committed
added info endpoint, closes #24
1 parent 19ae1d6 commit cb8b426

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/common/vars.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,19 @@ func HeaderMustSyncHeight() uint32 {
105105
return 1
106106
}
107107
}
108+
109+
func ChainToString(c chain) string {
110+
switch Chain {
111+
case Mainnet:
112+
return "main"
113+
case Signet:
114+
return "signet"
115+
case Regtest:
116+
return "regtest"
117+
case Testnet3:
118+
return "testnet"
119+
default:
120+
panic("chain not defined")
121+
}
122+
123+
}

src/server/api.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,32 @@ import (
1919
// Will keep for now just in case, so I don't have to refactor twice
2020
type ApiHandler struct{}
2121

22-
type TxRequest struct {
23-
Data string `form:"data" json:"data" binding:"required"`
22+
type Info struct {
23+
Network string `json:"network"`
24+
Height uint32 `json:"height"`
25+
TweaksOnly bool `json:"tweaks_only"`
26+
TweaksFullBasic bool `json:"tweaks_full_basic"`
27+
TweaksFullWithDustFilter bool `json:"tweaks_full_with_dust_filter"`
28+
TweaksCutThroughWithDustFilter bool `json:"tweaks_cut_through_with_dust_filter"`
29+
}
30+
31+
func (h *ApiHandler) GetInfo(c *gin.Context) {
32+
lastHeader, err := dblevel.FetchHighestBlockHeaderInvByFlag(true)
33+
if err != nil {
34+
common.ErrorLogger.Println(err)
35+
c.JSON(http.StatusInternalServerError, gin.H{
36+
"error": "could could not retrieve data from database",
37+
})
38+
return
39+
}
40+
c.JSON(http.StatusOK, Info{
41+
Network: common.ChainToString(common.Chain),
42+
Height: lastHeader.Height,
43+
TweaksOnly: common.TweaksOnly,
44+
TweaksFullBasic: common.TweakIndexFullNoDust,
45+
TweaksFullWithDustFilter: common.TweakIndexFullIncludingDust,
46+
TweaksCutThroughWithDustFilter: common.TweaksCutThroughWithDust,
47+
})
2448
}
2549

2650
func (h *ApiHandler) GetBestBlockHeight(c *gin.Context) {
@@ -303,6 +327,10 @@ func (h *ApiHandler) GetSpentOutpointsIndex(c *gin.Context) {
303327
c.JSON(http.StatusOK, result)
304328
}
305329

330+
type TxRequest struct {
331+
Data string `form:"data" json:"data" binding:"required"`
332+
}
333+
306334
func (h *ApiHandler) ForwardRawTX(c *gin.Context) {
307335
var txRequest TxRequest
308336
if err := c.ShouldBind(&txRequest); err != nil {

src/server/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func RunServer(api *ApiHandler) {
1818
AllowCredentials: true,
1919
}))
2020

21+
router.GET("/info", api.GetInfo)
2122
router.GET("/block-height", api.GetBestBlockHeight)
2223
router.GET("/tweaks/:blockheight", FetchHeaderInvMiddleware, api.GetTweakDataByHeight)
2324
router.GET("/tweak-index/:blockheight", FetchHeaderInvMiddleware, api.GetTweakIndexDataByHeight)

0 commit comments

Comments
 (0)