From 585a8504e5a03d787a065c4cedb4f9b7696c99c8 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Wed, 19 Jan 2022 17:18:50 +0100 Subject: [PATCH 1/4] Add /getbtc endpoint We do not support on chain transactions but for backwards compatibility we still implement these endpoints. Here we return an empty array. This is consumed by: https://github.com/BlueWallet/BlueWallet/blob/a28a2b96bce0bff6d1a24a951b59dc972369e490/class/wallets/lightning-custodian-wallet.js#L327 --- controllers/getbtc.ctrl.go | 24 ++++++++++++++++++++++++ main.go | 2 ++ 2 files changed, 26 insertions(+) create mode 100644 controllers/getbtc.ctrl.go diff --git a/controllers/getbtc.ctrl.go b/controllers/getbtc.ctrl.go new file mode 100644 index 0000000..b7cb6bb --- /dev/null +++ b/controllers/getbtc.ctrl.go @@ -0,0 +1,24 @@ +package controllers + +import ( + "net/http" + + "github.com/getAlby/lndhub.go/lib/service" + "github.com/labstack/echo/v4" +) + +// GetBtcController : GetBtcController struct +type GetBtcController struct{} + +func NewGetBtcController(svc *service.LndhubService) *GetBtcController { + return &GetBtcController{} +} + +// GetBtc : Get Btc handler +// +// We do NOT support onchain transactions thus we only return an empty array for backwards compatibility +func (GetBtcController) GetBtc(c echo.Context) error { + addresses := []string{} + + return c.JSON(http.StatusOK, &addresses) +} diff --git a/main.go b/main.go index daf56fb..9140e6f 100644 --- a/main.go +++ b/main.go @@ -118,6 +118,8 @@ func main() { secured.GET("/checkpayment/:payment_hash", controllers.NewCheckPaymentController(svc).CheckPayment) secured.GET("/balance", controllers.NewBalanceController(svc).Balance) + secured.GET("/getbtc", controllers.NewGetBtcController(svc).GetBtc) + // Start server go func() { if err := e.Start(":3000"); err != nil && err != http.ErrServerClosed { From 163dcb725ce085f3c7258dc2c1b07277a5bc7b88 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Wed, 19 Jan 2022 17:36:58 +0100 Subject: [PATCH 2/4] Fix --- controllers/getbtc.ctrl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/getbtc.ctrl.go b/controllers/getbtc.ctrl.go index b7cb6bb..ffa901d 100644 --- a/controllers/getbtc.ctrl.go +++ b/controllers/getbtc.ctrl.go @@ -17,7 +17,7 @@ func NewGetBtcController(svc *service.LndhubService) *GetBtcController { // GetBtc : Get Btc handler // // We do NOT support onchain transactions thus we only return an empty array for backwards compatibility -func (GetBtcController) GetBtc(c echo.Context) error { +func (controller *GetBtcController) GetBtc(c echo.Context) error { addresses := []string{} return c.JSON(http.StatusOK, &addresses) From 65fe75d7cefa189f902adeb3268001dc2173888a Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Wed, 19 Jan 2022 17:56:33 +0100 Subject: [PATCH 3/4] Introduce a Blank controller for unsported endpoints --- controllers/blank.ctrl.go | 31 +++++++++++++++++++++++++++++++ controllers/getbtc.ctrl.go | 24 ------------------------ main.go | 4 +++- 3 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 controllers/blank.ctrl.go delete mode 100644 controllers/getbtc.ctrl.go diff --git a/controllers/blank.ctrl.go b/controllers/blank.ctrl.go new file mode 100644 index 0000000..57f3b83 --- /dev/null +++ b/controllers/blank.ctrl.go @@ -0,0 +1,31 @@ +package controllers + +import ( + "net/http" + + "github.com/getAlby/lndhub.go/lib/service" + "github.com/labstack/echo/v4" +) + +// BlankController : Controller for endpoints that we do not support and simply return +// a blank response for compatibility + +// GetBtcController : GetBtcController struct +type BlankController struct{} + +func NewBlankController(svc *service.LndhubService) *BlankController { + return &BlankController{} +} + +// We do NOT support onchain transactions thus we only return an empty array for backwards compatibility +func (controller *BlankController) GetBtc(c echo.Context) error { + addresses := []string{} + + return c.JSON(http.StatusOK, &addresses) +} + +func (controller *BlankController) GetPending(c echo.Context) error { + addresses := []string{} + + return c.JSON(http.StatusOK, &addresses) +} diff --git a/controllers/getbtc.ctrl.go b/controllers/getbtc.ctrl.go deleted file mode 100644 index ffa901d..0000000 --- a/controllers/getbtc.ctrl.go +++ /dev/null @@ -1,24 +0,0 @@ -package controllers - -import ( - "net/http" - - "github.com/getAlby/lndhub.go/lib/service" - "github.com/labstack/echo/v4" -) - -// GetBtcController : GetBtcController struct -type GetBtcController struct{} - -func NewGetBtcController(svc *service.LndhubService) *GetBtcController { - return &GetBtcController{} -} - -// GetBtc : Get Btc handler -// -// We do NOT support onchain transactions thus we only return an empty array for backwards compatibility -func (controller *GetBtcController) GetBtc(c echo.Context) error { - addresses := []string{} - - return c.JSON(http.StatusOK, &addresses) -} diff --git a/main.go b/main.go index 9140e6f..1d6f2ba 100644 --- a/main.go +++ b/main.go @@ -118,7 +118,9 @@ func main() { secured.GET("/checkpayment/:payment_hash", controllers.NewCheckPaymentController(svc).CheckPayment) secured.GET("/balance", controllers.NewBalanceController(svc).Balance) - secured.GET("/getbtc", controllers.NewGetBtcController(svc).GetBtc) + blankController := controllers.NewBlankController(svc) + secured.GET("/getbtc", blankController.GetBtc) + secured.GET("/getpending", blankController.GetPending) // Start server go func() { From c6600c36ed62bc67ad411f4287dac4956e6d2828 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Wed, 19 Jan 2022 18:12:28 +0100 Subject: [PATCH 4/4] Comments --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index 1d6f2ba..b51c144 100644 --- a/main.go +++ b/main.go @@ -108,9 +108,11 @@ func main() { LndClient: &lndClient, } + // Public endpoints for account creation and authentication e.POST("/auth", controllers.NewAuthController(svc).Auth) e.POST("/create", controllers.NewCreateUserController(svc).CreateUser) + // Secured endpoints which require a Authorization token (JWT) secured := e.Group("", tokens.Middleware(c.JWTSecret)) secured.POST("/addinvoice", controllers.NewAddInvoiceController(svc).AddInvoice) secured.POST("/payinvoice", controllers.NewPayInvoiceController(svc).PayInvoice) @@ -118,6 +120,7 @@ func main() { secured.GET("/checkpayment/:payment_hash", controllers.NewCheckPaymentController(svc).CheckPayment) secured.GET("/balance", controllers.NewBalanceController(svc).Balance) + // These endpoints are not supported and we return a blank response for backwards compatibility blankController := controllers.NewBlankController(svc) secured.GET("/getbtc", blankController.GetBtc) secured.GET("/getpending", blankController.GetPending)