mirror of
https://github.com/bumi/lntip
synced 2025-06-16 09:45:35 +00:00
Add endpoint to get ne onchain BTC address
This commit is contained in:
parent
01460b2c5c
commit
456ae2eb50
12
ln/lnd.go
12
ln/lnd.go
@ -50,6 +50,18 @@ func (c LNDclient) AddInvoice(value int64, memo string) (Invoice, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c LNDclient) NewAddress() (string, error) {
|
||||||
|
stdOutLogger.Printf("Getting a new BTC address")
|
||||||
|
request := lnrpc.NewAddressRequest{
|
||||||
|
Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH,
|
||||||
|
}
|
||||||
|
res, err := c.lndClient.NewAddress(c.ctx, &request)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return res.Address, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetInvoice takes an invoice ID and returns the invoice details including settlement details
|
// GetInvoice takes an invoice ID and returns the invoice details including settlement details
|
||||||
// An error is returned if no corresponding invoice was found.
|
// An error is returned if no corresponding invoice was found.
|
||||||
func (c LNDclient) GetInvoice(paymentHashStr string) (Invoice, error) {
|
func (c LNDclient) GetInvoice(paymentHashStr string) (Invoice, error) {
|
||||||
|
9
lnme.go
9
lnme.go
@ -102,6 +102,15 @@ func main() {
|
|||||||
return c.JSON(http.StatusOK, invoice)
|
return c.JSON(http.StatusOK, invoice)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
e.POST("/v1/newaddress", func(c echo.Context) error {
|
||||||
|
address, err := lnClient.NewAddress()
|
||||||
|
if err != nil {
|
||||||
|
stdOutLogger.Printf("Error getting a new BTC address: %s", err)
|
||||||
|
return c.JSON(http.StatusInternalServerError, "Error getting address")
|
||||||
|
}
|
||||||
|
return c.JSON(http.StatusOK, address)
|
||||||
|
})
|
||||||
|
|
||||||
e.GET("/v1/invoice/:invoiceId", func(c echo.Context) error {
|
e.GET("/v1/invoice/:invoiceId", func(c echo.Context) error {
|
||||||
invoiceId := c.Param("invoiceId")
|
invoiceId := c.Param("invoiceId")
|
||||||
invoice, err := lnClient.GetInvoice(invoiceId)
|
invoice, err := lnClient.GetInvoice(invoiceId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user