lightning

package
v0.0.0-...-7c54f9f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProviderAlby is the Alby provider.
	ProviderAlby = "alby"
)

Variables

View Source
var (
	// AlbySupportedCurrencies is the list of currencies that we support for
	// creating invoices using Alby's API.
	AlbySupportedCurrencies = []string{"BTC", "USD"}
)

Functions

This section is empty.

Types

type AlbyConfig

type AlbyConfig struct {
	// APIKey is the API key to use for the Alby provider.
	APIKey string `long:"api_key" description:"API key for the Alby."`
}

type AlbyInvoiceData

type AlbyInvoiceData struct {
	Amount      uint64 `json:"amount"`
	Description string `json:"description"`
	Currency    string `json:"currency"`
}

AlbyInvoiceData represents the data required to create a new LN invoice using Alby's API.

type AlbyInvoiceProvider

type AlbyInvoiceProvider struct {
	Client HTTPClient
	APIKey string
}

AlbyInvoiceProvider is an implementation of the InvoiceProvider interface that uses Alby's API to create new LN invoices.

func NewAlbyProvider

func NewAlbyProvider(client HTTPClient, apiKey string) *AlbyInvoiceProvider

NewAlbyProvider creates a new InvoiceProvider with the given API key.

func (*AlbyInvoiceProvider) CreateInvoice

func (a *AlbyInvoiceProvider) CreateInvoice(ctx context.Context, amount uint64,
	currency string, description string) (*LNInvoice, error)

CreateInvoice creates a new LN invoice for the given price and description. It returns the payment request and the payment hash hex-encoded.

func (*AlbyInvoiceProvider) GetInvoicePreimage

func (a *AlbyInvoiceProvider) GetInvoicePreimage(ctx context.Context,
	paymentHash string) (string, error)

GetInvoicePreimage retrieves the preimage for a given payment hash. If the invoice is not paid or there's errors, it returns an empty string.

type AlbyInvoiceResponse

type AlbyInvoiceResponse struct {
	Amount         uint64 `json:"amount"`
	RHashStr       string `json:"r_hash_str"`
	PaymentRequest string `json:"payment_request"`
	ExpiresAt      string `json:"expires_at"`
}

AlbyInvoiceResponse represents the response from Alby's API when creating a new LN invoice.

type Amount

type Amount struct {
	// Amount is the amount in the currency's smallest unit.
	Amount uint64 `json:"amount"`

	// Currency is the currency of the amount.
	Currency string `json:"currency"`
}

Amount represents an amount in a specific currency.

type Config

type Config struct {
	// Provider is the provider to use for creating lightning invoices.
	Provider string `long:"provider" description:"LN provider to use."`

	// AlbyConfig is Alby's configuration.
	Alby AlbyConfig `group:"alby" namespace:"alby"`
}

Config is the main config for the lightning service.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns all default values for the Config struct.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface for making HTTP requests.

type LNInvoice

type LNInvoice struct {
	// UserAmount is the amount of the invoice in the user's currency.
	UserAmount Amount

	// PaymentAmount is the amount of the invoice in the payment currency.
	PaymentAmount Amount

	// PaymentHash is the hash of the payment preimage.
	PaymentHash string

	// PaymentRequest is the Lightning Network invoice payment request.
	PaymentRequest string
}

LNInvoice represents a Lightning Network invoice.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL