Documentation
¶
Index ¶
- Constants
- Variables
- func DisableLog()
- func MapSQLError(err error) error
- func UseLogger(logger btclog.Logger)
- type BaseDB
- type BatchedL402TransactionsDB
- type BatchedLNCSessionsDB
- type BatchedMPPSessionsDB
- type BatchedOnionDB
- type BatchedQuerier
- type BatchedSecretsDB
- type BatchedServicesDB
- type BatchedTx
- type CountByDateRangeParams
- type CountL402TxFilteredParams
- type ErrSQLUniqueConstraintViolation
- type ErrSerializationError
- type L402Transaction
- type L402TransactionsDB
- type L402TransactionsDBTxOptions
- type L402TransactionsStore
- func (s *L402TransactionsStore) CountFiltered(ctx context.Context, filter TransactionFilter) (int64, error)
- func (s *L402TransactionsStore) CountTransactions(ctx context.Context) (int64, error)
- func (s *L402TransactionsStore) CountTransactionsByDateRange(ctx context.Context, from, to time.Time) (int64, error)
- func (s *L402TransactionsStore) DeleteByTokenID(ctx context.Context, tokenID []byte) error
- func (s *L402TransactionsStore) GetRevenueStats(ctx context.Context, from, to time.Time) ([]RevenueByServiceRow, error)
- func (s *L402TransactionsStore) GetSettledByTokenID(ctx context.Context, tokenID []byte) (L402Transaction, error)
- func (s *L402TransactionsStore) GetTotalRevenue(ctx context.Context) (int64, error)
- func (s *L402TransactionsStore) GetTotalRevenueByDateRange(ctx context.Context, from, to time.Time) (int64, error)
- func (s *L402TransactionsStore) ListByDateRange(ctx context.Context, from, to time.Time, limit, offset int32) ([]L402Transaction, error)
- func (s *L402TransactionsStore) ListByService(ctx context.Context, serviceName string, limit, offset int32) ([]L402Transaction, error)
- func (s *L402TransactionsStore) ListByState(ctx context.Context, state string, limit, offset int32) ([]L402Transaction, error)
- func (s *L402TransactionsStore) ListFiltered(ctx context.Context, filter TransactionFilter) ([]L402Transaction, error)
- func (s *L402TransactionsStore) ListTransactions(ctx context.Context, limit, offset int32) ([]L402Transaction, error)
- func (s *L402TransactionsStore) RecordMPPTransaction(ctx context.Context, paymentHash []byte, serviceName string, priceSats int64, ...) error
- func (s *L402TransactionsStore) RecordTransaction(ctx context.Context, tokenID []byte, paymentHash []byte, serviceName string, ...) error
- func (s *L402TransactionsStore) SettleTransaction(ctx context.Context, paymentHash []byte) error
- type LNCSessionsDB
- type LNCSessionsDBTxOptions
- type LNCSessionsStore
- func (l *LNCSessionsStore) AddSession(ctx context.Context, session *lnc.Session) error
- func (l *LNCSessionsStore) GetSession(ctx context.Context, passphraseEntropy []byte) (*lnc.Session, error)
- func (l *LNCSessionsStore) SetExpiry(ctx context.Context, passphraseEntropy []byte, expiry time.Time) error
- func (l *LNCSessionsStore) SetRemotePubKey(ctx context.Context, passphraseEntropy, remotePubKey []byte) error
- type ListL402TxByDateRangeParams
- type ListL402TxByServiceParams
- type ListL402TxByStateParams
- type ListL402TxFilteredParams
- type ListL402TxParams
- type MPPSessionsDB
- type MPPSessionsStore
- func (s *MPPSessionsStore) CloseSession(ctx context.Context, sessionID string) error
- func (s *MPPSessionsStore) CloseSessionAndGetBalance(ctx context.Context, sessionID string) (int64, error)
- func (s *MPPSessionsStore) CreateSession(ctx context.Context, session *auth.Session) error
- func (s *MPPSessionsStore) DeductSessionBalance(ctx context.Context, sessionID string, amount int64) error
- func (s *MPPSessionsStore) GetSession(ctx context.Context, sessionID string) (*auth.Session, error)
- func (s *MPPSessionsStore) UpdateSessionBalance(ctx context.Context, sessionID string, addSats int64) error
- type MPPSessionsTxOptions
- type NewL402Transaction
- type NewLNCSession
- type NewMPPSession
- type NewOnionPrivateKey
- type NewSecret
- type OnionDB
- type OnionDBTxOptions
- type OnionStore
- type PostgresConfig
- type PostgresStore
- type QueryCreator
- type RevenueByServiceAndDateRangeParams
- type RevenueByServiceAndDateRangeRow
- type RevenueByServiceRow
- type SecretsDB
- type SecretsDBTxOptions
- type SecretsStore
- func (s *SecretsStore) GetSecret(ctx context.Context, hash [sha256.Size]byte) ([l402.SecretSize]byte, error)
- func (s *SecretsStore) NewSecret(ctx context.Context, hash [sha256.Size]byte) ([l402.SecretSize]byte, error)
- func (s *SecretsStore) RevokeSecret(ctx context.Context, hash [sha256.Size]byte) error
- type ServiceParams
- type ServiceRow
- type ServicesDB
- type ServicesDBTxOptions
- type ServicesStore
- type SetExpiryParams
- type SetRemoteParams
- type SqliteConfig
- type SqliteStore
- type TestPgFixture
- type TotalRevenueByDateRangeParams
- type TransactionExecutor
- type TransactionFilter
- type Tx
- type TxExecutorOption
- type TxOptions
- type UpdateL402TxState
- type UpsertServiceParams
Constants ¶
const ( // DefaultStoreTimeout is the default timeout used for any interaction // with the storage/database. DefaultStoreTimeout = time.Second * 10 // DefaultNumTxRetries is the default number of times we'll retry a // transaction if it fails with an error that permits transaction // repetition. DefaultNumTxRetries = 10 // DefaultRetryDelay is the default delay between retries. This will be // used to generate a random delay between 0 and this value. DefaultRetryDelay = time.Millisecond * 50 )
const (
PostgresTag = "11"
)
const Subsystem = "APDB"
Subsystem defines the logging code for this subsystem.
Variables ¶
var ( // DefaultPostgresFixtureLifetime is the default maximum time a Postgres // test fixture is being kept alive. After that time the docker // container will be terminated forcefully, even if the tests aren't // fully executed yet. So this time needs to be chosen correctly to be // longer than the longest expected individual test run time. DefaultPostgresFixtureLifetime = 10 * time.Minute )
var ( // ErrRetriesExceeded is returned when a transaction is retried more // than the max allowed valued without a success. ErrRetriesExceeded = errors.New("db tx retries exceeded") )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func MapSQLError ¶
MapSQLError attempts to interpret a given error as a database agnostic SQL error.
Types ¶
type BaseDB ¶
BaseDB is the base database struct that each implementation can embed to gain some common functionality.
type BatchedL402TransactionsDB ¶ added in v0.5.0
type BatchedL402TransactionsDB interface {
L402TransactionsDB
BatchedTx[L402TransactionsDB]
}
BatchedL402TransactionsDB is a version of the L402TransactionsDB that's capable of batched database operations.
type BatchedLNCSessionsDB ¶
type BatchedLNCSessionsDB interface {
LNCSessionsDB
BatchedTx[LNCSessionsDB]
}
BatchedLNCSessionsDB is a version of the LNCSecretsDB that's capable of batched database operations.
type BatchedMPPSessionsDB ¶ added in v0.5.0
type BatchedMPPSessionsDB interface {
MPPSessionsDB
BatchedTx[MPPSessionsDB]
}
BatchedMPPSessionsDB is a version of the MPPSessionsDB that's capable of batched database operations.
type BatchedOnionDB ¶
BatchedOnionDB is a version of the OnionDB that's capable of batched database operations.
type BatchedQuerier ¶
type BatchedQuerier interface {
// Querier is the underlying query source, this is in place so we can
// pass a BatchedQuerier implementation directly into objects that
// create a batched version of the normal methods they need.
sqlc.Querier
// BeginTx creates a new database transaction given the set of
// transaction options.
BeginTx(ctx context.Context, options TxOptions) (*sql.Tx, error)
}
BatchedQuerier is a generic interface that allows callers to create a new database transaction based on an abstract type that implements the TxOptions interface.
type BatchedSecretsDB ¶
BatchedSecretsDB is a version of the SecretsDB that's capable of batched database operations.
type BatchedServicesDB ¶ added in v0.5.0
type BatchedServicesDB interface {
ServicesDB
BatchedTx[ServicesDB]
}
BatchedServicesDB is a version of ServicesDB that supports batched transactions.
type BatchedTx ¶
type BatchedTx[Q any] interface { // ExecTx will execute the passed txBody, operating upon generic // parameter Q (usually a storage interface) in a single transaction. // The set of TxOptions are passed in in order to allow the caller to // specify if a transaction should be read-only and optionally what // type of concurrency control should be used. ExecTx(ctx context.Context, txOptions TxOptions, txBody func(Q) error) error }
BatchedTx is a generic interface that represents the ability to execute several operations to a given storage interface in a single atomic transaction. Typically, Q here will be some subset of the main sqlc.Querier interface allowing it to only depend on the routines it needs to implement any additional business logic.
type CountByDateRangeParams ¶ added in v0.5.0
type CountByDateRangeParams = sqlc.CountL402TransactionsByDateRangeParams
CountByDateRangeParams contains parameters for counting settled transactions within a settlement-time date range.
type CountL402TxFilteredParams ¶ added in v0.5.0
type CountL402TxFilteredParams = sqlc.CountL402TransactionsFilteredParams
CountL402TxFilteredParams contains parameters for the combined filter count query.
type ErrSQLUniqueConstraintViolation ¶
type ErrSQLUniqueConstraintViolation struct {
DBError error
}
ErrSQLUniqueConstraintViolation is an error type which represents a database agnostic SQL unique constraint violation.
func (ErrSQLUniqueConstraintViolation) Error ¶
func (e ErrSQLUniqueConstraintViolation) Error() string
Error returns the error message.
type ErrSerializationError ¶
type ErrSerializationError struct {
DBError error
}
ErrSerializationError is an error type which represents a database agnostic error that a transaction couldn't be serialized with other concurrent db transactions.
func (ErrSerializationError) Error ¶
func (e ErrSerializationError) Error() string
Error returns the error message.
func (ErrSerializationError) Unwrap ¶
func (e ErrSerializationError) Unwrap() error
Unwrap returns the wrapped error.
type L402Transaction ¶ added in v0.5.0
type L402Transaction = sqlc.L402Transaction
L402Transaction is the database model for an L402 transaction.
type L402TransactionsDB ¶ added in v0.5.0
type L402TransactionsDB interface {
// InsertL402Transaction inserts a new L402 transaction into the
// database.
InsertL402Transaction(ctx context.Context,
arg NewL402Transaction) (int32, error)
// UpdateL402TransactionState updates the state and settled_at
// timestamp of a transaction identified by its payment hash.
// Returns the number of rows affected.
UpdateL402TransactionState(ctx context.Context,
arg UpdateL402TxState) (int64, error)
// GetL402TransactionsByPaymentHash returns transactions matching the
// given payment hash.
GetL402TransactionsByPaymentHash(ctx context.Context,
paymentHash []byte) ([]L402Transaction, error)
// GetL402TransactionByIdentifierHash returns the transaction matching
// the given identifier hash.
GetL402TransactionByIdentifierHash(ctx context.Context,
identifierHash []byte) (L402Transaction, error)
// GetL402SettledTransactionByTokenID returns the settled transaction
// matching the given token ID.
GetL402SettledTransactionByTokenID(ctx context.Context,
tokenID []byte) (L402Transaction, error)
// ListL402Transactions returns a paginated list of all transactions,
// ordered by created_at DESC.
ListL402Transactions(ctx context.Context,
arg ListL402TxParams) ([]L402Transaction, error)
// ListL402TransactionsByService returns a paginated list of
// transactions filtered by service name.
ListL402TransactionsByService(ctx context.Context,
arg ListL402TxByServiceParams) ([]L402Transaction, error)
// ListL402TransactionsByState returns a paginated list of
// transactions filtered by state.
ListL402TransactionsByState(ctx context.Context,
arg ListL402TxByStateParams) ([]L402Transaction, error)
// ListL402TransactionsByDateRange returns a paginated list of
// transactions within a date range.
ListL402TransactionsByDateRange(ctx context.Context,
arg ListL402TxByDateRangeParams) ([]L402Transaction, error)
// CountL402Transactions returns the total number of settled
// transactions.
CountL402Transactions(ctx context.Context) (int64, error)
// CountL402TransactionsByService returns the number of transactions
// for a given service.
CountL402TransactionsByService(ctx context.Context,
serviceName string) (int64, error)
// CountL402TransactionsByDateRange returns the total number of
// settled transactions within a settlement-time date range.
CountL402TransactionsByDateRange(ctx context.Context,
arg CountByDateRangeParams) (int64, error)
// GetL402RevenueByService returns the total settled revenue grouped
// by service name.
GetL402RevenueByService(ctx context.Context) (
[]RevenueByServiceRow, error)
// GetL402RevenueByServiceAndDateRange returns the total settled
// revenue grouped by service name within a date range.
GetL402RevenueByServiceAndDateRange(ctx context.Context,
arg RevenueByServiceAndDateRangeParams) (
[]RevenueByServiceAndDateRangeRow, error)
// GetL402TotalRevenue returns the total settled revenue across all
// services.
GetL402TotalRevenue(ctx context.Context) (int64, error)
// GetL402TotalRevenueByDateRange returns the total settled revenue
// across all services within a date range.
GetL402TotalRevenueByDateRange(ctx context.Context,
arg TotalRevenueByDateRangeParams) (int64, error)
// DeleteL402TransactionByTokenID deletes a transaction by its
// token ID.
DeleteL402TransactionByTokenID(ctx context.Context,
tokenID []byte) (int64, error)
// ListL402TransactionsFiltered returns a paginated list of
// transactions with optional combined filters.
ListL402TransactionsFiltered(ctx context.Context,
arg ListL402TxFilteredParams) ([]L402Transaction, error)
// CountL402TransactionsFiltered returns the count of transactions
// matching the combined filters.
CountL402TransactionsFiltered(ctx context.Context,
arg CountL402TxFilteredParams) (int64, error)
}
L402TransactionsDB is an interface that defines the set of operations that can be executed against the L402 transactions database.
type L402TransactionsDBTxOptions ¶ added in v0.5.0
type L402TransactionsDBTxOptions struct {
// contains filtered or unexported fields
}
L402TransactionsDBTxOptions defines the set of db txn options the L402TransactionsStore understands.
func NewL402TransactionsDBReadTx ¶ added in v0.5.0
func NewL402TransactionsDBReadTx() L402TransactionsDBTxOptions
NewL402TransactionsDBReadTx creates a new read transaction option set.
func (*L402TransactionsDBTxOptions) ReadOnly ¶ added in v0.5.0
func (a *L402TransactionsDBTxOptions) ReadOnly() bool
ReadOnly returns true if the transaction should be read only.
NOTE: This implements the TxOptions interface.
type L402TransactionsStore ¶ added in v0.5.0
type L402TransactionsStore struct {
// contains filtered or unexported fields
}
L402TransactionsStore represents a storage backend for L402 transactions.
func NewL402TransactionsStore ¶ added in v0.5.0
func NewL402TransactionsStore( db BatchedL402TransactionsDB) *L402TransactionsStore
NewL402TransactionsStore creates a new L402TransactionsStore instance given an open BatchedL402TransactionsDB storage backend.
func (*L402TransactionsStore) CountFiltered ¶ added in v0.5.0
func (s *L402TransactionsStore) CountFiltered(ctx context.Context, filter TransactionFilter) (int64, error)
CountFiltered returns the count of transactions matching the given combined filters.
func (*L402TransactionsStore) CountTransactions ¶ added in v0.5.0
func (s *L402TransactionsStore) CountTransactions( ctx context.Context) (int64, error)
CountTransactions returns the total number of settled transactions.
func (*L402TransactionsStore) CountTransactionsByDateRange ¶ added in v0.5.0
func (s *L402TransactionsStore) CountTransactionsByDateRange( ctx context.Context, from, to time.Time) (int64, error)
CountTransactionsByDateRange returns the total number of settled transactions within a settlement-time date range.
func (*L402TransactionsStore) DeleteByTokenID ¶ added in v0.5.0
func (s *L402TransactionsStore) DeleteByTokenID(ctx context.Context, tokenID []byte) error
DeleteByTokenID deletes a transaction by its token ID.
func (*L402TransactionsStore) GetRevenueStats ¶ added in v0.5.0
func (s *L402TransactionsStore) GetRevenueStats(ctx context.Context, from, to time.Time) ([]RevenueByServiceRow, error)
GetRevenueStats returns settled revenue grouped by service, optionally filtered by date range. If from is zero-valued, all settled revenue is returned.
func (*L402TransactionsStore) GetSettledByTokenID ¶ added in v0.5.0
func (s *L402TransactionsStore) GetSettledByTokenID(ctx context.Context, tokenID []byte) (L402Transaction, error)
GetSettledByTokenID returns the settled transaction for the given token ID.
func (*L402TransactionsStore) GetTotalRevenue ¶ added in v0.5.0
func (s *L402TransactionsStore) GetTotalRevenue( ctx context.Context) (int64, error)
GetTotalRevenue returns the total settled revenue across all services.
func (*L402TransactionsStore) GetTotalRevenueByDateRange ¶ added in v0.5.0
func (s *L402TransactionsStore) GetTotalRevenueByDateRange( ctx context.Context, from, to time.Time) (int64, error)
GetTotalRevenueByDateRange returns the total settled revenue across all services within a date range.
func (*L402TransactionsStore) ListByDateRange ¶ added in v0.5.0
func (s *L402TransactionsStore) ListByDateRange(ctx context.Context, from, to time.Time, limit, offset int32) ([]L402Transaction, error)
ListByDateRange returns a paginated list of transactions within a date range.
func (*L402TransactionsStore) ListByService ¶ added in v0.5.0
func (s *L402TransactionsStore) ListByService(ctx context.Context, serviceName string, limit, offset int32) ([]L402Transaction, error)
ListByService returns a paginated list of transactions for a given service.
func (*L402TransactionsStore) ListByState ¶ added in v0.5.0
func (s *L402TransactionsStore) ListByState(ctx context.Context, state string, limit, offset int32) ([]L402Transaction, error)
ListByState returns a paginated list of transactions with the given state.
func (*L402TransactionsStore) ListFiltered ¶ added in v0.5.0
func (s *L402TransactionsStore) ListFiltered(ctx context.Context, filter TransactionFilter) ([]L402Transaction, error)
ListFiltered returns a paginated list of transactions matching the given combined filters. Empty strings disable the corresponding filter.
func (*L402TransactionsStore) ListTransactions ¶ added in v0.5.0
func (s *L402TransactionsStore) ListTransactions(ctx context.Context, limit, offset int32) ([]L402Transaction, error)
ListTransactions returns a paginated list of all transactions.
func (*L402TransactionsStore) RecordMPPTransaction ¶ added in v0.5.0
func (s *L402TransactionsStore) RecordMPPTransaction(ctx context.Context, paymentHash []byte, serviceName string, priceSats int64, authType string) error
RecordMPPTransaction records a new pending MPP charge or session transaction. Unlike L402, MPP transactions have no token_id or identifier_hash.
func (*L402TransactionsStore) RecordTransaction ¶ added in v0.5.0
func (s *L402TransactionsStore) RecordTransaction(ctx context.Context, tokenID []byte, paymentHash []byte, serviceName string, priceSats int64, identifierHash []byte) error
RecordTransaction records a new pending L402 transaction.
func (*L402TransactionsStore) SettleTransaction ¶ added in v0.5.0
func (s *L402TransactionsStore) SettleTransaction(ctx context.Context, paymentHash []byte) error
SettleTransaction marks all transactions with the given payment hash as settled.
type LNCSessionsDB ¶
type LNCSessionsDB interface {
// InsertLNCSession inserts a new session into the database.
InsertSession(ctx context.Context, arg NewLNCSession) error
// GetLNCSession returns the session tagged with the given passphrase
// entropy.
GetSession(ctx context.Context,
passphraseEntropy []byte) (sqlc.LncSession, error)
// SetRemotePubKey sets the remote public key for the session.
SetRemotePubKey(ctx context.Context,
arg SetRemoteParams) error
// SetExpiry sets the expiry for the session.
SetExpiry(ctx context.Context, arg SetExpiryParams) error
}
LNCSessionsDB is an interface that defines the set of operations that can be executed agaist the lnc sessions database.
type LNCSessionsDBTxOptions ¶
type LNCSessionsDBTxOptions struct {
// contains filtered or unexported fields
}
LNCSessionsDBTxOptions defines the set of db txn options the LNCSessionsDB understands.
func NewLNCSessionsDBReadTx ¶
func NewLNCSessionsDBReadTx() LNCSessionsDBTxOptions
NewLNCSessionsDBReadTx creates a new read transaction option set.
func (*LNCSessionsDBTxOptions) ReadOnly ¶
func (a *LNCSessionsDBTxOptions) ReadOnly() bool
ReadOnly returns true if the transaction should be read only.
NOTE: This implements the TxOptions
type LNCSessionsStore ¶
type LNCSessionsStore struct {
// contains filtered or unexported fields
}
LNCSessionsStore represents a storage backend.
func NewLNCSessionsStore ¶
func NewLNCSessionsStore(db BatchedLNCSessionsDB) *LNCSessionsStore
NewSecretsStore creates a new SecretsStore instance given a open BatchedSecretsDB storage backend.
func (*LNCSessionsStore) AddSession ¶
AddSession adds a new session to the database.
func (*LNCSessionsStore) GetSession ¶
func (l *LNCSessionsStore) GetSession(ctx context.Context, passphraseEntropy []byte) (*lnc.Session, error)
GetSession returns the session tagged with the given label.
func (*LNCSessionsStore) SetExpiry ¶
func (l *LNCSessionsStore) SetExpiry(ctx context.Context, passphraseEntropy []byte, expiry time.Time) error
SetExpiry sets the expiry time for a session.
func (*LNCSessionsStore) SetRemotePubKey ¶
func (l *LNCSessionsStore) SetRemotePubKey(ctx context.Context, passphraseEntropy, remotePubKey []byte) error
SetRemotePubKey sets the remote public key for a session.
type ListL402TxByDateRangeParams ¶ added in v0.5.0
type ListL402TxByDateRangeParams = sqlc.ListL402TransactionsByDateRangeParams
ListL402TxByDateRangeParams contains parameters for listing transactions by date range.
type ListL402TxByServiceParams ¶ added in v0.5.0
type ListL402TxByServiceParams = sqlc.ListL402TransactionsByServiceParams
ListL402TxByServiceParams contains parameters for listing transactions by service.
type ListL402TxByStateParams ¶ added in v0.5.0
type ListL402TxByStateParams = sqlc.ListL402TransactionsByStateParams
ListL402TxByStateParams contains parameters for listing transactions by state.
type ListL402TxFilteredParams ¶ added in v0.5.0
type ListL402TxFilteredParams = sqlc.ListL402TransactionsFilteredParams
ListL402TxFilteredParams contains parameters for the combined filter query.
type ListL402TxParams ¶ added in v0.5.0
type ListL402TxParams = sqlc.ListL402TransactionsParams
ListL402TxParams contains pagination parameters for listing transactions.
type MPPSessionsDB ¶ added in v0.5.0
type MPPSessionsDB interface {
// InsertMPPSession inserts a new MPP session into the database.
InsertMPPSession(ctx context.Context,
arg NewMPPSession) (int32, error)
// GetMPPSessionByID returns the MPP session with the given session ID.
GetMPPSessionByID(ctx context.Context,
sessionID string) (sqlc.MppSession, error)
// UpdateMPPSessionDeposit atomically adds to the deposit balance.
UpdateMPPSessionDeposit(ctx context.Context,
arg sqlc.UpdateMPPSessionDepositParams) (sql.Result, error)
// UpdateMPPSessionSpent atomically adds to the spent counter.
// The query includes a balance check: deposit_sats - spent_sats >= amount.
UpdateMPPSessionSpent(ctx context.Context,
arg sqlc.UpdateMPPSessionSpentParams) (sql.Result, error)
// CloseMPPSession marks the session as closed.
CloseMPPSession(ctx context.Context,
arg sqlc.CloseMPPSessionParams) (sql.Result, error)
// CloseMPPSessionReturningBalance atomically closes the session and
// returns the remaining balance (deposit_sats - spent_sats).
CloseMPPSessionReturningBalance(ctx context.Context,
arg sqlc.CloseMPPSessionReturningBalanceParams) (int64, error)
}
MPPSessionsDB is an interface that defines the set of operations that can be executed against the MPP sessions database.
type MPPSessionsStore ¶ added in v0.5.0
type MPPSessionsStore struct {
// contains filtered or unexported fields
}
MPPSessionsStore represents a storage backend for MPP sessions.
func NewMPPSessionsStore ¶ added in v0.5.0
func NewMPPSessionsStore(db BatchedMPPSessionsDB) *MPPSessionsStore
NewMPPSessionsStore creates a new MPPSessionsStore instance given an open BatchedMPPSessionsDB storage backend.
func (*MPPSessionsStore) CloseSession ¶ added in v0.5.0
func (s *MPPSessionsStore) CloseSession(ctx context.Context, sessionID string) error
CloseSession marks the session as closed. No further operations are accepted on a closed session.
NOTE: This implements the auth.SessionStore interface.
func (*MPPSessionsStore) CloseSessionAndGetBalance ¶ added in v0.5.0
func (s *MPPSessionsStore) CloseSessionAndGetBalance(ctx context.Context, sessionID string) (int64, error)
CloseSessionAndGetBalance atomically closes the session and returns the remaining balance (deposit_sats - spent_sats). This prevents the TOCTOU race where a concurrent bearer request could deduct balance between a separate GetSession read and CloseSession write.
NOTE: This implements the auth.SessionStore interface.
func (*MPPSessionsStore) CreateSession ¶ added in v0.5.0
CreateSession creates a new session with the given initial state.
NOTE: This implements the auth.SessionStore interface.
func (*MPPSessionsStore) DeductSessionBalance ¶ added in v0.5.0
func (s *MPPSessionsStore) DeductSessionBalance(ctx context.Context, sessionID string, amount int64) error
DeductSessionBalance atomically adds the given amount to the session's spent counter. The caller is responsible for checking that the deduction does not exceed the deposit balance.
NOTE: This implements the auth.SessionStore interface.
func (*MPPSessionsStore) GetSession ¶ added in v0.5.0
GetSession returns the session with the given session ID.
NOTE: This implements the auth.SessionStore interface.
func (*MPPSessionsStore) UpdateSessionBalance ¶ added in v0.5.0
func (s *MPPSessionsStore) UpdateSessionBalance(ctx context.Context, sessionID string, addSats int64) error
UpdateSessionBalance atomically adds the given amount to the session's deposit balance.
NOTE: This implements the auth.SessionStore interface.
type MPPSessionsTxOptions ¶ added in v0.5.0
type MPPSessionsTxOptions struct {
// contains filtered or unexported fields
}
MPPSessionsTxOptions defines the set of db txn options the MPPSessionsStore understands.
func NewMPPSessionsReadTx ¶ added in v0.5.0
func NewMPPSessionsReadTx() MPPSessionsTxOptions
NewMPPSessionsReadTx creates a new read transaction option set.
func (*MPPSessionsTxOptions) ReadOnly ¶ added in v0.5.0
func (a *MPPSessionsTxOptions) ReadOnly() bool
ReadOnly returns true if the transaction should be read only.
NOTE: This implements the TxOptions interface.
type NewL402Transaction ¶ added in v0.5.0
type NewL402Transaction = sqlc.InsertL402TransactionParams
NewL402Transaction is a struct that contains the parameters required to insert a new L402 transaction into the database.
type NewLNCSession ¶
type NewLNCSession = sqlc.InsertSessionParams
type NewMPPSession ¶ added in v0.5.0
type NewMPPSession = sqlc.InsertMPPSessionParams
NewMPPSession is a struct that contains the parameters required to insert a new MPP session into the database.
type NewOnionPrivateKey ¶
type NewOnionPrivateKey = sqlc.UpsertOnionParams
type NewSecret ¶
type NewSecret = sqlc.InsertSecretParams
NewSecret is a struct that contains the parameters required to insert a new secret into the database.
type OnionDB ¶
type OnionDB interface {
// UpsertOnion inserts a new onion private key into the database. If
// the onion private key already exists in the db this is a NOOP
// operation.
UpsertOnion(ctx context.Context, arg NewOnionPrivateKey) error
// SelectOnionPrivateKey selects the onion private key from the
// database.
SelectOnionPrivateKey(ctx context.Context) ([]byte, error)
// DeleteOnionPrivateKey deletes the onion private key from the
// database.
DeleteOnionPrivateKey(ctx context.Context) error
}
OnionDB is an interface that defines the set of operations that can be executed against the onion database.
type OnionDBTxOptions ¶
type OnionDBTxOptions struct {
// contains filtered or unexported fields
}
OnionTxOptions defines the set of db txn options the OnionStore understands.
func NewOnionDBReadTx ¶
func NewOnionDBReadTx() OnionDBTxOptions
NewOnionDBReadTx creates a new read transaction option set.
func (*OnionDBTxOptions) ReadOnly ¶
func (a *OnionDBTxOptions) ReadOnly() bool
ReadOnly returns true if the transaction should be read only.
NOTE: This implements the TxOptions
type OnionStore ¶
type OnionStore struct {
// contains filtered or unexported fields
}
OnionStore represents a storage backend.
func NewOnionStore ¶
func NewOnionStore(db BatchedOnionDB) *OnionStore
NewOnionStore creates a new OnionStore instance given a open BatchedOnionDB storage backend.
func (*OnionStore) DeletePrivateKey ¶
func (o *OnionStore) DeletePrivateKey() error
DeletePrivateKey securely removes the private key from the store.
func (*OnionStore) PrivateKey ¶
func (o *OnionStore) PrivateKey() ([]byte, error)
PrivateKey retrieves a stored private key. If it is not found, then ErrNoPrivateKey should be returned.
func (*OnionStore) StorePrivateKey ¶
func (o *OnionStore) StorePrivateKey(privateKey []byte) error
StorePrivateKey stores the private key according to the implementation of the OnionStore interface.
type PostgresConfig ¶
type PostgresConfig struct {
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
Host string `long:"host" description:"Database server hostname."`
Port int `long:"port" description:"Database server port."`
User string `long:"user" description:"Database user."`
Password string `long:"password" description:"Database user's password."`
DBName string `long:"dbname" description:"Database name to use."`
MaxOpenConnections int32 `long:"maxconnections" description:"Max open connections to keep alive to the database server."`
RequireSSL bool `long:"requiressl" description:"Whether to require using SSL (mode: require) when connecting to the server."`
}
PostgresConfig holds the postgres database configuration.
func (*PostgresConfig) DSN ¶
func (s *PostgresConfig) DSN(hidePassword bool) string
DSN returns the dns to connect to the database.
type PostgresStore ¶
type PostgresStore struct {
*BaseDB
// contains filtered or unexported fields
}
PostgresStore is a database store implementation that uses a Postgres backend.
func NewPostgresStore ¶
func NewPostgresStore(cfg *PostgresConfig) (*PostgresStore, error)
NewPostgresStore creates a new store that is backed by a Postgres database backend.
func NewTestPostgresDB ¶
func NewTestPostgresDB(t *testing.T) *PostgresStore
NewTestPostgresDB is a helper function that creates a Postgres database for testing.
type QueryCreator ¶
QueryCreator is a generic function that's used to create a Querier, which is a type of interface that implements storage related methods from a database transaction. This will be used to instantiate an object callers can use to apply multiple modifications to an object interface in a single atomic transaction.
type RevenueByServiceAndDateRangeParams ¶ added in v0.5.0
type RevenueByServiceAndDateRangeParams = sqlc.GetL402RevenueByServiceAndDateRangeParams
RevenueByServiceAndDateRangeParams contains parameters for querying revenue by service within a date range.
type RevenueByServiceAndDateRangeRow ¶ added in v0.5.0
type RevenueByServiceAndDateRangeRow = sqlc.GetL402RevenueByServiceAndDateRangeRow
RevenueByServiceAndDateRangeRow contains a service name and its total revenue within a date range.
type RevenueByServiceRow ¶ added in v0.5.0
type RevenueByServiceRow = sqlc.GetL402RevenueByServiceRow
RevenueByServiceRow contains a service name and its total revenue.
type SecretsDB ¶
type SecretsDB interface {
// InsertSecret inserts a new secret into the database.
InsertSecret(ctx context.Context, arg NewSecret) (int32, error)
// GetSecretByHash returns the secret that corresponds to the given
// hash.
GetSecretByHash(ctx context.Context, hash []byte) ([]byte, error)
// DeleteSecretByHash removes the secret that corresponds to the given
// hash.
DeleteSecretByHash(ctx context.Context, hash []byte) (int64, error)
}
SecretsDB is an interface that defines the set of operations that can be executed against the secrets database.
type SecretsDBTxOptions ¶
type SecretsDBTxOptions struct {
// contains filtered or unexported fields
}
SecretsTxOptions defines the set of db txn options the SecretsStore understands.
func NewSecretsDBReadTx ¶
func NewSecretsDBReadTx() SecretsDBTxOptions
NewSecretsDBReadTx creates a new read transaction option set.
func (*SecretsDBTxOptions) ReadOnly ¶
func (a *SecretsDBTxOptions) ReadOnly() bool
ReadOnly returns true if the transaction should be read only.
NOTE: This implements the TxOptions
type SecretsStore ¶
type SecretsStore struct {
// contains filtered or unexported fields
}
SecretsStore represents a storage backend.
func NewSecretsStore ¶
func NewSecretsStore(db BatchedSecretsDB) *SecretsStore
NewSecretsStore creates a new SecretsStore instance given a open BatchedSecretsDB storage backend.
func (*SecretsStore) GetSecret ¶
func (s *SecretsStore) GetSecret(ctx context.Context, hash [sha256.Size]byte) ([l402.SecretSize]byte, error)
GetSecret returns the cryptographically random secret that corresponds to the given hash. If there is no secret, then ErrSecretNotFound is returned.
func (*SecretsStore) NewSecret ¶
func (s *SecretsStore) NewSecret(ctx context.Context, hash [sha256.Size]byte) ([l402.SecretSize]byte, error)
NewSecret creates a new cryptographically random secret which is keyed by the given hash.
func (*SecretsStore) RevokeSecret ¶
RevokeSecret removes the cryptographically random secret that corresponds to the given hash. This acts as a NOP if the secret does not exist.
type ServiceParams ¶ added in v0.5.0
type ServiceParams struct {
Name string
Address string
Protocol string
HostRegexp string
PathRegexp string
Auth string
AuthScheme string
Price int64
}
ServiceParams contains the fields for creating or updating a service.
type ServiceRow ¶ added in v0.5.0
ServiceRow is the database model for a service.
type ServicesDB ¶ added in v0.5.0
type ServicesDB interface {
// UpsertService inserts or updates a service by name.
UpsertService(ctx context.Context, arg UpsertServiceParams) error
// DeleteService deletes a service by name.
DeleteService(ctx context.Context, name string) (int64, error)
// ListServices returns all services ordered by name.
ListServices(ctx context.Context) ([]ServiceRow, error)
}
ServicesDB is an interface that defines the set of operations that can be executed against the services database table.
type ServicesDBTxOptions ¶ added in v0.5.0
type ServicesDBTxOptions struct {
// contains filtered or unexported fields
}
ServicesDBTxOptions defines the set of db txn options the ServicesStore understands.
func (*ServicesDBTxOptions) ReadOnly ¶ added in v0.5.0
func (a *ServicesDBTxOptions) ReadOnly() bool
ReadOnly returns true if the transaction should be read only.
NOTE: This implements the TxOptions interface.
type ServicesStore ¶ added in v0.5.0
type ServicesStore struct {
// contains filtered or unexported fields
}
ServicesStore represents a storage backend for service configurations.
func NewServicesStore ¶ added in v0.5.0
func NewServicesStore(db BatchedServicesDB) *ServicesStore
NewServicesStore creates a new ServicesStore instance.
func (*ServicesStore) DeleteService ¶ added in v0.5.0
func (s *ServicesStore) DeleteService(ctx context.Context, name string) error
DeleteService removes a service by name.
func (*ServicesStore) ListServices ¶ added in v0.5.0
func (s *ServicesStore) ListServices(ctx context.Context) ([]ServiceRow, error)
ListServices returns all persisted services.
func (*ServicesStore) UpsertService ¶ added in v0.5.0
func (s *ServicesStore) UpsertService(ctx context.Context, params ServiceParams) error
UpsertService inserts or updates a service configuration.
type SetExpiryParams ¶
type SetExpiryParams = sqlc.SetExpiryParams
type SetRemoteParams ¶
type SetRemoteParams = sqlc.SetRemotePubKeyParams
type SqliteConfig ¶
type SqliteConfig struct {
// SkipMigrations if true, then all the tables will be created on start
// up if they don't already exist.
SkipMigrations bool `long:"skipmigrations" description:"Skip applying migrations on startup."`
// DatabaseFileName is the full file path where the database file can be
// found.
DatabaseFileName string `long:"dbfile" description:"The full path to the database."`
}
SqliteConfig holds all the config arguments needed to interact with our sqlite DB.
type SqliteStore ¶
type SqliteStore struct {
*BaseDB
// contains filtered or unexported fields
}
SqliteStore is a database store implementation that uses a sqlite backend.
func NewSqliteStore ¶
func NewSqliteStore(cfg *SqliteConfig) (*SqliteStore, error)
NewSqliteStore attempts to open a new sqlite database based on the passed config.
func NewTestDB ¶
func NewTestDB(t *testing.T) *SqliteStore
NewTestDB is a helper function that creates an SQLite database for testing.
func NewTestSqliteDB ¶
func NewTestSqliteDB(t *testing.T) *SqliteStore
NewTestSqliteDB is a helper function that creates an SQLite database for testing.
type TestPgFixture ¶
type TestPgFixture struct {
// contains filtered or unexported fields
}
TestPgFixture is a test fixture that starts a Postgres 11 instance in a docker container.
func NewTestPgFixture ¶
func NewTestPgFixture(t *testing.T, expiry time.Duration) *TestPgFixture
NewTestPgFixture constructs a new TestPgFixture starting up a docker container running Postgres 11. The started container will expire in after the passed duration.
func (*TestPgFixture) ClearDB ¶
func (f *TestPgFixture) ClearDB(t *testing.T)
ClearDB clears the database.
func (*TestPgFixture) GetConfig ¶
func (f *TestPgFixture) GetConfig() *PostgresConfig
GetConfig returns the full config of the Postgres node.
func (*TestPgFixture) GetDSN ¶
func (f *TestPgFixture) GetDSN() string
GetDSN returns the DSN (Data Source Name) for the started Postgres node.
func (*TestPgFixture) TearDown ¶
func (f *TestPgFixture) TearDown(t *testing.T)
TearDown stops the underlying docker container.
type TotalRevenueByDateRangeParams ¶ added in v0.5.0
type TotalRevenueByDateRangeParams = sqlc.GetL402TotalRevenueByDateRangeParams
TotalRevenueByDateRangeParams contains parameters for querying total settled revenue within a date range.
type TransactionExecutor ¶
type TransactionExecutor[Query any] struct { BatchedQuerier // contains filtered or unexported fields }
TransactionExecutor is a generic struct that abstracts away from the type of query a type needs to run under a database transaction, and also the set of options for that transaction. The QueryCreator is used to create a query given a database transaction created by the BatchedQuerier.
func NewTransactionExecutor ¶
func NewTransactionExecutor[Querier any](db BatchedQuerier, createQuery QueryCreator[Querier], opts ...TxExecutorOption) *TransactionExecutor[Querier]
NewTransactionExecutor creates a new instance of a TransactionExecutor given a Querier query object and a concrete type for the type of transactions the Querier understands.
func (*TransactionExecutor[Q]) ExecTx ¶
func (t *TransactionExecutor[Q]) ExecTx(ctx context.Context, txOptions TxOptions, txBody func(Q) error) error
ExecTx is a wrapper for txBody to abstract the creation and commit of a db transaction. The db transaction is embedded in a `*Queries` that txBody needs to use when executing each one of the queries that need to be applied atomically. This can be used by other storage interfaces to parameterize the type of query and options run, in order to have access to batched operations related to a storage object.
type TransactionFilter ¶ added in v0.5.0
type TransactionFilter struct {
Service string
State string
AuthType string
HasDateRange bool
From time.Time
To time.Time
Limit int32
Offset int32
}
TransactionFilter contains the filter criteria for listing or counting transactions.
type Tx ¶
type Tx interface {
// Commit commits the database transaction, an error should be returned
// if the commit isn't possible.
Commit() error
// Rollback rolls back an incomplete database transaction.
// Transactions that were able to be committed can still call this as a
// noop.
Rollback() error
}
Tx represents a database transaction that can be committed or rolled back.
type TxExecutorOption ¶
type TxExecutorOption func(*txExecutorOptions)
TxExecutorOption is a functional option that allows us to pass in optional argument when creating the executor.
func WithTxRetries ¶
func WithTxRetries(numRetries int) TxExecutorOption
WithTxRetries is a functional option that allows us to specify the number of times a transaction should be retried if it fails with a repeatable error.
func WithTxRetryDelay ¶
func WithTxRetryDelay(delay time.Duration) TxExecutorOption
WithTxRetryDelay is a functional option that allows us to specify the delay to wait before a transaction is retried.
type TxOptions ¶
type TxOptions interface {
// ReadOnly returns true if the transaction should be read only.
ReadOnly() bool
}
TxOptions represents a set of options one can use to control what type of database transaction is created. Transaction can wither be read or write.
type UpdateL402TxState ¶ added in v0.5.0
type UpdateL402TxState = sqlc.UpdateL402TransactionStateParams
UpdateL402TxState is a struct that contains the parameters required to update an L402 transaction's state.
type UpsertServiceParams ¶ added in v0.5.0
type UpsertServiceParams = sqlc.UpsertServiceParams
UpsertServiceParams contains the parameters for upserting a service.