remove old api docs

This commit is contained in:
kiwiidb
2022-06-17 15:38:44 +02:00
parent 71c09f258a
commit b256a3fefe
17 changed files with 709 additions and 1849 deletions

View File

@@ -30,18 +30,6 @@ type AddInvoiceResponseBody struct {
PayReq string `json:"pay_req"` PayReq string `json:"pay_req"`
} }
// AddInvoice godoc
// @Summary Generate a new invoice
// @Description Returns a new bolt11 invoice
// @Accept json
// @Produce json
// @Tags Invoice
// @Param invoice body AddInvoiceRequestBody True "Add Invoice"
// @Success 200 {object} AddInvoiceResponseBody
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /addinvoice [post]
// @Security OAuth2Password
func (controller *AddInvoiceController) AddInvoice(c echo.Context) error { func (controller *AddInvoiceController) AddInvoice(c echo.Context) error {
userID := c.Get("UserID").(int64) userID := c.Get("UserID").(int64)
return AddInvoice(c, controller.svc, userID) return AddInvoice(c, controller.svc, userID)

View File

@@ -22,17 +22,6 @@ type BalanceResponse struct {
} }
} }
// Balance godoc
// @Summary Retrieve balance
// @Description Current user's balance in satoshi
// @Accept json
// @Produce json
// @Tags Account
// @Success 200 {object} BalanceResponse
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /balance [get]
// @Security OAuth2Password
func (controller *BalanceController) Balance(c echo.Context) error { func (controller *BalanceController) Balance(c echo.Context) error {
userId := c.Get("UserID").(int64) userId := c.Get("UserID").(int64)
balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId) balance, err := controller.svc.CurrentUserBalance(c.Request().Context(), userId)

View File

@@ -21,18 +21,6 @@ func NewCheckPaymentController(svc *service.LndhubService) *CheckPaymentControll
return &CheckPaymentController{svc: svc} return &CheckPaymentController{svc: svc}
} }
// CheckPayment godoc
// @Summary Check if an invoice is paid
// @Description Checks if an invoice is paid, can be incoming our outgoing
// @Accept json
// @Produce json
// @Tags Invoice
// @Param payment_hash path string true "Payment hash"
// @Success 200 {object} CheckPaymentResponseBody
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /checkpayment/{payment_hash} [get]
// @Security OAuth2Password
func (controller *CheckPaymentController) CheckPayment(c echo.Context) error { func (controller *CheckPaymentController) CheckPayment(c echo.Context) error {
userID := c.Get("UserID").(int64) userID := c.Get("UserID").(int64)
rHash := c.Param("payment_hash") rHash := c.Param("payment_hash")

View File

@@ -28,17 +28,6 @@ type CreateUserRequestBody struct {
AccountType string `json:"accounttype"` AccountType string `json:"accounttype"`
} }
// CreateUser godoc
// @Summary Create an account
// @Description Create a new account with a login and password
// @Accept json
// @Produce json
// @Tags Account
// @Param account body CreateUserRequestBody false "Create User"
// @Success 200 {object} CreateUserResponseBody
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /create [post]
func (controller *CreateUserController) CreateUser(c echo.Context) error { func (controller *CreateUserController) CreateUser(c echo.Context) error {
var body CreateUserRequestBody var body CreateUserRequestBody

View File

@@ -73,17 +73,6 @@ func NewGetInfoController(svc *service.LndhubService) *GetInfoController {
return &GetInfoController{svc: svc} return &GetInfoController{svc: svc}
} }
// GetInfo godoc
// @Summary Get info about the Lightning node
// @Description Returns info about the backend node powering this LNDhub instance
// @Accept json
// @Produce json
// @Tags Info
// @Success 200 {object} GetInfoResponse
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /getinfo [get]
// @Security OAuth2Password
func (controller *GetInfoController) GetInfo(c echo.Context) error { func (controller *GetInfoController) GetInfo(c echo.Context) error {
info, err := controller.svc.GetInfo(c.Request().Context()) info, err := controller.svc.GetInfo(c.Request().Context())
@@ -96,6 +85,6 @@ func (controller *GetInfoController) GetInfo(c echo.Context) error {
// BlueWallet right now requires a `identity_pubkey` in the response // BlueWallet right now requires a `identity_pubkey` in the response
// https://github.com/BlueWallet/BlueWallet/blob/a28a2b96bce0bff6d1a24a951b59dc972369e490/class/wallets/lightning-custodian-wallet.js#L578 // https://github.com/BlueWallet/BlueWallet/blob/a28a2b96bce0bff6d1a24a951b59dc972369e490/class/wallets/lightning-custodian-wallet.js#L578
c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=300, stale-if-error=21600") // cache for 5 minutes or if error for 6 hours max c.Response().Header().Set(echo.HeaderCacheControl, "public, max-age=300, stale-if-error=21600") // cache for 5 minutes or if error for 6 hours max
return c.JSON(http.StatusOK, info) return c.JSON(http.StatusOK, info)
} }

View File

@@ -46,17 +46,6 @@ type IncomingInvoice struct {
CustomRecords map[uint64][]byte `json:"custom_records"` CustomRecords map[uint64][]byte `json:"custom_records"`
} }
// GetTXS godoc
// @Summary Retrieve outgoing payments
// @Description Returns a list of outgoing payments for a user
// @Accept json
// @Produce json
// @Tags Account
// @Success 200 {object} []OutgoingInvoice
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /gettxs [get]
// @Security OAuth2Password
func (controller *GetTXSController) GetTXS(c echo.Context) error { func (controller *GetTXSController) GetTXS(c echo.Context) error {
userId := c.Get("UserID").(int64) userId := c.Get("UserID").(int64)
@@ -84,17 +73,6 @@ func (controller *GetTXSController) GetTXS(c echo.Context) error {
return c.JSON(http.StatusOK, &response) return c.JSON(http.StatusOK, &response)
} }
// GetUserInvoices godoc
// @Summary Retrieve incoming invoices
// @Description Returns a list of incoming invoices for a user
// @Accept json
// @Produce json
// @Tags Account
// @Success 200 {object} []IncomingInvoice
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /getuserinvoices [get]
// @Security OAuth2Password
func (controller *GetTXSController) GetUserInvoices(c echo.Context) error { func (controller *GetTXSController) GetUserInvoices(c echo.Context) error {
userId := c.Get("UserID").(int64) userId := c.Get("UserID").(int64)

View File

@@ -17,18 +17,6 @@ func NewInvoiceController(svc *service.LndhubService) *InvoiceController {
return &InvoiceController{svc: svc} return &InvoiceController{svc: svc}
} }
// Invoice godoc
// @Summary Generate a new invoice
// @Description Returns a new bolt11 invoice for a user with given login, without an Authorization Header
// @Accept json
// @Produce json
// @Tags Invoice
// @Param user_login path string true "User Login"
// @Param invoice body AddInvoiceRequestBody True "Add Invoice"
// @Success 200 {object} AddInvoiceResponseBody
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /invoice/{user_login} [post]
func (controller *InvoiceController) Invoice(c echo.Context) error { func (controller *InvoiceController) Invoice(c echo.Context) error {
user, err := controller.svc.FindUserByLogin(c.Request().Context(), c.Param("user_login")) user, err := controller.svc.FindUserByLogin(c.Request().Context(), c.Param("user_login"))
if err != nil { if err != nil {

View File

@@ -27,20 +27,6 @@ func NewInvoiceStreamController(svc *service.LndhubService) *InvoiceStreamContro
return &InvoiceStreamController{svc: svc} return &InvoiceStreamController{svc: svc}
} }
// StreamInvoices godoc
// @Summary Websocket for incoming payments
// @Description Websocket: won't work with Swagger web UI. Returns a stream of settled incoming payments.
// @Description A keep-alive message is sent on startup and every 30s.
// @Accept json
// @Produce json
// @Tags Invoice
// @Param token query string true "Auth token, retrieved from /auth endpoint"
// @Param since_payment_hash query string false "Payment hash of earliest invoice. If specified, missing updates starting from this payment will be sent."
// @Success 200 {object} []InvoiceEventWrapper
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /invoices/stream [get]
// @Security OAuth2Password
func (controller *InvoiceStreamController) StreamInvoices(c echo.Context) error { func (controller *InvoiceStreamController) StreamInvoices(c echo.Context) error {
userId, err := tokens.ParseToken(controller.svc.Config.JWTSecret, (c.QueryParam("token")), false) userId, err := tokens.ParseToken(controller.svc.Config.JWTSecret, (c.QueryParam("token")), false)
if err != nil { if err != nil {

View File

@@ -41,18 +41,6 @@ type KeySendResponseBody struct {
PaymentRoute *service.Route `json:"payment_route,omitempty"` PaymentRoute *service.Route `json:"payment_route,omitempty"`
} }
//// KeySend godoc
// @Summary Make a keysend payment
// @Description Pay a node without an invoice using it's public key
// @Accept json
// @Produce json
// @Tags Payment
// @Param KeySendRequestBody body KeySendRequestBody True "Invoice to pay"
// @Success 200 {object} KeySendResponseBody
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /keysend [post]
// @Security OAuth2Password
func (controller *KeySendController) KeySend(c echo.Context) error { func (controller *KeySendController) KeySend(c echo.Context) error {
userID := c.Get("UserID").(int64) userID := c.Get("UserID").(int64)
reqBody := KeySendRequestBody{} reqBody := KeySendRequestBody{}

View File

@@ -39,18 +39,6 @@ type PayInvoiceResponseBody struct {
PaymentRoute *service.Route `json:"payment_route,omitempty"` PaymentRoute *service.Route `json:"payment_route,omitempty"`
} }
// PayInvoice godoc
// @Summary Pay an invoice
// @Description Pay a bolt11 invoice
// @Accept json
// @Produce json
// @Tags Payment
// @Param PayInvoiceRequest body PayInvoiceRequestBody True "Invoice to pay"
// @Success 200 {object} PayInvoiceResponseBody
// @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse
// @Router /payinvoice [post]
// @Security OAuth2Password
func (controller *PayInvoiceController) PayInvoice(c echo.Context) error { func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
userID := c.Get("UserID").(int64) userID := c.Get("UserID").(int64)
reqBody := PayInvoiceRequestBody{} reqBody := PayInvoiceRequestBody{}

View File

@@ -17,9 +17,9 @@ func NewBalanceController(svc *service.LndhubService) *BalanceController {
} }
type BalanceResponse struct { type BalanceResponse struct {
BTC struct { Balance int64 `json:"balance"`
AvailableBalance int64 Currency string `json:"currency"`
} Unit string `json:"unit"`
} }
// Balance godoc // Balance godoc
@@ -31,7 +31,7 @@ type BalanceResponse struct {
// @Success 200 {object} BalanceResponse // @Success 200 {object} BalanceResponse
// @Failure 400 {object} responses.ErrorResponse // @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse // @Failure 500 {object} responses.ErrorResponse
// @Router /balance [get] // @Router /v2/balance [get]
// @Security OAuth2Password // @Security OAuth2Password
func (controller *BalanceController) Balance(c echo.Context) error { func (controller *BalanceController) Balance(c echo.Context) error {
userId := c.Get("UserID").(int64) userId := c.Get("UserID").(int64)
@@ -40,8 +40,8 @@ func (controller *BalanceController) Balance(c echo.Context) error {
return err return err
} }
return c.JSON(http.StatusOK, &BalanceResponse{ return c.JSON(http.StatusOK, &BalanceResponse{
BTC: struct{ AvailableBalance int64 }{ Balance: balance,
AvailableBalance: balance, Currency: "BTC",
}, Unit: "sat",
}) })
} }

View File

@@ -2,9 +2,9 @@ package v2controllers
import ( import (
"net/http" "net/http"
"time"
"github.com/getAlby/lndhub.go/common" "github.com/getAlby/lndhub.go/common"
"github.com/getAlby/lndhub.go/lib"
"github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/responses"
"github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/service"
"github.com/getsentry/sentry-go" "github.com/getsentry/sentry-go"
@@ -20,44 +20,35 @@ func NewInvoiceController(svc *service.LndhubService) *InvoiceController {
return &InvoiceController{svc: svc} return &InvoiceController{svc: svc}
} }
type OutgoingInvoice struct { type Invoice struct {
RHash interface{} `json:"r_hash,omitempty"` PaymentHash string `json:"payment_hash"`
PaymentHash interface{} `json:"payment_hash"` PaymentRequest string `json:"payment_request"`
PaymentPreimage string `json:"payment_preimage"` Description string `json:"description"`
Value int64 `json:"value"` DescriptionHash string `json:"description_hash"`
Type string `json:"type"` PaymentPreimage string `json:"payment_preimage,omitempty"`
Destination string `json:"destination"`
Amount int64 `json:"amount"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
Timestamp int64 `json:"timestamp"` Status string `json:"status"`
Memo string `json:"memo"` Type string `json:"type"`
ErrorMessage string `json:"error_message,omitempty"`
SettledAt time.Time `json:"settled_at"`
ExpiresAt time.Time `json:"expires_at"`
IsPaid bool `json:"is_paid"`
Keysend bool `json:"keysend"` Keysend bool `json:"keysend"`
CustomRecords map[uint64][]byte `json:"custom_records"` CustomRecords map[uint64][]byte `json:"custom_records"`
} }
type IncomingInvoice struct { // GetOutgoingInvoices godoc
RHash interface{} `json:"r_hash,omitempty"`
PaymentHash interface{} `json:"payment_hash"`
PaymentRequest string `json:"payment_request"`
Description string `json:"description"`
PayReq string `json:"pay_req"`
Timestamp int64 `json:"timestamp"`
Type string `json:"type"`
ExpireTime int64 `json:"expire_time"`
Amount int64 `json:"amt"`
IsPaid bool `json:"ispaid"`
Keysend bool `json:"keysend"`
CustomRecords map[uint64][]byte `json:"custom_records"`
}
// GetTXS godoc
// @Summary Retrieve outgoing payments // @Summary Retrieve outgoing payments
// @Description Returns a list of outgoing payments for a user // @Description Returns a list of outgoing payments for a user
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Tags Account // @Tags Account
// @Success 200 {object} []OutgoingInvoice // @Success 200 {object} []Invoice
// @Failure 400 {object} responses.ErrorResponse // @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse // @Failure 500 {object} responses.ErrorResponse
// @Router /gettxs [get] // @Router /v2/invoices/outgoing [get]
// @Security OAuth2Password // @Security OAuth2Password
func (controller *InvoiceController) GetOutgoingInvoices(c echo.Context) error { func (controller *InvoiceController) GetOutgoingInvoices(c echo.Context) error {
userId := c.Get("UserID").(int64) userId := c.Get("UserID").(int64)
@@ -67,18 +58,23 @@ func (controller *InvoiceController) GetOutgoingInvoices(c echo.Context) error {
return err return err
} }
response := make([]OutgoingInvoice, len(invoices)) response := make([]Invoice, len(invoices))
for i, invoice := range invoices { for i, invoice := range invoices {
rhash, _ := lib.ToJavaScriptBuffer(invoice.RHash) response[i] = Invoice{
response[i] = OutgoingInvoice{ PaymentHash: invoice.RHash,
RHash: rhash, PaymentRequest: invoice.PaymentRequest,
PaymentHash: rhash, Description: invoice.Memo,
DescriptionHash: invoice.DescriptionHash,
PaymentPreimage: invoice.Preimage, PaymentPreimage: invoice.Preimage,
Value: invoice.Amount, Destination: invoice.DestinationPubkeyHex,
Type: common.InvoiceTypePaid, Amount: invoice.Amount,
Fee: invoice.Fee, Fee: invoice.Fee,
Timestamp: invoice.CreatedAt.Unix(), Status: invoice.State,
Memo: invoice.Memo, Type: common.InvoiceTypePaid,
ErrorMessage: invoice.ErrorMessage,
SettledAt: invoice.SettledAt.Time,
ExpiresAt: invoice.ExpiresAt.Time,
IsPaid: invoice.State == common.InvoiceStateSettled,
Keysend: invoice.Keysend, Keysend: invoice.Keysend,
CustomRecords: invoice.DestinationCustomRecords, CustomRecords: invoice.DestinationCustomRecords,
} }
@@ -86,16 +82,16 @@ func (controller *InvoiceController) GetOutgoingInvoices(c echo.Context) error {
return c.JSON(http.StatusOK, &response) return c.JSON(http.StatusOK, &response)
} }
// GetUserInvoices godoc // GetIncomingInvoices godoc
// @Summary Retrieve incoming invoices // @Summary Retrieve incoming invoices
// @Description Returns a list of incoming invoices for a user // @Description Returns a list of incoming invoices for a user
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Tags Account // @Tags Account
// @Success 200 {object} []IncomingInvoice // @Success 200 {object} []Invoice
// @Failure 400 {object} responses.ErrorResponse // @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse // @Failure 500 {object} responses.ErrorResponse
// @Router /getuserinvoices [get] // @Router /v2/invoices/incoming [get]
// @Security OAuth2Password // @Security OAuth2Password
func (controller *InvoiceController) GetIncomingInvoices(c echo.Context) error { func (controller *InvoiceController) GetIncomingInvoices(c echo.Context) error {
userId := c.Get("UserID").(int64) userId := c.Get("UserID").(int64)
@@ -105,37 +101,40 @@ func (controller *InvoiceController) GetIncomingInvoices(c echo.Context) error {
return err return err
} }
response := make([]IncomingInvoice, len(invoices)) response := make([]Invoice, len(invoices))
for i, invoice := range invoices { for i, invoice := range invoices {
rhash, _ := lib.ToJavaScriptBuffer(invoice.RHash) response[i] = Invoice{
response[i] = IncomingInvoice{ PaymentHash: invoice.RHash,
RHash: rhash, PaymentRequest: invoice.PaymentRequest,
PaymentHash: invoice.RHash, Description: invoice.Memo,
PaymentRequest: invoice.PaymentRequest, DescriptionHash: invoice.DescriptionHash,
Description: invoice.Memo, PaymentPreimage: invoice.Preimage,
PayReq: invoice.PaymentRequest, Destination: invoice.DestinationPubkeyHex,
Timestamp: invoice.CreatedAt.Unix(), Amount: invoice.Amount,
Type: common.InvoiceTypeUser, Fee: invoice.Fee,
ExpireTime: 3600 * 24, Status: invoice.State,
Amount: invoice.Amount, Type: common.InvoiceTypeUser,
IsPaid: invoice.State == common.InvoiceStateSettled, ErrorMessage: invoice.ErrorMessage,
Keysend: invoice.Keysend, SettledAt: invoice.SettledAt.Time,
CustomRecords: invoice.DestinationCustomRecords, ExpiresAt: invoice.ExpiresAt.Time,
IsPaid: invoice.State == common.InvoiceStateSettled,
Keysend: invoice.Keysend,
CustomRecords: invoice.DestinationCustomRecords,
} }
} }
return c.JSON(http.StatusOK, &response) return c.JSON(http.StatusOK, &response)
} }
type AddInvoiceRequestBody struct { type AddInvoiceRequestBody struct {
Amount interface{} `json:"amt"` // amount in Satoshi Amount int64 `json:"amount" validate:"required,gt=0"`
Memo string `json:"memo"` Description string `json:"description"`
DescriptionHash string `json:"description_hash" validate:"omitempty,hexadecimal,len=64"` DescriptionHash string `json:"description_hash" validate:"omitempty,hexadecimal,len=64"`
} }
type AddInvoiceResponseBody struct { type AddInvoiceResponseBody struct {
RHash string `json:"r_hash"` PaymentHash string `json:"payment_hash"`
PaymentRequest string `json:"payment_request"` PaymentRequest string `json:"payment_request"`
PayReq string `json:"pay_req"` ExpiresAt time.Time `json:"expires_at"`
} }
// AddInvoice godoc // AddInvoice godoc
@@ -148,7 +147,7 @@ type AddInvoiceResponseBody struct {
// @Success 200 {object} AddInvoiceResponseBody // @Success 200 {object} AddInvoiceResponseBody
// @Failure 400 {object} responses.ErrorResponse // @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse // @Failure 500 {object} responses.ErrorResponse
// @Router /addinvoice [post] // @Router /v2/invoices [post]
// @Security OAuth2Password // @Security OAuth2Password
func (controller *InvoiceController) AddInvoice(c echo.Context) error { func (controller *InvoiceController) AddInvoice(c echo.Context) error {
userID := c.Get("UserID").(int64) userID := c.Get("UserID").(int64)
@@ -168,18 +167,19 @@ func (controller *InvoiceController) AddInvoice(c echo.Context) error {
if err != nil || amount < 0 { if err != nil || amount < 0 {
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError) return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
} }
c.Logger().Infof("Adding invoice: user_id:%v memo:%s value:%v description_hash:%s", userID, body.Memo, amount, body.DescriptionHash) c.Logger().Infof("Adding invoice: user_id:%v memo:%s value:%v description_hash:%s", userID, body.Description, amount, body.DescriptionHash)
invoice, err := controller.svc.AddIncomingInvoice(c.Request().Context(), userID, amount, body.Memo, body.DescriptionHash) invoice, err := controller.svc.AddIncomingInvoice(c.Request().Context(), userID, amount, body.Description, body.DescriptionHash)
if err != nil { if err != nil {
c.Logger().Errorf("Error creating invoice: user_id:%v error: %v", userID, err) c.Logger().Errorf("Error creating invoice: user_id:%v error: %v", userID, err)
sentry.CaptureException(err) sentry.CaptureException(err)
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError) return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
} }
responseBody := AddInvoiceResponseBody{} responseBody := AddInvoiceResponseBody{
responseBody.RHash = invoice.RHash PaymentHash: invoice.RHash,
responseBody.PaymentRequest = invoice.PaymentRequest PaymentRequest: invoice.PaymentRequest,
responseBody.PayReq = invoice.PaymentRequest ExpiresAt: invoice.ExpiresAt.Time,
}
return c.JSON(http.StatusOK, &responseBody) return c.JSON(http.StatusOK, &responseBody)
} }

View File

@@ -1,11 +1,9 @@
package v2controllers package v2controllers
import ( import (
"fmt"
"net/http" "net/http"
"strconv" "strconv"
"github.com/getAlby/lndhub.go/lib"
"github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/responses"
"github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/service"
"github.com/getAlby/lndhub.go/lnd" "github.com/getAlby/lndhub.go/lnd"
@@ -31,14 +29,14 @@ type KeySendRequestBody struct {
} }
type KeySendResponseBody struct { type KeySendResponseBody struct {
RHash *lib.JavaScriptBuffer `json:"payment_hash,omitempty"` Amount int64 `json:"amount,omitempty"`
Amount int64 `json:"num_satoshis,omitempty"` Fee int64 `json:"fee,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
Destination string `json:"destination,omitempty"` DescriptionHash string `json:"description_hash,omitempty"`
DescriptionHashStr string `json:"description_hash,omitempty"` Destination string `json:"destination,omitempty"`
PaymentError string `json:"payment_error,omitempty"` PaymentError string `json:"payment_error,omitempty"`
PaymentPreimage *lib.JavaScriptBuffer `json:"payment_preimage,omitempty"` PaymentPreimage string `json:"payment_preimage,omitempty"`
PaymentRoute *service.Route `json:"payment_route,omitempty"` PaymentHash string `json:"payment_hash,omitempty"`
} }
//// KeySend godoc //// KeySend godoc
@@ -51,7 +49,7 @@ type KeySendResponseBody struct {
// @Success 200 {object} KeySendResponseBody // @Success 200 {object} KeySendResponseBody
// @Failure 400 {object} responses.ErrorResponse // @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse // @Failure 500 {object} responses.ErrorResponse
// @Router /keysend [post] // @Router /v2/payments/keysend [post]
// @Security OAuth2Password // @Security OAuth2Password
func (controller *KeySendController) KeySend(c echo.Context) error { func (controller *KeySendController) KeySend(c echo.Context) error {
userID := c.Get("UserID").(int64) userID := c.Get("UserID").(int64)
@@ -109,19 +107,20 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
return c.JSON(http.StatusBadRequest, echo.Map{ return c.JSON(http.StatusBadRequest, echo.Map{
"error": true, "error": true,
"code": 10, "code": 10,
"message": fmt.Sprintf("Payment failed. Does the receiver have enough inbound capacity? (%v)", err), "message": err.Error(),
}) })
} }
responseBody := &KeySendResponseBody{} responseBody := &KeySendResponseBody{
responseBody.RHash = &lib.JavaScriptBuffer{Data: sendPaymentResponse.PaymentHash} Amount: sendPaymentResponse.Invoice.Amount,
responseBody.Amount = invoice.Amount Fee: sendPaymentResponse.Invoice.Fee,
responseBody.Destination = invoice.DestinationPubkeyHex Description: sendPaymentResponse.Invoice.Memo,
responseBody.Description = invoice.Memo DescriptionHash: sendPaymentResponse.Invoice.DescriptionHash,
responseBody.DescriptionHashStr = invoice.DescriptionHash Destination: sendPaymentResponse.Invoice.DestinationPubkeyHex,
responseBody.PaymentError = sendPaymentResponse.PaymentError PaymentError: sendPaymentResponse.PaymentError,
responseBody.PaymentPreimage = &lib.JavaScriptBuffer{Data: sendPaymentResponse.PaymentPreimage} PaymentPreimage: sendPaymentResponse.PaymentPreimageStr,
responseBody.PaymentRoute = sendPaymentResponse.PaymentRoute PaymentHash: sendPaymentResponse.PaymentHashStr,
}
return c.JSON(http.StatusOK, responseBody) return c.JSON(http.StatusOK, responseBody)
} }

View File

@@ -1,11 +1,9 @@
package v2controllers package v2controllers
import ( import (
"fmt"
"net/http" "net/http"
"strings" "strings"
"github.com/getAlby/lndhub.go/lib"
"github.com/getAlby/lndhub.go/lib/responses" "github.com/getAlby/lndhub.go/lib/responses"
"github.com/getAlby/lndhub.go/lib/service" "github.com/getAlby/lndhub.go/lib/service"
"github.com/getAlby/lndhub.go/lnd" "github.com/getAlby/lndhub.go/lnd"
@@ -24,19 +22,19 @@ func NewPayInvoiceController(svc *service.LndhubService) *PayInvoiceController {
} }
type PayInvoiceRequestBody struct { type PayInvoiceRequestBody struct {
Invoice string `json:"invoice" validate:"required"` Invoice string `json:"invoice" validate:"required"`
Amount interface{} `json:"amount" validate:"omitempty"` Amount int64 `json:"amount" validate:"omitempty,gte=0"`
} }
type PayInvoiceResponseBody struct { type PayInvoiceResponseBody struct {
RHash *lib.JavaScriptBuffer `json:"payment_hash,omitempty"` PaymentRequest string `json:"payment_request,omitempty"`
PaymentRequest string `json:"payment_request,omitempty"` Amount int64 `json:"amount,omitempty"`
PayReq string `json:"pay_req,omitempty"` Fee int64 `json:"fee,omitempty"`
Amount int64 `json:"num_satoshis,omitempty"` Description string `json:"description,omitempty"`
Description string `json:"description,omitempty"` DescriptionHash string `json:"description_hash,omitempty"`
DescriptionHashStr string `json:"description_hash,omitempty"` Destination string `json:"destination,omitempty"`
PaymentError string `json:"payment_error,omitempty"` PaymentError string `json:"payment_error,omitempty"`
PaymentPreimage *lib.JavaScriptBuffer `json:"payment_preimage,omitempty"` PaymentPreimage string `json:"payment_preimage,omitempty"`
PaymentRoute *service.Route `json:"payment_route,omitempty"` PaymentHash string `json:"payment_hash,omitempty"`
} }
// PayInvoice godoc // PayInvoice godoc
@@ -49,7 +47,7 @@ type PayInvoiceResponseBody struct {
// @Success 200 {object} PayInvoiceResponseBody // @Success 200 {object} PayInvoiceResponseBody
// @Failure 400 {object} responses.ErrorResponse // @Failure 400 {object} responses.ErrorResponse
// @Failure 500 {object} responses.ErrorResponse // @Failure 500 {object} responses.ErrorResponse
// @Router /payinvoice [post] // @Router /v2/payments/bolt11 [post]
// @Security OAuth2Password // @Security OAuth2Password
func (controller *PayInvoiceController) PayInvoice(c echo.Context) error { func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
userID := c.Get("UserID").(int64) userID := c.Get("UserID").(int64)
@@ -115,22 +113,22 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
hub.CaptureException(err) hub.CaptureException(err)
}) })
} }
return c.JSON(http.StatusBadRequest, echo.Map{ return c.JSON(http.StatusInternalServerError, echo.Map{
"error": true, "error": true,
"code": 10, "code": 10,
"message": fmt.Sprintf("Payment failed. Does the receiver have enough inbound capacity? (%v)", err), "message": err.Error(),
}) })
} }
responseBody := &PayInvoiceResponseBody{} responseBody := &PayInvoiceResponseBody{
responseBody.RHash = &lib.JavaScriptBuffer{Data: sendPaymentResponse.PaymentHash} Amount: sendPaymentResponse.Invoice.Amount,
responseBody.PaymentRequest = paymentRequest Fee: sendPaymentResponse.Invoice.Fee,
responseBody.PayReq = paymentRequest Description: sendPaymentResponse.Invoice.Memo,
responseBody.Amount = invoice.Amount DescriptionHash: sendPaymentResponse.Invoice.DescriptionHash,
responseBody.Description = invoice.Memo Destination: sendPaymentResponse.Invoice.DestinationPubkeyHex,
responseBody.DescriptionHashStr = invoice.DescriptionHash PaymentError: sendPaymentResponse.PaymentError,
responseBody.PaymentError = sendPaymentResponse.PaymentError PaymentPreimage: sendPaymentResponse.PaymentPreimageStr,
responseBody.PaymentPreimage = &lib.JavaScriptBuffer{Data: sendPaymentResponse.PaymentPreimage} PaymentHash: sendPaymentResponse.PaymentHashStr,
responseBody.PaymentRoute = sendPaymentResponse.PaymentRoute }
return c.JSON(http.StatusOK, responseBody) return c.JSON(http.StatusOK, responseBody)
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +1,5 @@
basePath: / basePath: /
definitions: definitions:
controllers.AddInvoiceRequestBody:
properties:
amt:
description: amount in Satoshi
description_hash:
type: string
memo:
type: string
type: object
controllers.AddInvoiceResponseBody:
properties:
pay_req:
type: string
payment_request:
type: string
r_hash:
type: string
type: object
controllers.AuthRequestBody: controllers.AuthRequestBody:
properties: properties:
login: login:
@@ -34,128 +16,61 @@ definitions:
refresh_token: refresh_token:
type: string type: string
type: object type: object
controllers.BalanceResponse: responses.ErrorResponse:
properties: properties:
btc: code:
properties: type: integer
availableBalance: error:
type: integer
type: object
type: object
controllers.Chain:
properties:
chain:
description: The blockchain the node is on (eg bitcoin, litecoin)
type: string
network:
description: The network the node is on (eg regtest, testnet, mainnet)
type: string
type: object
controllers.CheckPaymentResponseBody:
properties:
paid:
type: boolean type: boolean
message:
type: string
type: object type: object
controllers.CreateUserRequestBody: v2controllers.AddInvoiceRequestBody:
properties: properties:
accounttype: amount:
type: integer
description:
type: string type: string
login: description_hash:
type: string type: string
partnerid: required:
- amount
type: object
v2controllers.AddInvoiceResponseBody:
properties:
expires_at:
type: string type: string
payment_hash:
type: string
payment_request:
type: string
type: object
v2controllers.BalanceResponse:
properties:
balance:
type: integer
currency:
type: string
unit:
type: string
type: object
v2controllers.CreateUserRequestBody:
properties:
password: password:
type: string type: string
type: object username:
controllers.CreateUserResponseBody:
properties:
login:
type: string type: string
type: object
v2controllers.CreateUserResponseBody:
properties:
password: password:
type: string type: string
type: object username:
controllers.Feature:
properties:
is_known:
type: boolean
is_required:
type: boolean
name:
type: string type: string
type: object type: object
controllers.GetInfoResponse: v2controllers.Invoice:
properties: properties:
alias: amount:
description: If applicable, the alias of the current node, e.g. "bob"
type: string
best_header_timestamp:
description: Timestamp of the block best known to the wallet
type: integer
block_hash:
description: The node's current view of the hash of the best block
type: string
block_height:
description: The node's current view of the height of the best block
type: integer
chains:
description: A list of active chains the node is connected to
items:
$ref: '#/definitions/controllers.Chain'
type: array
color:
description: The color of the current node in hex code format
type: string
commit_hash:
description: The SHA1 commit hash that the daemon is compiled with.
type: string
features:
additionalProperties:
$ref: '#/definitions/controllers.Feature'
description: |-
Features that our node has advertised in our init message, node
announcements and invoices.
type: object
identity_pubkey:
description: The identity pubkey of the current node.
type: string
num_active_channels:
description: Number of active channels
type: integer
num_inactive_channels:
description: Number of inactive channels
type: integer
num_peers:
description: Number of peers
type: integer
num_pending_channels:
description: Number of pending channels
type: integer
synced_to_chain:
description: Whether the wallet's view is synced to the main chain
type: boolean
synced_to_graph:
description: Whether we consider ourselves synced with the public channel
graph.
type: boolean
testnet:
description: |-
Whether the current node is connected to testnet. This field is
deprecated and the network field should be used instead
Deprecated: Do not use.
type: boolean
uris:
description: The URIs of the current node.
items:
type: string
type: array
version:
description: The version of the LND software that the node is running.
type: string
type: object
controllers.IncomingInvoice:
properties:
amt:
type: integer type: integer
custom_records: custom_records:
additionalProperties: additionalProperties:
@@ -165,31 +80,34 @@ definitions:
type: object type: object
description: description:
type: string type: string
expire_time: description_hash:
type: string
destination:
type: string
error_message:
type: string
expires_at:
type: string
fee:
type: integer type: integer
ispaid: is_paid:
type: boolean type: boolean
keysend: keysend:
type: boolean type: boolean
pay_req: payment_hash:
type: string
payment_preimage:
type: string type: string
payment_hash: {}
payment_request: payment_request:
type: string type: string
r_hash: {} settled_at:
timestamp: type: string
type: integer status:
type: string
type: type:
type: string type: string
type: object type: object
controllers.InvoiceEventWrapper: v2controllers.KeySendRequestBody:
properties:
invoice:
$ref: '#/definitions/controllers.IncomingInvoice'
type:
type: string
type: object
controllers.KeySendRequestBody:
properties: properties:
amount: amount:
type: integer type: integer
@@ -205,101 +123,55 @@ definitions:
- amount - amount
- destination - destination
type: object type: object
controllers.KeySendResponseBody: v2controllers.KeySendResponseBody:
properties: properties:
amount:
type: integer
description: description:
type: string type: string
description_hash: description_hash:
type: string type: string
destination: destination:
type: string type: string
num_satoshis: fee:
type: integer type: integer
payment_error: payment_error:
type: string type: string
payment_hash: payment_hash:
$ref: '#/definitions/lib.JavaScriptBuffer'
payment_preimage:
$ref: '#/definitions/lib.JavaScriptBuffer'
payment_route:
$ref: '#/definitions/service.Route'
type: object
controllers.OutgoingInvoice:
properties:
custom_records:
additionalProperties:
items:
type: integer
type: array
type: object
fee:
type: integer
keysend:
type: boolean
memo:
type: string type: string
payment_hash: {}
payment_preimage: payment_preimage:
type: string type: string
r_hash: {}
timestamp:
type: integer
type:
type: string
value:
type: integer
type: object type: object
controllers.PayInvoiceRequestBody: v2controllers.PayInvoiceRequestBody:
properties: properties:
amount: {} amount:
minimum: 0
type: integer
invoice: invoice:
type: string type: string
required: required:
- invoice - invoice
type: object type: object
controllers.PayInvoiceResponseBody: v2controllers.PayInvoiceResponseBody:
properties: properties:
amount:
type: integer
description: description:
type: string type: string
description_hash: description_hash:
type: string type: string
num_satoshis: destination:
type: integer
pay_req:
type: string type: string
fee:
type: integer
payment_error: payment_error:
type: string type: string
payment_hash: payment_hash:
$ref: '#/definitions/lib.JavaScriptBuffer' type: string
payment_preimage: payment_preimage:
$ref: '#/definitions/lib.JavaScriptBuffer' type: string
payment_request: payment_request:
type: string type: string
payment_route:
$ref: '#/definitions/service.Route'
type: object
lib.JavaScriptBuffer:
properties:
data:
items:
type: integer
type: array
type: object
responses.ErrorResponse:
properties:
code:
type: integer
error:
type: boolean
message:
type: string
type: object
service.Route:
properties:
total_amt:
type: integer
total_fees:
type: integer
type: object type: object
info: info:
contact: contact:
@@ -314,38 +186,6 @@ info:
title: LNDhub.go title: LNDhub.go
version: 0.6.1 version: 0.6.1
paths: paths:
/addinvoice:
post:
consumes:
- application/json
description: Returns a new bolt11 invoice
parameters:
- description: Add Invoice
in: body
name: invoice
required: true
schema:
$ref: '#/definitions/controllers.AddInvoiceRequestBody'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.AddInvoiceResponseBody'
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
security:
- OAuth2Password: []
summary: Generate a new invoice
tags:
- Invoice
/auth: /auth:
post: post:
consumes: consumes:
@@ -375,7 +215,7 @@ paths:
summary: Authenticate summary: Authenticate
tags: tags:
- Account - Account
/balance: /v2/balance:
get: get:
consumes: consumes:
- application/json - application/json
@@ -386,7 +226,7 @@ paths:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/controllers.BalanceResponse' $ref: '#/definitions/v2controllers.BalanceResponse'
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
@@ -400,78 +240,25 @@ paths:
summary: Retrieve balance summary: Retrieve balance
tags: tags:
- Account - Account
/checkpayment/{payment_hash}: /v2/invoices:
get:
consumes:
- application/json
description: Checks if an invoice is paid, can be incoming our outgoing
parameters:
- description: Payment hash
in: path
name: payment_hash
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.CheckPaymentResponseBody'
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
security:
- OAuth2Password: []
summary: Check if an invoice is paid
tags:
- Invoice
/create:
post: post:
consumes: consumes:
- application/json - application/json
description: Create a new account with a login and password description: Returns a new bolt11 invoice
parameters: parameters:
- description: Create User - description: Add Invoice
in: body in: body
name: account name: invoice
required: true
schema: schema:
$ref: '#/definitions/controllers.CreateUserRequestBody' $ref: '#/definitions/v2controllers.AddInvoiceRequestBody'
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/controllers.CreateUserResponseBody' $ref: '#/definitions/v2controllers.AddInvoiceResponseBody'
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
summary: Create an account
tags:
- Account
/getinfo:
get:
consumes:
- application/json
description: Returns info about the backend node powering this LNDhub instance
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.GetInfoResponse'
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
@@ -482,37 +269,10 @@ paths:
$ref: '#/definitions/responses.ErrorResponse' $ref: '#/definitions/responses.ErrorResponse'
security: security:
- OAuth2Password: [] - OAuth2Password: []
summary: Get info about the Lightning node summary: Generate a new invoice
tags: tags:
- Info - Invoice
/gettxs: /v2/invoices/incoming:
get:
consumes:
- application/json
description: Returns a list of outgoing payments for a user
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/controllers.OutgoingInvoice'
type: array
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
security:
- OAuth2Password: []
summary: Retrieve outgoing payments
tags:
- Account
/getuserinvoices:
get: get:
consumes: consumes:
- application/json - application/json
@@ -524,7 +284,7 @@ paths:
description: OK description: OK
schema: schema:
items: items:
$ref: '#/definitions/controllers.IncomingInvoice' $ref: '#/definitions/v2controllers.Invoice'
type: array type: array
"400": "400":
description: Bad Request description: Bad Request
@@ -539,60 +299,11 @@ paths:
summary: Retrieve incoming invoices summary: Retrieve incoming invoices
tags: tags:
- Account - Account
/invoice/{user_login}: /v2/invoices/outgoing:
post:
consumes:
- application/json
description: Returns a new bolt11 invoice for a user with given login, without
an Authorization Header
parameters:
- description: User Login
in: path
name: user_login
required: true
type: string
- description: Add Invoice
in: body
name: invoice
required: true
schema:
$ref: '#/definitions/controllers.AddInvoiceRequestBody'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.AddInvoiceResponseBody'
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
summary: Generate a new invoice
tags:
- Invoice
/invoices/stream:
get: get:
consumes: consumes:
- application/json - application/json
description: |- description: Returns a list of outgoing payments for a user
Websocket: won't work with Swagger web UI. Returns a stream of settled incoming payments.
A keep-alive message is sent on startup and every 30s.
parameters:
- description: Auth token, retrieved from /auth endpoint
in: query
name: token
required: true
type: string
- description: Payment hash of earliest invoice. If specified, missing updates
starting from this payment will be sent.
in: query
name: since_payment_hash
type: string
produces: produces:
- application/json - application/json
responses: responses:
@@ -600,7 +311,7 @@ paths:
description: OK description: OK
schema: schema:
items: items:
$ref: '#/definitions/controllers.InvoiceEventWrapper' $ref: '#/definitions/v2controllers.Invoice'
type: array type: array
"400": "400":
description: Bad Request description: Bad Request
@@ -612,42 +323,10 @@ paths:
$ref: '#/definitions/responses.ErrorResponse' $ref: '#/definitions/responses.ErrorResponse'
security: security:
- OAuth2Password: [] - OAuth2Password: []
summary: Websocket for incoming payments summary: Retrieve outgoing payments
tags: tags:
- Invoice - Account
/keysend: /v2/payments/bolt11:
post:
consumes:
- application/json
description: Pay a node without an invoice using it's public key
parameters:
- description: Invoice to pay
in: body
name: KeySendRequestBody
required: true
schema:
$ref: '#/definitions/controllers.KeySendRequestBody'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.KeySendResponseBody'
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
security:
- OAuth2Password: []
summary: Make a keysend payment
tags:
- Payment
/payinvoice:
post: post:
consumes: consumes:
- application/json - application/json
@@ -658,14 +337,14 @@ paths:
name: PayInvoiceRequest name: PayInvoiceRequest
required: true required: true
schema: schema:
$ref: '#/definitions/controllers.PayInvoiceRequestBody' $ref: '#/definitions/v2controllers.PayInvoiceRequestBody'
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/controllers.PayInvoiceResponseBody' $ref: '#/definitions/v2controllers.PayInvoiceResponseBody'
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
@@ -679,6 +358,67 @@ paths:
summary: Pay an invoice summary: Pay an invoice
tags: tags:
- Payment - Payment
/v2/payments/keysend:
post:
consumes:
- application/json
description: Pay a node without an invoice using it's public key
parameters:
- description: Invoice to pay
in: body
name: KeySendRequestBody
required: true
schema:
$ref: '#/definitions/v2controllers.KeySendRequestBody'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/v2controllers.KeySendResponseBody'
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
security:
- OAuth2Password: []
summary: Make a keysend payment
tags:
- Payment
/v2/users:
post:
consumes:
- application/json
description: Create a new account with a username and password
parameters:
- description: Create User
in: body
name: account
schema:
$ref: '#/definitions/v2controllers.CreateUserRequestBody'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/v2controllers.CreateUserResponseBody'
"400":
description: Bad Request
schema:
$ref: '#/definitions/responses.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/responses.ErrorResponse'
summary: Create an account
tags:
- Account
schemes: schemes:
- https - https
- http - http