Documentation ¶
Index ¶
- Constants
- Variables
- type BrandingConfig
- type Config
- type FooterLinkMap
- type Limits
- type LndhubService
- func (svc *LndhubService) AccountFor(ctx context.Context, accountType string, userId int64) (models.Account, error)
- func (svc *LndhubService) AddIncomingInvoice(ctx context.Context, userID int64, amount int64, ...) (*models.Invoice, *responses.ErrorResponse)
- func (svc *LndhubService) AddOutgoingInvoice(ctx context.Context, userID int64, paymentRequest string, ...) (*models.Invoice, *responses.ErrorResponse)
- func (svc *LndhubService) AddRoutingFeeEntry(ctx context.Context, entry *models.TransactionEntry, invoice *models.Invoice, ...) (err error)
- func (svc *LndhubService) CalcFeeLimit(destination string, amount int64) int64
- func (svc *LndhubService) CalcServiceFee(amount int64) int64
- func (svc *LndhubService) CheckIncomingPaymentAllowed(c echo.Context, amount, userId int64) (result *responses.ErrorResponse, err error)
- func (svc *LndhubService) CheckOutgoingPaymentAllowed(c echo.Context, lnpayReq *lnd.LNPayReq, userId int64) (result *responses.ErrorResponse, err error)
- func (svc *LndhubService) CheckPendingOutgoingPayments(ctx context.Context, pendingPayments []models.Invoice) (err error)
- func (svc *LndhubService) ConnectInvoiceSubscription(ctx context.Context) (lnd.SubscribeInvoicesWrapper, error)
- func (svc *LndhubService) CreateUser(ctx context.Context, login string, password string) (user *models.User, err error)
- func (svc *LndhubService) CurrentUserBalance(ctx context.Context, userId int64) (int64, error)
- func (svc *LndhubService) DecodePaymentRequest(ctx context.Context, bolt11 string) (*lnrpc.PayReq, error)
- func (svc *LndhubService) EncodeInvoiceWithUserLogin(ctx context.Context, w io.Writer, invoice models.Invoice) error
- func (svc *LndhubService) FindInvoiceByPaymentHash(ctx context.Context, userId int64, rHash string) (*models.Invoice, error)
- func (svc *LndhubService) FindUser(ctx context.Context, userId int64) (*models.User, error)
- func (svc *LndhubService) FindUserByLogin(ctx context.Context, login string) (*models.User, error)
- func (svc *LndhubService) GenerateToken(ctx context.Context, login, password, inRefreshToken string) (accessToken, refreshToken string, err error)
- func (svc *LndhubService) GetAllPendingPayments(ctx context.Context) ([]models.Invoice, error)
- func (svc *LndhubService) GetInfo(ctx context.Context) (*lnrpc.GetInfoResponse, error)
- func (svc *LndhubService) GetLimits(c echo.Context) (limits *Limits)
- func (svc *LndhubService) GetPendingPaymentsUntil(ctx context.Context, ts time.Time) ([]models.Invoice, error)
- func (svc *LndhubService) GetTransactionEntryByInvoiceId(ctx context.Context, id int64) (models.TransactionEntry, error)
- func (svc *LndhubService) GetVolumeOverPeriod(ctx context.Context, userId int64, invoiceType string, period time.Duration) (result int64, err error)
- func (svc *LndhubService) HandleFailedPayment(ctx context.Context, invoice *models.Invoice, ...) error
- func (svc *LndhubService) HandleInternalKeysendPayment(ctx context.Context, invoice *models.Invoice) (result *models.Invoice, err error)
- func (svc *LndhubService) HandleKeysendPayment(ctx context.Context, rawInvoice *lnrpc.Invoice) error
- func (svc *LndhubService) HandleSuccessfulPayment(ctx context.Context, invoice *models.Invoice, ...) error
- func (svc *LndhubService) InsertTransactionEntry(ctx context.Context, invoice *models.Invoice, ...) (entry models.TransactionEntry, err error)
- func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error
- func (svc *LndhubService) InvoicesFor(ctx context.Context, userId int64, invoiceType string) ([]models.Invoice, error)
- func (svc *LndhubService) ParseInt(value interface{}) (int64, error)
- func (svc *LndhubService) PayInvoice(ctx context.Context, invoice *models.Invoice) (*SendPaymentResponse, error)
- func (svc *LndhubService) ProcessInvoiceUpdate(ctx context.Context, rawInvoice *lnrpc.Invoice) error
- func (svc *LndhubService) RevertFeeReserve(ctx context.Context, entry *models.TransactionEntry, invoice *models.Invoice, ...) (err error)
- func (svc *LndhubService) RevertServiceFee(ctx context.Context, entry *models.TransactionEntry, invoice *models.Invoice, ...) (err error)
- func (svc *LndhubService) SendInternalPayment(ctx context.Context, invoice *models.Invoice) (sendPaymentResponse SendPaymentResponse, err error)
- func (svc *LndhubService) SendPaymentSync(ctx context.Context, invoice *models.Invoice) (SendPaymentResponse, error)
- func (svc *LndhubService) StartInvoiceRoutine(ctx context.Context) (err error)
- func (svc *LndhubService) StartPendingPaymentRoutine(ctx context.Context) (err error)
- func (svc *LndhubService) StartWebhookSubscription(ctx context.Context, url string)
- func (svc *LndhubService) SubscribeIncomingOutgoingInvoices() (incoming, outgoing chan models.Invoice, err error)
- func (svc *LndhubService) TrackOutgoingPaymentstatus(ctx context.Context, invoice *models.Invoice)
- func (svc *LndhubService) TransactionEntriesFor(ctx context.Context, userId int64) ([]models.TransactionEntry, error)
- func (svc *LndhubService) UpdateUser(ctx context.Context, userId int64, login *string, password *string, ...) (user *models.User, err error)
- func (svc *LndhubService) ValidateUserMiddleware() echo.MiddlewareFunc
- type Pubsub
- type Route
- type SendPaymentResponse
- type WebhookInvoicePayload
Constants ¶
View Source
const ( KEYSEND_CUSTOM_RECORD = 5482373484 TLV_WHATSAT_MESSAGE = 34349334 TLV_RECORD_NAME = 128100 TLV_WALLET_ID = 696969 //cfr. https://github.com/satoshisstream/satoshis.stream/blob/main/TLV_registry.md#field-696969---lnpay )
View Source
const DefaultChannelBufSize = 50
This should give enough space to allow for some spike in traffic without flooding memory to much.
Variables ¶
View Source
var AlreadyProcessedKeysendError = errors.New("already processed keysend payment")
Functions ¶
This section is empty.
Types ¶
type BrandingConfig ¶
type BrandingConfig struct { Title string `envconfig:"BRANDING_TITLE" default:"LndHub.go - Alby Lightning"` Desc string `envconfig:"BRANDING_DESC" default:"Alby server for the Lightning Network"` Url string `envconfig:"BRANDING_URL" default:"https://ln.getalby.com"` Logo string `envconfig:"BRANDING_LOGO" default:"/static/img/alby.svg"` Favicon string `envconfig:"BRANDING_FAVICON" default:"/static/img/favicon.png"` }
type Config ¶
type Config struct { DatabaseUri string `envconfig:"DATABASE_URI" required:"true"` DatabaseMaxConns int `envconfig:"DATABASE_MAX_CONNS" default:"10"` DatabaseMaxIdleConns int `envconfig:"DATABASE_MAX_IDLE_CONNS" default:"5"` DatabaseConnMaxLifetime int `envconfig:"DATABASE_CONN_MAX_LIFETIME" default:"1800"` // 30 minutes DatabaseTimeout int `envconfig:"DATABASE_TIMEOUT" default:"60"` // 60 seconds SentryDSN string `envconfig:"SENTRY_DSN"` DatadogAgentUrl string `envconfig:"DATADOG_AGENT_URL"` SentryTracesSampleRate float64 `envconfig:"SENTRY_TRACES_SAMPLE_RATE"` LogFilePath string `envconfig:"LOG_FILE_PATH"` JWTSecret []byte `envconfig:"JWT_SECRET" required:"true"` AdminToken string `envconfig:"ADMIN_TOKEN"` JWTRefreshTokenExpiry int `envconfig:"JWT_REFRESH_EXPIRY" default:"604800"` // in seconds, default 7 days JWTAccessTokenExpiry int `envconfig:"JWT_ACCESS_EXPIRY" default:"172800"` // in seconds, default 2 days CustomName string `envconfig:"CUSTOM_NAME"` Host string `envconfig:"HOST" default:"localhost:3000"` Port int `envconfig:"PORT" default:"3000"` EnableGRPC bool `envconfig:"ENABLE_GRPC" default:"false"` GRPCPort int `envconfig:"GRPC_PORT" default:"10009"` DefaultRateLimit int `envconfig:"DEFAULT_RATE_LIMIT" default:"10"` StrictRateLimit int `envconfig:"STRICT_RATE_LIMIT" default:"10"` BurstRateLimit int `envconfig:"BURST_RATE_LIMIT" default:"1"` EnablePrometheus bool `envconfig:"ENABLE_PROMETHEUS" default:"false"` PrometheusPort int `envconfig:"PROMETHEUS_PORT" default:"9092"` WebhookUrl string `envconfig:"WEBHOOK_URL"` FeeReserve bool `envconfig:"FEE_RESERVE" default:"false"` ServiceFee int `envconfig:"SERVICE_FEE" default:"0"` NoServiceFeeUpToAmount int `envconfig:"NO_SERVICE_FEE_UP_TO_AMOUNT" default:"0"` AllowAccountCreation bool `envconfig:"ALLOW_ACCOUNT_CREATION" default:"true"` MinPasswordEntropy int `envconfig:"MIN_PASSWORD_ENTROPY" default:"0"` MaxReceiveAmount int64 `envconfig:"MAX_RECEIVE_AMOUNT" default:"0"` MaxSendAmount int64 `envconfig:"MAX_SEND_AMOUNT" default:"0"` MaxAccountBalance int64 `envconfig:"MAX_ACCOUNT_BALANCE" default:"0"` MaxFeeAmount int64 `envconfig:"MAX_FEE_AMOUNT" default:"5000"` MaxSendVolume int64 `envconfig:"MAX_SEND_VOLUME" default:"0"` //0 means the volume check is disabled by default MaxReceiveVolume int64 `envconfig:"MAX_RECEIVE_VOLUME" default:"0"` //0 means the volume check is disabled by default MaxVolumePeriod int64 `envconfig:"MAX_VOLUME_PERIOD" default:"2592000"` //in seconds, default 1 month RabbitMQUri string `envconfig:"RABBITMQ_URI"` RabbitMQLndhubInvoiceExchange string `envconfig:"RABBITMQ_INVOICE_EXCHANGE" default:"lndhub_invoice"` RabbitMQLndInvoiceExchange string `envconfig:"RABBITMQ_LND_INVOICE_EXCHANGE" default:"lnd_invoice"` RabbitMQLndPaymentExchange string `envconfig:"RABBITMQ_LND_PAYMENT_EXCHANGE" default:"lnd_payment"` RabbitMQInvoiceConsumerQueueName string `envconfig:"RABBITMQ_INVOICE_CONSUMER_QUEUE_NAME" default:"lnd_invoice_consumer"` RabbitMQPaymentConsumerQueueName string `envconfig:"RABBITMQ_PAYMENT_CONSUMER_QUEUE_NAME" default:"lnd_payment_consumer"` Branding BrandingConfig }
type FooterLinkMap ¶
func (*FooterLinkMap) Decode ¶
func (flm *FooterLinkMap) Decode(value string) error
type LndhubService ¶
type LndhubService struct { Config *Config DB *bun.DB LndClient lnd.LightningClientWrapper RabbitMQClient rabbitmq.Client Logger *lecho.Logger InvoicePubSub *Pubsub }
func (*LndhubService) AccountFor ¶
func (*LndhubService) AddIncomingInvoice ¶
func (svc *LndhubService) AddIncomingInvoice(ctx context.Context, userID int64, amount int64, memo, descriptionHashStr string) (*models.Invoice, *responses.ErrorResponse)
func (*LndhubService) AddOutgoingInvoice ¶
func (*LndhubService) AddRoutingFeeEntry ¶
func (svc *LndhubService) AddRoutingFeeEntry(ctx context.Context, entry *models.TransactionEntry, invoice *models.Invoice, tx bun.Tx) (err error)
func (*LndhubService) CalcFeeLimit ¶
func (svc *LndhubService) CalcFeeLimit(destination string, amount int64) int64
func (*LndhubService) CalcServiceFee ¶
func (svc *LndhubService) CalcServiceFee(amount int64) int64
func (*LndhubService) CheckIncomingPaymentAllowed ¶
func (svc *LndhubService) CheckIncomingPaymentAllowed(c echo.Context, amount, userId int64) (result *responses.ErrorResponse, err error)
func (*LndhubService) CheckOutgoingPaymentAllowed ¶
func (svc *LndhubService) CheckOutgoingPaymentAllowed(c echo.Context, lnpayReq *lnd.LNPayReq, userId int64) (result *responses.ErrorResponse, err error)
func (*LndhubService) CheckPendingOutgoingPayments ¶
func (*LndhubService) ConnectInvoiceSubscription ¶
func (svc *LndhubService) ConnectInvoiceSubscription(ctx context.Context) (lnd.SubscribeInvoicesWrapper, error)
func (*LndhubService) CreateUser ¶
func (*LndhubService) CurrentUserBalance ¶
func (*LndhubService) DecodePaymentRequest ¶
func (*LndhubService) EncodeInvoiceWithUserLogin ¶
func (*LndhubService) FindInvoiceByPaymentHash ¶
func (*LndhubService) FindUserByLogin ¶
func (*LndhubService) GenerateToken ¶
func (*LndhubService) GetAllPendingPayments ¶
func (*LndhubService) GetInfo ¶
func (svc *LndhubService) GetInfo(ctx context.Context) (*lnrpc.GetInfoResponse, error)
func (*LndhubService) GetLimits ¶
func (svc *LndhubService) GetLimits(c echo.Context) (limits *Limits)
func (*LndhubService) GetPendingPaymentsUntil ¶
func (*LndhubService) GetTransactionEntryByInvoiceId ¶
func (svc *LndhubService) GetTransactionEntryByInvoiceId(ctx context.Context, id int64) (models.TransactionEntry, error)
func (*LndhubService) GetVolumeOverPeriod ¶
func (*LndhubService) HandleFailedPayment ¶
func (svc *LndhubService) HandleFailedPayment(ctx context.Context, invoice *models.Invoice, entryToRevert models.TransactionEntry, failedPaymentError error) error
func (*LndhubService) HandleInternalKeysendPayment ¶
func (*LndhubService) HandleKeysendPayment ¶
func (*LndhubService) HandleSuccessfulPayment ¶
func (svc *LndhubService) HandleSuccessfulPayment(ctx context.Context, invoice *models.Invoice, parentEntry models.TransactionEntry) error
func (*LndhubService) InsertTransactionEntry ¶
func (svc *LndhubService) InsertTransactionEntry(ctx context.Context, invoice *models.Invoice, creditAccount, debitAccount, feeAccount models.Account) (entry models.TransactionEntry, err error)
func (*LndhubService) InvoiceUpdateSubscription ¶
func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error
func (*LndhubService) InvoicesFor ¶
func (*LndhubService) ParseInt ¶
func (svc *LndhubService) ParseInt(value interface{}) (int64, error)
func (*LndhubService) PayInvoice ¶
func (svc *LndhubService) PayInvoice(ctx context.Context, invoice *models.Invoice) (*SendPaymentResponse, error)
func (*LndhubService) ProcessInvoiceUpdate ¶
func (*LndhubService) RevertFeeReserve ¶
func (svc *LndhubService) RevertFeeReserve(ctx context.Context, entry *models.TransactionEntry, invoice *models.Invoice, tx bun.Tx) (err error)
func (*LndhubService) RevertServiceFee ¶
func (svc *LndhubService) RevertServiceFee(ctx context.Context, entry *models.TransactionEntry, invoice *models.Invoice, tx bun.Tx) (err error)
func (*LndhubService) SendInternalPayment ¶
func (svc *LndhubService) SendInternalPayment(ctx context.Context, invoice *models.Invoice) (sendPaymentResponse SendPaymentResponse, err error)
func (*LndhubService) SendPaymentSync ¶
func (svc *LndhubService) SendPaymentSync(ctx context.Context, invoice *models.Invoice) (SendPaymentResponse, error)
func (*LndhubService) StartInvoiceRoutine ¶
func (svc *LndhubService) StartInvoiceRoutine(ctx context.Context) (err error)
func (*LndhubService) StartPendingPaymentRoutine ¶
func (svc *LndhubService) StartPendingPaymentRoutine(ctx context.Context) (err error)
func (*LndhubService) StartWebhookSubscription ¶
func (svc *LndhubService) StartWebhookSubscription(ctx context.Context, url string)
func (*LndhubService) SubscribeIncomingOutgoingInvoices ¶
func (svc *LndhubService) SubscribeIncomingOutgoingInvoices() (incoming, outgoing chan models.Invoice, err error)
func (*LndhubService) TrackOutgoingPaymentstatus ¶
func (svc *LndhubService) TrackOutgoingPaymentstatus(ctx context.Context, invoice *models.Invoice)
Should be called in a goroutine as the tracking can potentially take a long time
func (*LndhubService) TransactionEntriesFor ¶
func (svc *LndhubService) TransactionEntriesFor(ctx context.Context, userId int64) ([]models.TransactionEntry, error)
func (*LndhubService) UpdateUser ¶
func (*LndhubService) ValidateUserMiddleware ¶
func (svc *LndhubService) ValidateUserMiddleware() echo.MiddlewareFunc
type Pubsub ¶
type Pubsub struct {
// contains filtered or unexported fields
}
func (*Pubsub) Unsubscribe ¶
type SendPaymentResponse ¶
type SendPaymentResponse struct { PaymentPreimage []byte `json:"payment_preimage,omitempty"` PaymentPreimageStr string PaymentError string `json:"payment_error,omitempty"` PaymentHash []byte `json:"payment_hash,omitempty"` PaymentHashStr string PaymentRoute *Route TransactionEntry *models.TransactionEntry Invoice *models.Invoice }
type WebhookInvoicePayload ¶
type WebhookInvoicePayload struct { ID int64 `json:"id"` Type string `json:"type"` UserLogin string `json:"user_login"` Amount int64 `json:"amount"` Fee int64 `json:"fee"` Memo string `json:"memo"` DescriptionHash string `json:"description_hash,omitempty"` PaymentRequest string `json:"payment_request"` DestinationPubkeyHex string `json:"destination_pubkey_hex"` DestinationCustomRecords map[uint64][]byte `json:"custom_records,omitempty"` RHash string `json:"r_hash"` Preimage string `json:"preimage"` Keysend bool `json:"keysend"` State string `json:"state"` ErrorMessage string `json:"error_message,omitempty"` CreatedAt time.Time `json:"created_at"` ExpiresAt time.Time `json:"expires_at"` UpdatedAt time.Time `json:"updated_at"` SettledAt time.Time `json:"settled_at"` }
func ConvertPayload ¶
func ConvertPayload(invoice models.Invoice, user *models.User) (result WebhookInvoicePayload)
Click to show internal directories.
Click to hide internal directories.