2019-03-07 02:19:57 +00:00
|
|
|
package loopdb
|
|
|
|
|
|
|
|
import (
|
2023-05-16 15:40:52 +00:00
|
|
|
"context"
|
2019-03-07 02:19:57 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/lightningnetwork/lnd/lntypes"
|
|
|
|
)
|
|
|
|
|
2019-03-07 04:32:24 +00:00
|
|
|
// SwapStore is the primary database interface used by the loopd system. It
|
|
|
|
// houses information for all pending completed/failed swaps.
|
2019-03-07 02:19:57 +00:00
|
|
|
type SwapStore interface {
|
2019-03-07 04:32:24 +00:00
|
|
|
// FetchLoopOutSwaps returns all swaps currently in the store.
|
2023-05-16 15:40:52 +00:00
|
|
|
FetchLoopOutSwaps(ctx context.Context) ([]*LoopOut, error)
|
2019-03-07 02:19:57 +00:00
|
|
|
|
2023-02-02 11:58:32 +00:00
|
|
|
// FetchLoopOutSwap returns the loop out swap with the given hash.
|
2023-05-16 15:40:52 +00:00
|
|
|
FetchLoopOutSwap(ctx context.Context, hash lntypes.Hash) (*LoopOut, error)
|
2023-02-02 11:58:32 +00:00
|
|
|
|
2019-03-07 04:32:24 +00:00
|
|
|
// CreateLoopOut adds an initiated swap to the store.
|
2023-05-16 15:40:52 +00:00
|
|
|
CreateLoopOut(ctx context.Context, hash lntypes.Hash,
|
|
|
|
swap *LoopOutContract) error
|
2019-03-07 02:19:57 +00:00
|
|
|
|
2023-05-30 07:29:44 +00:00
|
|
|
// BatchCreateLoopOut creates a batch of loop out swaps to the store.
|
|
|
|
BatchCreateLoopOut(ctx context.Context,
|
|
|
|
swaps map[lntypes.Hash]*LoopOutContract) error
|
|
|
|
|
2019-03-07 04:32:24 +00:00
|
|
|
// UpdateLoopOut stores a new event for a target loop out swap. This
|
|
|
|
// appends to the event log for a particular swap as it goes through
|
|
|
|
// the various stages in its lifetime.
|
2023-05-16 15:40:52 +00:00
|
|
|
UpdateLoopOut(ctx context.Context, hash lntypes.Hash, time time.Time,
|
2019-05-15 11:55:41 +00:00
|
|
|
state SwapStateData) error
|
2019-03-07 02:19:57 +00:00
|
|
|
|
2019-03-12 15:09:57 +00:00
|
|
|
// FetchLoopInSwaps returns all swaps currently in the store.
|
2023-05-16 15:40:52 +00:00
|
|
|
FetchLoopInSwaps(ctx context.Context) ([]*LoopIn, error)
|
2019-03-12 15:09:57 +00:00
|
|
|
|
|
|
|
// CreateLoopIn adds an initiated swap to the store.
|
2023-05-16 15:40:52 +00:00
|
|
|
CreateLoopIn(ctx context.Context, hash lntypes.Hash,
|
|
|
|
swap *LoopInContract) error
|
2019-03-12 15:09:57 +00:00
|
|
|
|
2023-05-30 07:29:44 +00:00
|
|
|
// BatchCreateLoopIn creates a batch of loop in swaps to the store.
|
|
|
|
BatchCreateLoopIn(ctx context.Context,
|
|
|
|
swaps map[lntypes.Hash]*LoopInContract) error
|
|
|
|
|
2019-03-12 15:09:57 +00:00
|
|
|
// UpdateLoopIn stores a new event for a target loop in swap. This
|
|
|
|
// appends to the event log for a particular swap as it goes through
|
|
|
|
// the various stages in its lifetime.
|
2023-05-16 15:40:52 +00:00
|
|
|
UpdateLoopIn(ctx context.Context, hash lntypes.Hash, time time.Time,
|
2019-05-15 11:55:41 +00:00
|
|
|
state SwapStateData) error
|
2019-03-12 15:09:57 +00:00
|
|
|
|
2023-05-30 07:29:44 +00:00
|
|
|
// BatchInsertUpdate inserts batch of swap updates to the store.
|
|
|
|
BatchInsertUpdate(ctx context.Context,
|
|
|
|
updateData map[lntypes.Hash][]BatchInsertUpdateData) error
|
|
|
|
|
2022-05-18 19:07:10 +00:00
|
|
|
// PutLiquidityParams writes the serialized `manager.Parameters` bytes
|
|
|
|
// into the bucket.
|
|
|
|
//
|
|
|
|
// NOTE: it's the caller's responsibility to encode the param. Atm,
|
|
|
|
// it's encoding using the proto package's `Marshal` method.
|
2023-05-16 15:40:52 +00:00
|
|
|
PutLiquidityParams(ctx context.Context, params []byte) error
|
2022-05-18 19:07:10 +00:00
|
|
|
|
|
|
|
// FetchLiquidityParams reads the serialized `manager.Parameters` bytes
|
|
|
|
// from the bucket.
|
|
|
|
//
|
|
|
|
// NOTE: it's the caller's responsibility to decode the param. Atm,
|
|
|
|
// it's decoding using the proto package's `Unmarshal` method.
|
2023-05-16 15:40:52 +00:00
|
|
|
FetchLiquidityParams(ctx context.Context) ([]byte, error)
|
2022-05-18 19:07:10 +00:00
|
|
|
|
2024-05-30 20:37:45 +00:00
|
|
|
// BatchUpdateLoopOutSwapCosts updates the swap costs for a batch of
|
|
|
|
// loop out swaps.
|
|
|
|
BatchUpdateLoopOutSwapCosts(ctx context.Context,
|
|
|
|
swaps map[lntypes.Hash]SwapCost) error
|
|
|
|
|
2024-05-31 06:45:34 +00:00
|
|
|
// HasMigration returns true if the migration with the given ID has
|
|
|
|
// been done.
|
|
|
|
HasMigration(ctx context.Context, migrationID string) (bool, error)
|
|
|
|
|
|
|
|
// SetMigration marks the migration with the given ID as done.
|
|
|
|
SetMigration(ctx context.Context, migrationID string) error
|
|
|
|
|
2019-03-07 02:19:57 +00:00
|
|
|
// Close closes the underlying database.
|
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2023-05-30 07:29:44 +00:00
|
|
|
// BatchInsertUpdateData is a struct that holds the data for the
|
|
|
|
// BatchInsertUpdate function.
|
|
|
|
type BatchInsertUpdateData struct {
|
|
|
|
Time time.Time
|
|
|
|
State SwapStateData
|
|
|
|
}
|
|
|
|
|
2019-03-07 02:19:57 +00:00
|
|
|
// TODO(roasbeef): back up method in interface?
|