Documentation
¶
Index ¶
- Constants
- Variables
- func UseLogger(logger btclog.Logger)
- type BaseDB
- type Config
- type FSM
- func (f *FSM) AsyncWaitForExpiredOrSweptAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
- func (r *FSM) Debugf(format string, args ...interface{})
- func (r *FSM) Errorf(format string, args ...interface{})
- func (f *FSM) GetReservationStates() fsm.States
- func (r *FSM) Infof(format string, args ...interface{})
- func (f *FSM) InitAction(ctx context.Context, eventCtx fsm.EventContext) fsm.EventType
- func (f *FSM) SubscribeToConfirmationAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
- type ID
- type InitReservationContext
- type Manager
- func (m *Manager) GetReservation(ctx context.Context, id ID) (*Reservation, error)
- func (m *Manager) GetReservations(ctx context.Context) ([]*Reservation, error)
- func (m *Manager) LockReservation(ctx context.Context, id ID) error
- func (m *Manager) RecoverReservations(ctx context.Context) error
- func (m *Manager) Run(ctx context.Context, height int32, initChan chan struct{}) error
- func (m *Manager) UnlockReservation(ctx context.Context, id ID) error
- type NotificationManager
- type Querier
- type Reservation
- type SQLStore
- func (r *SQLStore) CreateReservation(ctx context.Context, reservation *Reservation) error
- func (r *SQLStore) GetReservation(ctx context.Context, reservationId ID) (*Reservation, error)
- func (r *SQLStore) ListReservations(ctx context.Context) ([]*Reservation, error)
- func (r *SQLStore) UpdateReservation(ctx context.Context, reservation *Reservation) error
- type Store
Constants ¶
const ( KeyFamily = int32(42068) DefaultConfTarget = int32(3) IdLength = 32 )
const Subsystem = "RSRV"
Subsystem defines the sub system name of this package.
Variables ¶
var ( // Init is the initial state of the reservation. Init = fsm.StateType("Init") // WaitForConfirmation is the state where we wait for the reservation // tx to be confirmed. WaitForConfirmation = fsm.StateType("WaitForConfirmation") // Confirmed is the state where the reservation tx has been confirmed. Confirmed = fsm.StateType("Confirmed") // TimedOut is the state where the reservation has timed out. TimedOut = fsm.StateType("TimedOut") // Failed is the state where the reservation has failed. Failed = fsm.StateType("Failed") // Spent is the state where a spend tx has been confirmed. Spent = fsm.StateType("Spent") // Locked is the state where the reservation is locked and can't be // used for instant out swaps. Locked = fsm.StateType("Locked") )
States.
var ( // OnServerRequest is the event that is triggered when the server // requests a new reservation. OnServerRequest = fsm.EventType("OnServerRequest") // OnBroadcast is the event that is triggered when the reservation tx // has been broadcast. OnBroadcast = fsm.EventType("OnBroadcast") // OnConfirmed is the event that is triggered when the reservation tx // has been confirmed. OnConfirmed = fsm.EventType("OnConfirmed") // OnTimedOut is the event that is triggered when the reservation has // timed out. OnTimedOut = fsm.EventType("OnTimedOut") // OnSwept is the event that is triggered when the reservation has been // swept by the server. OnSwept = fsm.EventType("OnSwept") // OnRecover is the event that is triggered when the reservation FSM // recovers from a restart. OnRecover = fsm.EventType("OnRecover") // OnSpent is the event that is triggered when the reservation has been // spent. OnSpent = fsm.EventType("OnSpent") // OnLocked is the event that is triggered when the reservation has // been locked. OnLocked = fsm.EventType("OnLocked") // OnUnlocked is the event that is triggered when the reservation has // been unlocked. OnUnlocked = fsm.EventType("OnUnlocked") )
Events.
var ( ErrReservationAlreadyExists = fmt.Errorf("reservation already exists") ErrReservationNotFound = fmt.Errorf("reservation not found") )
Functions ¶
Types ¶
type BaseDB ¶
type BaseDB interface { Querier // ExecTx allows for executing a function in the context of a database // transaction. ExecTx(ctx context.Context, txOptions loopdb.TxOptions, txBody func(Querier) error) error }
BaseDB is the interface that contains all the queries generated by sqlc for the reservation table and transaction functionality.
type Config ¶
type Config struct { // Store is the database store for the reservations. Store Store // Wallet handles the key derivation for the reservation. Wallet lndclient.WalletKitClient // ChainNotifier is used to subscribe to block notifications. ChainNotifier lndclient.ChainNotifierClient // ReservationClient is the client used to communicate with the // swap server. ReservationClient swapserverrpc.ReservationServiceClient // NotificationManager is the manager that handles the notification // subscriptions. NotificationManager NotificationManager }
Config contains all the services that the reservation FSM needs to operate.
type FSM ¶
type FSM struct { *fsm.StateMachine // contains filtered or unexported fields }
FSM is the state machine that manages the reservation lifecycle.
func NewFSMFromReservation ¶
func NewFSMFromReservation(cfg *Config, reservation *Reservation) *FSM
NewFSMFromReservation creates a new reservation FSM from an existing reservation recovered from the database.
func (*FSM) AsyncWaitForExpiredOrSweptAction ¶
func (f *FSM) AsyncWaitForExpiredOrSweptAction(ctx context.Context, _ fsm.EventContext) fsm.EventType
AsyncWaitForExpiredOrSweptAction waits for the reservation to be either expired or swept. This is non-blocking and can be used to wait for the reservation to expire while expecting other events.
func (*FSM) GetReservationStates ¶
GetReservationStates returns the statemap that defines the reservation state machine.
func (*FSM) InitAction ¶
InitAction is the action that is executed when the reservation state machine is initialized. It creates the reservation in the database and dispatches the payment to the server.
func (*FSM) SubscribeToConfirmationAction ¶
SubscribeToConfirmationAction is the action that is executed when the reservation is waiting for confirmation. It subscribes to the confirmation of the reservation transaction.
type ID ¶
ID is a unique identifier for a reservation.
func (*ID) FromByteSlice ¶
FromByteSlice creates a reservation id from a byte slice.
type InitReservationContext ¶
type InitReservationContext struct {
// contains filtered or unexported fields
}
InitReservationContext contains the request parameters for a reservation.
type Manager ¶
Manager manages the reservation state machines.
func NewManager ¶
NewManager creates a new reservation manager.
func (*Manager) GetReservation ¶
GetReservation returns the reservation for the given id.
func (*Manager) GetReservations ¶
func (m *Manager) GetReservations(ctx context.Context) ([]*Reservation, error)
GetReservations retrieves all reservations from the database.
func (*Manager) LockReservation ¶
LockReservation locks the reservation with the given ID.
func (*Manager) RecoverReservations ¶
RecoverReservations tries to recover all reservations that are still active from the database.
type NotificationManager ¶
type NotificationManager interface { SubscribeReservations(context.Context, ) <-chan *swapserverrpc.ServerReservationNotification }
NotificationManager handles subscribing to incoming reservation subscriptions.
type Querier ¶
type Querier interface { // CreateReservation stores the reservation in the database. CreateReservation(ctx context.Context, arg sqlc.CreateReservationParams) error // GetReservation retrieves the reservation from the database. GetReservation(ctx context.Context, reservationID []byte) (sqlc.Reservation, error) // GetReservationUpdates fetches all updates for a reservation. GetReservationUpdates(ctx context.Context, reservationID []byte) ([]sqlc.ReservationUpdate, error) // GetReservations lists all existing reservations the client has ever // made. GetReservations(ctx context.Context) ([]sqlc.Reservation, error) // InsertReservationUpdate inserts a new reservation update. InsertReservationUpdate(ctx context.Context, arg sqlc.InsertReservationUpdateParams) error // UpdateReservation updates a reservation. UpdateReservation(ctx context.Context, arg sqlc.UpdateReservationParams) error }
Querier is the interface that contains all the queries generated by sqlc for the reservation table.
type Reservation ¶
type Reservation struct { // ID is the unique identifier of the reservation. ID ID // State is the current state of the reservation. State fsm.StateType // ClientPubkey is the client's pubkey. ClientPubkey *btcec.PublicKey // ServerPubkey is the server's pubkey. ServerPubkey *btcec.PublicKey // Value is the amount of the reservation. Value btcutil.Amount // Expiry is the absolute block height at which the reservation expires. Expiry uint32 // KeyLocator is the key locator of the client's key. KeyLocator keychain.KeyLocator // Outpoint is the outpoint of the reservation. Outpoint *wire.OutPoint // InitiationHeight is the height at which the reservation was // initiated. InitiationHeight int32 // ConfirmationHeight is the height at which the reservation was // confirmed. ConfirmationHeight uint32 }
Reservation holds all the necessary information for the 2-of-2 multisig reservation utxo.
func NewReservation ¶
func NewReservation(id ID, serverPubkey, clientPubkey *btcec.PublicKey, value btcutil.Amount, expiry, heightHint uint32, keyLocator keychain.KeyLocator) (*Reservation, error)
func (*Reservation) GetPkScript ¶
func (r *Reservation) GetPkScript() ([]byte, error)
GetPkScript returns the pk script of the reservation.
func (*Reservation) Musig2CreateSession ¶
func (r *Reservation) Musig2CreateSession(ctx context.Context, signer lndclient.SignerClient) (*input.MuSig2SessionInfo, error)
Musig2CreateSession creates a musig2 session for the reservation.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore manages the reservations in the database.
func (*SQLStore) CreateReservation ¶
func (r *SQLStore) CreateReservation(ctx context.Context, reservation *Reservation) error
CreateReservation stores the reservation in the database.
func (*SQLStore) GetReservation ¶
GetReservation retrieves the reservation from the database.
func (*SQLStore) ListReservations ¶
func (r *SQLStore) ListReservations(ctx context.Context) ([]*Reservation, error)
ListReservations lists all existing reservations the client has ever made.
func (*SQLStore) UpdateReservation ¶
func (r *SQLStore) UpdateReservation(ctx context.Context, reservation *Reservation) error
UpdateReservation updates the reservation in the database.
type Store ¶
type Store interface { // CreateReservation stores the reservation in the database. CreateReservation(ctx context.Context, reservation *Reservation) error // UpdateReservation updates the reservation in the database. UpdateReservation(ctx context.Context, reservation *Reservation) error // GetReservation retrieves the reservation from the database. GetReservation(ctx context.Context, id ID) (*Reservation, error) // ListReservations lists all existing reservations the client has ever // made. ListReservations(ctx context.Context) ([]*Reservation, error) }
Store is the interface that stores the reservations.