{"modulePath":"github.com/lightninglabs/loop","version":"v0.36.0-beta","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package loopdb\n\n## Constants\n\n```go\nconst (\n\t// DefaultLoopOutHtlcConfirmations is the default number of\n\t// confirmations we set for a loop out htlc.\n\tDefaultLoopOutHtlcConfirmations uint32 = 1\n\n\t// DefaultLoopDBTimeout is the default maximum time we wait for the\n\t// Loop bbolt database to be opened. If the database is already opened\n\t// by another process, the unique lock cannot be obtained. With the\n\t// timeout we error out after the given time instead of just blocking\n\t// for forever.\n\tDefaultLoopDBTimeout = 5 * time.Second\n)\n```\n\n```go\nconst (\n\t// StateTypePending indicates that the swap is still pending.\n\tStateTypePending SwapStateType = 0\n\n\t// StateTypeSuccess indicates that the swap has completed successfully.\n\tStateTypeSuccess = 1\n\n\t// StateTypeFail indicates that the swap has failed.\n\tStateTypeFail = 2\n)\n```\n\n```go\nconst (\n\tPostgresTag = \"11\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrLoopOutsNotEqual        = errors.New(\"loop outs not equal\")\n\tErrLoopInsNotEqual         = errors.New(\"loop ins not equal\")\n\tErrLiquidityParamsNotEqual = errors.New(\"liquidity params not equal\")\n)\n```\n\n```go\nvar (\n\t// DefaultPostgresFixtureLifetime is the default maximum time a Postgres\n\t// test fixture is being kept alive. After that time the docker\n\t// container will be terminated forcefully, even if the tests aren't\n\t// fully executed yet. So this time needs to be chosen correctly to be\n\t// longer than the longest expected individual test run time.\n\tDefaultPostgresFixtureLifetime = 10 * time.Minute\n)\n```\n\n```go\nvar (\n\n\t// ErrDBReversion is returned when detecting an attempt to revert to a\n\t// prior database version.\n\tErrDBReversion = fmt.Errorf(\"channel db cannot revert to prior version\")\n)\n```\n\n## Functions\n\n```go\nfunc CurrentRPCProtocolVersion() swapserverrpc.ProtocolVersion\n```\nCurrentRPCProtocolVersion returns the RPC protocol version selected to be used for new swaps.\n\n```go\nfunc EnableExperimentalProtocol()\n```\nEnableExperimentalProtocol sets the current protocol version to include all experimental features. Do not call this function directly: used in loopd and unit tests only.\n\n```go\nfunc MapSQLError(err error) error\n```\nMapSQLError attempts to interpret a given error as a database agnostic SQL error.\n\n```go\nfunc MarshalKeyLocator(keyLocator keychain.KeyLocator) ([]byte, error)\n```\nMarshalKeyLocator marshals a keychain.KeyLocator to a byte slice.\n\n```go\nfunc MarshalProtocolVersion(version ProtocolVersion) []byte\n```\nMarshalProtocolVersion marshals a ProtocolVersion value to a byte slice.\n\n```go\nfunc NewBoltSwapStore(dbPath string, chainParams *chaincfg.Params) (\n\t*boltSwapStore, error)\n```\nNewBoltSwapStore creates a new client swap store.\n\n```go\nfunc NewMigrationError(err error) *migrationError\n```\n\n```go\nfunc ResetCurrentProtocolVersion()\n```\nResetCurrentProtocolVersion resets the current protocol version to the stable protocol. Note: used in integration tests only!\n\n```go\nfunc UnmarshalKeyLocator(data []byte) (keychain.KeyLocator, error)\n```\nUnmarshalKeyLocator unmarshals a keychain.KeyLocator from a byte slice.\n\n```go\nfunc UseLogger(logger btclog.Logger)\n```\nUseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.\n\n## Types\n\n```go\ntype BaseDB struct {\n\t*sql.DB\n\n\t*sqlc.Queries\n\t// contains filtered or unexported fields\n}\n```\nBaseDB is the base database struct that each implementation can embed to gain some common functionality.\n\n```go\nfunc (db *BaseDB) BatchCreateLoopIn(ctx context.Context,\n\tswaps map[lntypes.Hash]*LoopInContract) error\n```\nBatchCreateLoopIn adds multiple initiated swaps to the store.\n\n```go\nfunc (db *BaseDB) BatchCreateLoopOut(ctx context.Context,\n\tswaps map[lntypes.Hash]*LoopOutContract) error\n```\nBatchCreateLoopOut adds multiple initiated swaps to the store.\n\n```go\nfunc (db *BaseDB) BatchInsertUpdate(ctx context.Context,\n\tupdateData map[lntypes.Hash][]BatchInsertUpdateData) error\n```\nBatchInsertUpdate inserts multiple swap updates to the store.\n\n```go\nfunc (db *BaseDB) BatchUpdateLoopOutSwapCosts(ctx context.Context,\n\tcosts map[lntypes.Hash]SwapCost) error\n```\nBatchUpdateLoopOutSwapCosts updates the swap costs for a batch of loop out swaps.\n\n```go\nfunc (db *BaseDB) BeginTx(ctx context.Context,\n\topts TxOptions) (*sql.Tx, error)\n```\nBeginTx wraps the normal sql specific BeginTx method with the TxOptions interface. This interface is then mapped to the concrete sql tx options struct.\n\n```go\nfunc (db *BaseDB) CreateLoopIn(ctx context.Context, hash lntypes.Hash,\n\tswap *LoopInContract) error\n```\nCreateLoopIn adds an initiated swap to the store.\n\n```go\nfunc (db *BaseDB) CreateLoopOut(ctx context.Context, hash lntypes.Hash,\n\tswap *LoopOutContract) error\n```\nCreateLoopOut adds an initiated swap to the store.\n\n```go\nfunc (db *BaseDB) ExecTx(ctx context.Context, txOptions TxOptions,\n\ttxBody func(*sqlc.Queries) error) error\n```\nExecTx is a wrapper for txBody to abstract the creation and commit of a db transaction. The db transaction is embedded in a \\`\\*sqlc.Queries\\` that txBody needs to use when executing each one of the queries that need to be applied atomically.\n\n```go\nfunc (db *BaseDB) FetchLiquidityParams(ctx context.Context) ([]byte,\n\terror)\n```\nFetchLiquidityParams reads the serialized \\`manager.Parameters\\` bytes from the bucket.\n\nNOTE: it's the caller's responsibility to decode the param. Atm, it's decoding using the proto package's \\`Unmarshal\\` method.\n\n```go\nfunc (db *BaseDB) FetchLoopInSwaps(ctx context.Context) (\n\t[]*LoopIn, error)\n```\nFetchLoopInSwaps returns all swaps currently in the store.\n\n```go\nfunc (db *BaseDB) FetchLoopOutSwap(ctx context.Context,\n\thash lntypes.Hash) (*LoopOut, error)\n```\nFetchLoopOutSwap returns the loop out swap with the given hash.\n\n```go\nfunc (db *BaseDB) FetchLoopOutSwaps(ctx context.Context) ([]*LoopOut,\n\terror)\n```\nFetchLoopOutSwaps returns all swaps currently in the store.\n\n```go\nfunc (db *BaseDB) FixFaultyTimestamps(ctx context.Context) error\n```\nFixFaultyTimestamps fixes faulty timestamps in the database, caused by using milliseconds instead of seconds as the publication deadline.\n\n```go\nfunc (db *BaseDB) GetNetwork() *chaincfg.Params\n```\nGetNetwork returns the network(mainnet, testnet...) that the database is running on.\n\n```go\nfunc (db *BaseDB) HasMigration(ctx context.Context, migrationID string) (\n\tbool, error)\n```\nHasMigration returns true if the migration with the given ID has been done.\n\n```go\nfunc (db *BaseDB) PutLiquidityParams(ctx context.Context,\n\tparams []byte) error\n```\nPutLiquidityParams writes the serialized \\`manager.Parameters\\` bytes into the bucket.\n\nNOTE: it's the caller's responsibility to encode the param. Atm, it's encoding using the proto package's \\`Marshal\\` method.\n\n```go\nfunc (db *BaseDB) SetMigration(ctx context.Context, migrationID string) error\n```\nSetMigration marks the migration with the given ID as done.\n\n```go\nfunc (db *BaseDB) UpdateLoopIn(ctx context.Context, hash lntypes.Hash,\n\ttime time.Time, state SwapStateData) error\n```\nUpdateLoopIn 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.\n\n```go\nfunc (db *BaseDB) UpdateLoopOut(ctx context.Context, hash lntypes.Hash,\n\ttime time.Time, state SwapStateData) error\n```\nUpdateLoopOut 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.\n\n```go\nfunc (db *BaseDB) UpdateLoopOutAssetInfo(ctx context.Context, hash lntypes.Hash,\n\tasset *LoopOutAssetSwap) error\n```\nUpdateLoopOutAssetInfo updates the offchain send amounts of the prepay and swap payment for an asset loop out swap.\n\n```go\ntype BatchInsertUpdateData struct {\n\tTime  time.Time\n\tState SwapStateData\n}\n```\nBatchInsertUpdateData is a struct that holds the data for the BatchInsertUpdate function.\n\n```go\ntype BatchedQuerier interface {\n\tsqlc.Querier\n\n\t// ExecTx is a wrapper for txBody to abstract the creation and commit of\n\t// a db transaction. The db transaction is embedded in a `*sqlc.Queries`\n\t// that txBody needs to use when executing each one of the queries that\n\t// need to be applied atomically.\n\tExecTx(ctx context.Context, txOptions TxOptions,\n\t\ttxBody func(*sqlc.Queries) error) error\n}\n```\nBatchedQuerier implements all DB queries and ExecTx on \\*sqlc.Queries. It is implemented by BaseDB, SqliteSwapStore, etc.\n\n```go\ntype ChannelSet []uint64\n```\nChannelSet stores a set of channels.\n\n```go\nfunc ConvertOutgoingChanSet(outgoingChanSet string) (ChannelSet, error)\n```\nConvertOutgoingChanSet converts a comma separated string of channel IDs into a ChannelSet.\n\n```go\nfunc NewChannelSet(set []uint64) (ChannelSet, error)\n```\nNewChannelSet instantiates a new channel set and verifies that there are no duplicates present.\n\n```go\nfunc (c ChannelSet) String() string\n```\nString returns the human-readable representation of a channel set.\n\n```go\ntype ErrSqlUniqueConstraintViolation struct {\n\tDbError error\n}\n```\nErrSqlUniqueConstraintViolation is an error type which represents a database agnostic SQL unique constraint violation.\n\n```go\nfunc (e ErrSqlUniqueConstraintViolation) Error() string\n```\n\n```go\ntype HtlcKeys struct {\n\t// SenderScriptKey is the sender's public key that is used in the HTLC,\n\t// specifically when constructing the script spend scripts.\n\tSenderScriptKey [33]byte\n\n\t// SenderInternalPubKey is the sender's internal pubkey that is used in\n\t// taproot HTLCs as part of the aggregate internal key.\n\tSenderInternalPubKey [33]byte\n\n\t// ReceiverScriptKey is the receiver's public key that is used in the\n\t// HTLC, specifically when constructing the script spend scripts.\n\tReceiverScriptKey [33]byte\n\n\t// ReceiverInternalPubKey is the sender's internal pubkey that is used\n\t// in taproot HTLCs as part of the aggregate internal key.\n\tReceiverInternalPubKey [33]byte\n\n\t// ClientScriptKeyLocator is the client's key locator for the key used\n\t// in the HTLC script spend scripts.\n\tClientScriptKeyLocator keychain.KeyLocator\n}\n```\nHtlcKeys is a holder of all keys used when constructing the swap HTLC. Since it's used for both loop in and loop out swaps it may hold partial information about the sender or receiver depending on the swap type.\n\n```go\ntype Loop struct {\n\tHash   lntypes.Hash\n\tEvents []*LoopEvent\n}\n```\nLoop contains fields shared between LoopIn and LoopOut.\n\n```go\nfunc (s *Loop) LastUpdate() *LoopEvent\n```\nLastUpdate returns the most recent update of this swap.\n\n```go\nfunc (s *Loop) State() SwapStateData\n```\nState returns the most recent state of this swap.\n\n```go\ntype LoopEvent struct {\n\tSwapStateData\n\n\t// Time is the time that this swap had its state changed.\n\tTime time.Time\n}\n```\nLoopEvent contains the dynamic data of a swap.\n\n```go\ntype LoopIn struct {\n\tLoop\n\n\tContract *LoopInContract\n}\n```\nLoopIn is a combination of the contract and the updates.\n\n```go\nfunc (s *LoopIn) LastUpdateTime() time.Time\n```\nLastUpdateTime returns the last update time of this swap.\n\n```go\ntype LoopInContract struct {\n\tSwapContract\n\n\t// HtlcConfTarget specifies the targeted confirmation target for the\n\t// client sweep tx.\n\tHtlcConfTarget int32\n\n\t// LastHop is the last hop to use for the loop in swap (optional).\n\tLastHop *route.Vertex\n\n\t// ExternalHtlc specifies whether the htlc is published by an external\n\t// source.\n\tExternalHtlc bool\n}\n```\nLoopInContract contains the data that is serialized to persistent storage for pending loop in swaps.\n\n```go\ntype LoopOut struct {\n\tLoop\n\n\t// Contract is the active contract for this swap. It describes the\n\t// precise details of the swap including the final fee, CLTV value,\n\t// etc.\n\tContract *LoopOutContract\n}\n```\nLoopOut is a combination of the contract and the updates.\n\n```go\nfunc ConvertLoopOutRow(network *chaincfg.Params, row sqlc.GetLoopOutSwapRow,\n\tupdates []sqlc.SwapUpdate) (*LoopOut,\n\terror)\n```\nConvertLoopOutRow converts a database row containing a loop out swap to a LoopOut struct.\n\n```go\nfunc (s *LoopOut) LastUpdateTime() time.Time\n```\nLastUpdateTime returns the last update time of this swap.\n\n```go\ntype LoopOutAssetSwap struct {\n\t// AssetId is the optional asset id that is used to pay the swap invoice.\n\tAssetId []byte\n\n\t// PrepayRfqId is the rfq id that is used to pay the prepay invoice.\n\tPrepayRfqId []byte\n\n\t// SwapRfqId is the rfq id that is used to pay the swap invoice.\n\tSwapRfqId []byte\n\n\t// PrepayPaidAmt is the asset amount that was paid for the prepay\n\t// invoice.\n\tPrepayPaidAmt uint64\n\n\t// SwapPaidAmt is the asset amount that was paid for the swap invoice.\n\tSwapPaidAmt uint64\n}\n```\n\n```go\ntype LoopOutContract struct {\n\t// SwapContract contains basic information pertaining to this swap.\n\t// Each swap type has a base contract, then swap specific information\n\t// on top of it.\n\tSwapContract\n\n\t// DestAddr is the destination address of the loop out swap.\n\tDestAddr btcutil.Address\n\n\t// IsExternalAddr indicates whether the destination address does not\n\t// belong to the backing lnd node.\n\tIsExternalAddr bool\n\n\t// SwapInvoice is the invoice that is to be paid by the client to\n\t// initiate the loop out swap.\n\tSwapInvoice string\n\n\t// PaymentAddr authenticates swap RPCs when the swap invoice contains\n\t// blinded paths. A nil value uses the ordinary invoice's payment address.\n\tPaymentAddr *[32]byte\n\n\t// MaxSwapRoutingFee is the maximum off-chain fee in msat that may be\n\t// paid for the swap payment to the server.\n\tMaxSwapRoutingFee btcutil.Amount\n\n\t// SweepConfTarget specifies the targeted confirmation target for the\n\t// client sweep tx.\n\tSweepConfTarget int32\n\n\t// HtlcConfirmations is the number of confirmations we require the on\n\t// chain htlc to have before proceeding with the swap.\n\tHtlcConfirmations uint32\n\n\t// OutgoingChanSet is the set of short ids of channels that may be used.\n\t// If empty, any channel may be used.\n\tOutgoingChanSet ChannelSet\n\n\t// PrepayInvoice is the invoice that the client should pay to the\n\t// server that will be returned if the swap is complete.\n\tPrepayInvoice string\n\n\t// MaxPrepayRoutingFee is the maximum off-chain fee in msat that may be\n\t// paid for the prepayment to the server.\n\tMaxPrepayRoutingFee btcutil.Amount\n\n\t// SwapPublicationDeadline is a timestamp that the server commits to\n\t// have the on-chain swap published by. It is set by the client to\n\t// allow the server to delay the publication in exchange for possibly\n\t// lower fees.\n\tSwapPublicationDeadline time.Time\n\n\t// PaymentTimeout is the timeout for any individual off-chain payment\n\t// attempt.\n\tPaymentTimeout time.Duration\n\n\t// AssetSwapInfo contains information, should the loop out swpa be\n\t// paid via an asset channel.\n\tAssetSwapInfo *LoopOutAssetSwap\n}\n```\nLoopOutContract contains the data that is serialized to persistent storage for pending swaps.\n\n```go\ntype MigratorManager struct {\n\t// contains filtered or unexported fields\n}\n```\nMigratorManager is a struct that handles migrating data from one SwapStore to another.\n\n```go\nfunc NewMigratorManager(fromStore SwapStore,\n\ttoStore SwapStore) *MigratorManager\n```\nNewMigratorManager creates a new MigratorManager.\n\n```go\nfunc (m *MigratorManager) RunMigrations(ctx context.Context) error\n```\nRunMigrations runs the migrations from the fromStore to the toStore.\n\n```go\ntype PostgresConfig struct {\n\tSkipMigrations     bool   `long:\"skipmigrations\" description:\"Skip applying migrations on startup.\"`\n\tHost               string `long:\"host\" description:\"Database server hostname.\"`\n\tPort               int    `long:\"port\" description:\"Database server port.\"`\n\tUser               string `long:\"user\" description:\"Database user.\"`\n\tPassword           string `long:\"password\" description:\"Database user's password.\"` //nolint:gosec\n\tDBName             string `long:\"dbname\" description:\"Database name to use.\"`\n\tMaxOpenConnections int32  `long:\"maxconnections\" description:\"Maximum number of open connections to the database server. Defaults to 25 if unset.\"`\n\tRequireSSL         bool   `long:\"requiressl\" description:\"Whether to require using SSL (mode: require) when connecting to the server.\"`\n}\n```\nPostgresConfig holds the postgres database configuration.\n\n```go\nfunc (s *PostgresConfig) DSN(hidePassword bool) string\n```\nDSN returns the data source name used to connect to the database.\n\n```go\ntype PostgresStore struct {\n\t*BaseDB\n\t// contains filtered or unexported fields\n}\n```\nPostgresStore is a database store implementation that uses a Postgres backend.\n\n```go\nfunc NewPostgresStore(cfg *PostgresConfig,\n\tnetwork *chaincfg.Params) (*PostgresStore, error)\n```\nNewPostgresStore creates a new store that is backed by a Postgres database backend.\n\n```go\nfunc NewTestPostgresDB(t *testing.T) *PostgresStore\n```\nNewTestPostgresDB is a helper function that creates a Postgres database for testing.\n\n```go\ntype ProtocolVersion uint32\n```\nProtocolVersion represents the protocol version (declared on rpc level) that the client declared to us.\n\n```go\nconst (\n\t// ProtocolVersionLegacy indicates that the client is a legacy version\n\t// that did not report its protocol version.\n\tProtocolVersionLegacy ProtocolVersion = 0\n\n\t// ProtocolVersionMultiLoopOut indicates that the client supports multi\n\t// loop out.\n\tProtocolVersionMultiLoopOut ProtocolVersion = 1\n\n\t// ProtocolVersionSegwitLoopIn indicates that the client supports segwit\n\t// loop in.\n\tProtocolVersionSegwitLoopIn ProtocolVersion = 2\n\n\t// ProtocolVersionPreimagePush indicates that the client will push loop\n\t// out preimages to the server to speed up claim.\n\tProtocolVersionPreimagePush ProtocolVersion = 3\n\n\t// ProtocolVersionUserExpiryLoopOut indicates that the client will\n\t// propose a cltv expiry height for loop out.\n\tProtocolVersionUserExpiryLoopOut ProtocolVersion = 4\n\n\t// ProtocolVersionHtlcV2 indicates that the client will use the new\n\t// HTLC v2 scripts for swaps.\n\tProtocolVersionHtlcV2 ProtocolVersion = 5\n\n\t// ProtocolVersionMultiLoopIn indicates that the client creates a probe\n\t// invoice so that the server can perform a multi-path probe.\n\tProtocolVersionMultiLoopIn ProtocolVersion = 6\n\n\t// ProtocolVersionLoopOutCancel indicates that the client supports\n\t// canceling loop out swaps.\n\tProtocolVersionLoopOutCancel = 7\n\n\t// ProtocolVersionProbe indicates that the client is able to request\n\t// the server to perform a probe to test inbound liquidty.\n\tProtocolVersionProbe ProtocolVersion = 8\n\n\t// ProtocolVersionRoutingPlugin indicates that the client may ask the\n\t// server to use a custom routing helper plugin in order to enhance\n\t// off-chain payments corresponding to a swap.\n\tProtocolVersionRoutingPlugin = 9\n\n\t// ProtocolVersionHtlcV3 indicates that the client will now use the new\n\t// HTLC v3 (P2TR) script for swaps.\n\tProtocolVersionHtlcV3 = 10\n\n\t// ProtocolVersionMuSig2 will enable MuSig2 signature scheme for loops.\n\tProtocolVersionMuSig2 ProtocolVersion = 11\n\n\t// ProtocolVersionUnrecorded is set for swaps were created before we\n\t// started saving protocol version with swaps.\n\tProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32\n)\n```\n\n```go\nfunc CurrentProtocolVersion() ProtocolVersion\n```\nCurrentProtocolVersion returns the internal protocol version selected to be used for new swaps.\n\n```go\nfunc UnmarshalProtocolVersion(b []byte) (ProtocolVersion, error)\n```\nUnmarshalProtocolVersion attempts to unmarshal a byte slice to a ProtocolVersion value. If the unmarshal fails, ProtocolVersionUnrecorded is returned along with an error.\n\n```go\nfunc (p ProtocolVersion) String() string\n```\nString returns the string representation of a protocol version.\n\n```go\nfunc (p ProtocolVersion) Valid() bool\n```\nValid returns true if the value of the ProtocolVersion is valid.\n\n```go\ntype SqliteConfig struct {\n\t// SkipMigrations if true, then all the tables will be created on start\n\t// up if they don't already exist.\n\tSkipMigrations bool `long:\"skipmigrations\" description:\"Skip applying migrations on startup.\"`\n\n\t// DatabaseFileName is the full file path where the database file can be\n\t// found.\n\tDatabaseFileName string `long:\"dbfile\" description:\"The full path to the database.\"`\n}\n```\nSqliteConfig holds all the config arguments needed to interact with our sqlite DB.\n\n```go\ntype SqliteSwapStore struct {\n\t*BaseDB\n\t// contains filtered or unexported fields\n}\n```\nSqliteSwapStore is a sqlite3 based database for the loop daemon.\n\n```go\nfunc NewSqliteStore(cfg *SqliteConfig, network *chaincfg.Params) (*SqliteSwapStore, error)\n```\nNewSqliteStore attempts to open a new sqlite database based on the passed config.\n\n```go\nfunc NewTestDB(t *testing.T) *SqliteSwapStore\n```\nNewTestDB is a helper function that creates an SQLite database for testing.\n\n```go\nfunc NewTestSqliteDB(t *testing.T) *SqliteSwapStore\n```\nNewTestSqliteDB is a helper function that creates an SQLite database for testing.\n\n```go\ntype SqliteTxOptions struct {\n\t// contains filtered or unexported fields\n}\n```\nSqliteTxOptions defines the set of db txn options the KeyStore understands.\n\n```go\nfunc NewSqlReadOpts() *SqliteTxOptions\n```\nNewSqlReadOpts returns a new KeyStoreTxOptions instance that triggers a read transaction.\n\n```go\nfunc NewSqlWriteOpts() *SqliteTxOptions\n```\nNewSqlWriteOpts returns a new KeyStoreTxOptions instance that triggers a write (regular) transaction.\n\n```go\nfunc (r *SqliteTxOptions) ReadOnly() bool\n```\nReadOnly returns true if the transaction should be read only.\n\nNOTE: This implements the TxOptions interface.\n\n```go\ntype StoreMock struct {\n\tsync.RWMutex\n\n\tLoopOutSwaps   map[lntypes.Hash]*LoopOutContract\n\tLoopOutUpdates map[lntypes.Hash][]SwapStateData\n\n\tLoopInSwaps   map[lntypes.Hash]*LoopInContract\n\tLoopInUpdates map[lntypes.Hash][]SwapStateData\n\t// contains filtered or unexported fields\n}\n```\nStoreMock implements a mock client swap store.\n\n```go\nfunc NewStoreMock(t *testing.T) *StoreMock\n```\nNewStoreMock instantiates a new mock store.\n\n```go\nfunc (s *StoreMock) AssertLoopInState(\n\texpectedState SwapState) SwapStateData\n```\nAssertLoopInState asserts that a specified state transition is persisted to disk.\n\n```go\nfunc (s *StoreMock) AssertLoopInStored()\n```\nAssertLoopInStored asserts that a loop-in swap is stored.\n\n```go\nfunc (s *StoreMock) AssertLoopOutState(expectedState SwapState)\n```\nAssertLoopOutState asserts that a specified state transition is persisted to disk.\n\n```go\nfunc (s *StoreMock) AssertLoopOutStored()\n```\nAssertLoopOutStored asserts that a swap is stored.\n\n```go\nfunc (s *StoreMock) AssertStoreFinished(expectedResult SwapState)\n```\nAssertStoreFinished asserts that a swap is marked as finished.\n\n```go\nfunc (s *StoreMock) AssertStorePreimageReveal()\n```\nAssertStorePreimageReveal asserts that a swap is marked as preimage revealed.\n\n```go\nfunc (b *StoreMock) BatchCreateLoopIn(ctx context.Context,\n\tswaps map[lntypes.Hash]*LoopInContract) error\n```\nBatchCreateLoopIn creates many loop in swaps in a batch.\n\n```go\nfunc (b *StoreMock) BatchCreateLoopOut(ctx context.Context,\n\tswaps map[lntypes.Hash]*LoopOutContract) error\n```\nBatchCreateLoopOut creates many loop out swaps in a batch.\n\n```go\nfunc (b *StoreMock) BatchInsertUpdate(ctx context.Context,\n\tupdateData map[lntypes.Hash][]BatchInsertUpdateData) error\n```\nBatchInsertUpdate inserts many updates for a swap in a batch.\n\n```go\nfunc (s *StoreMock) BatchUpdateLoopOutSwapCosts(ctx context.Context,\n\tcosts map[lntypes.Hash]SwapCost) error\n```\nBatchUpdateLoopOutSwapCosts updates the swap costs for a batch of loop out swaps.\n\n```go\nfunc (s *StoreMock) Close() error\n```\nClose closes the store.\n\n```go\nfunc (s *StoreMock) CreateLoopIn(ctx context.Context, hash lntypes.Hash,\n\tswap *LoopInContract) error\n```\nCreateLoopIn adds an initiated loop in swap to the store.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) CreateLoopOut(ctx context.Context, hash lntypes.Hash,\n\tswap *LoopOutContract) error\n```\nCreateLoopOut adds an initiated swap to the store.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) FetchLiquidityParams(ctx context.Context) ([]byte, error)\n```\nFetchLiquidityParams reads the serialized \\`manager.Parameters\\` bytes from the bucket.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) FetchLoopInSwaps(ctx context.Context) ([]*LoopIn,\n\terror)\n```\nFetchLoopInSwaps returns all in swaps currently in the store.\n\n```go\nfunc (s *StoreMock) FetchLoopOutSwap(ctx context.Context,\n\thash lntypes.Hash) (*LoopOut, error)\n```\nFetchLoopOutSwap returns a swap currently in the store.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) FetchLoopOutSwaps(ctx context.Context) ([]*LoopOut, error)\n```\nFetchLoopOutSwaps returns all swaps currently in the store.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) HasMigration(ctx context.Context, migrationID string) (\n\tbool, error)\n```\nHasMigration returns true if the migration with the given ID has been done.\n\n```go\nfunc (s *StoreMock) IsDone() error\n```\nIsDone asserts that the store mock has no pending operations.\n\n```go\nfunc (s *StoreMock) PutLiquidityParams(ctx context.Context,\n\tparams []byte) error\n```\nPutLiquidityParams writes the serialized \\`manager.Parameters\\` bytes into the bucket.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) SetMigration(ctx context.Context,\n\tmigrationID string) error\n```\nSetMigration marks the migration with the given ID as done.\n\n```go\nfunc (s *StoreMock) UpdateLoopIn(ctx context.Context, hash lntypes.Hash,\n\ttime time.Time, state SwapStateData) error\n```\nUpdateLoopIn 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.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) UpdateLoopOut(ctx context.Context, hash lntypes.Hash,\n\ttime time.Time, state SwapStateData) error\n```\nUpdateLoopOut 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.\n\nNOTE: Part of the SwapStore interface.\n\n```go\nfunc (s *StoreMock) UpdateLoopOutAssetInfo(ctx context.Context,\n\thash lntypes.Hash, asset *LoopOutAssetSwap) error\n```\n\n```go\ntype SwapContract struct {\n\t// Preimage is the preimage for the swap.\n\tPreimage lntypes.Preimage\n\n\t// AmountRequested is the total amount of the swap.\n\tAmountRequested btcutil.Amount\n\n\t// HtlcKeys holds all keys used in the swap HTLC construction.\n\tHtlcKeys HtlcKeys\n\n\t// CltvExpiry is the total absolute CLTV expiry of the swap.\n\tCltvExpiry int32\n\n\t// MaxSwapFee is the maximum we are willing to pay the server for the\n\t// swap.\n\tMaxSwapFee btcutil.Amount\n\n\t// MaxMinerFee is the maximum in on-chain fees that we are willing to\n\t// spend.\n\tMaxMinerFee btcutil.Amount\n\n\t// InitiationHeight is the block height at which the swap was\n\t// initiated.\n\tInitiationHeight int32\n\n\t// InitiationTime is the time at which the swap was initiated.\n\tInitiationTime time.Time\n\n\t// Label contains an optional label for the swap.\n\tLabel string\n\n\t// ProtocolVersion stores the protocol version when the swap was\n\t// created.\n\tProtocolVersion ProtocolVersion\n}\n```\nSwapContract contains the base data that is serialized to persistent storage for pending swaps.\n\n```go\ntype SwapCost struct {\n\t// Server is the amount paid to the server.\n\tServer btcutil.Amount\n\n\t// Onchain is the amount paid to miners for the onchain tx.\n\tOnchain btcutil.Amount\n\n\t// Offchain is the amount paid in routing fees.\n\tOffchain btcutil.Amount\n}\n```\nSwapCost is a breakdown of the final swap costs.\n\n```go\nfunc (s SwapCost) Total() btcutil.Amount\n```\nTotal returns the total costs represented by swap costs.\n\n```go\ntype SwapState uint8\n```\nSwapState indicates the current state of a swap. This enumeration is the union of loop in and loop out states. A single type is used for both swap types to be able to reduce code duplication that would otherwise be required.\n\n```go\nconst (\n\t// StateInitiated is the initial state of a swap. At that point, the\n\t// initiation call to the server has been made and the payment process\n\t// has been started for the swap and prepayment invoices.\n\tStateInitiated SwapState = 0\n\n\t// StatePreimageRevealed is reached when the sweep tx publication is\n\t// first attempted. From that point on, we should consider the preimage\n\t// to no longer be secret and we need to do all we can to get the sweep\n\t// confirmed. This state will mostly coalesce with StateHtlcConfirmed,\n\t// except in the case where we wait for fees to come down before we\n\t// sweep.\n\tStatePreimageRevealed SwapState = 1\n\n\t// StateSuccess is the final swap state that is reached when the sweep\n\t// tx has the required confirmation depth (SweepConfDepth) and the\n\t// server pulled the off-chain htlc.\n\tStateSuccess SwapState = 2\n\n\t// StateFailOffchainPayments indicates that it wasn't possible to find\n\t// routes for one or both of the off-chain payments to the server that\n\t// satisfied the payment restrictions (fee and timelock limits).\n\tStateFailOffchainPayments SwapState = 3\n\n\t// StateFailTimeout indicates that the on-chain htlc wasn't confirmed\n\t// before its expiry or confirmed too late (MinPreimageRevealDelta\n\t// violated).\n\tStateFailTimeout SwapState = 4\n\n\t// StateFailSweepTimeout indicates that the on-chain htlc wasn't swept\n\t// before the server revoked the htlc. The server didn't pull the\n\t// off-chain htlc (even though it could have) and we timed out the\n\t// off-chain htlc ourselves. No funds lost.\n\tStateFailSweepTimeout SwapState = 5\n\n\t// StateFailInsufficientValue indicates that the published on-chain htlc\n\t// had a value lower than the requested amount.\n\tStateFailInsufficientValue SwapState = 6\n\n\t// StateFailTemporary indicates that the swap cannot progress because\n\t// of an internal error. This is not a final state. Manual intervention\n\t// (like a restart) is required to solve this problem.\n\tStateFailTemporary SwapState = 7\n\n\t// StateHtlcPublished means that the client published the on-chain htlc.\n\tStateHtlcPublished SwapState = 8\n\n\t// StateInvoiceSettled means that the swap invoice has been paid by the\n\t// server.\n\tStateInvoiceSettled SwapState = 9\n\n\t// StateFailIncorrectHtlcAmt indicates that the amount of an externally\n\t// published loop in htlc didn't match the swap amount.\n\tStateFailIncorrectHtlcAmt SwapState = 10\n\n\t// StateFailAbandoned indicates that a swap has been abandoned. Its\n\t// execution has been canceled. It won't further be processed.\n\tStateFailAbandoned SwapState = 11\n\n\t// StateFailInsufficientConfirmedBalance indicates that the swap wasn't\n\t// published due to insufficient confirmed balance.\n\tStateFailInsufficientConfirmedBalance SwapState = 12\n\n\t// StateFailIncorrectHtlcAmtSwept indicates that the amount of an\n\t// externally published loop in htlc that didn't match the swap amount\n\t// has been swept back to the user after the htlc timeout period.\n\tStateFailIncorrectHtlcAmtSwept SwapState = 13\n)\n```\n\n```go\nfunc (s SwapState) IsFinal() bool\n```\nIsFinal returns true if the swap is in a final state.\n\n```go\nfunc (s SwapState) IsPending() bool\n```\nIsPending returns true if the swap is in a pending state.\n\n```go\nfunc (s SwapState) String() string\n```\nString returns a string representation of the swap's state.\n\n```go\nfunc (s SwapState) Type() SwapStateType\n```\nType returns the type of the SwapState it is called on.\n\n```go\ntype SwapStateData struct {\n\t// State is the state the swap is in.\n\tState SwapState\n\n\t// Cost are the accrued (final) costs so far.\n\tCost SwapCost\n\n\t// HtlcTxHash is the tx id of the confirmed htlc.\n\tHtlcTxHash *chainhash.Hash\n}\n```\nSwapStateData is all persistent data to describe the current swap state.\n\n```go\ntype SwapStateType uint8\n```\nSwapStateType defines the types of swap states that exist. Every swap state defined as type SwapState above, falls into one of these SwapStateType categories.\n\n```go\ntype SwapStore interface {\n\t// FetchLoopOutSwaps returns all swaps currently in the store.\n\tFetchLoopOutSwaps(ctx context.Context) ([]*LoopOut, error)\n\n\t// FetchLoopOutSwap returns the loop out swap with the given hash.\n\tFetchLoopOutSwap(ctx context.Context, hash lntypes.Hash) (*LoopOut, error)\n\n\t// CreateLoopOut adds an initiated swap to the store.\n\tCreateLoopOut(ctx context.Context, hash lntypes.Hash,\n\t\tswap *LoopOutContract) error\n\n\t// BatchCreateLoopOut creates a batch of loop out swaps to the store.\n\tBatchCreateLoopOut(ctx context.Context,\n\t\tswaps map[lntypes.Hash]*LoopOutContract) error\n\n\t// UpdateLoopOut stores a new event for a target loop out swap. This\n\t// appends to the event log for a particular swap as it goes through\n\t// the various stages in its lifetime.\n\tUpdateLoopOut(ctx context.Context, hash lntypes.Hash, time time.Time,\n\t\tstate SwapStateData) error\n\n\t// UpdateLoopOutAssetInfo updates the asset information for a loop out\n\t// swap.\n\tUpdateLoopOutAssetInfo(ctx context.Context, hash lntypes.Hash,\n\t\tasset *LoopOutAssetSwap) error\n\n\t// FetchLoopInSwaps returns all swaps currently in the store.\n\tFetchLoopInSwaps(ctx context.Context) ([]*LoopIn, error)\n\n\t// CreateLoopIn adds an initiated swap to the store.\n\tCreateLoopIn(ctx context.Context, hash lntypes.Hash,\n\t\tswap *LoopInContract) error\n\n\t// BatchCreateLoopIn creates a batch of loop in swaps to the store.\n\tBatchCreateLoopIn(ctx context.Context,\n\t\tswaps map[lntypes.Hash]*LoopInContract) error\n\n\t// UpdateLoopIn stores a new event for a target loop in swap. This\n\t// appends to the event log for a particular swap as it goes through\n\t// the various stages in its lifetime.\n\tUpdateLoopIn(ctx context.Context, hash lntypes.Hash, time time.Time,\n\t\tstate SwapStateData) error\n\n\t// BatchInsertUpdate inserts batch of swap updates to the store.\n\tBatchInsertUpdate(ctx context.Context,\n\t\tupdateData map[lntypes.Hash][]BatchInsertUpdateData) error\n\n\t// PutLiquidityParams writes the serialized `manager.Parameters` bytes\n\t// into the bucket.\n\t//\n\t// NOTE: it's the caller's responsibility to encode the param. Atm,\n\t// it's encoding using the proto package's `Marshal` method.\n\tPutLiquidityParams(ctx context.Context, params []byte) error\n\n\t// FetchLiquidityParams reads the serialized `manager.Parameters` bytes\n\t// from the bucket.\n\t//\n\t// NOTE: it's the caller's responsibility to decode the param. Atm,\n\t// it's decoding using the proto package's `Unmarshal` method.\n\tFetchLiquidityParams(ctx context.Context) ([]byte, error)\n\n\t// BatchUpdateLoopOutSwapCosts updates the swap costs for a batch of\n\t// loop out swaps.\n\tBatchUpdateLoopOutSwapCosts(ctx context.Context,\n\t\tswaps map[lntypes.Hash]SwapCost) error\n\n\t// HasMigration returns true if the migration with the given ID has\n\t// been done.\n\tHasMigration(ctx context.Context, migrationID string) (bool, error)\n\n\t// SetMigration marks the migration with the given ID as done.\n\tSetMigration(ctx context.Context, migrationID string) error\n\n\t// Close closes the underlying database.\n\tClose() error\n}\n```\nSwapStore is the primary database interface used by the loopd system. It houses information for all pending completed/failed swaps.\n\n```go\ntype TestPgFixture struct {\n\t// contains filtered or unexported fields\n}\n```\nTestPgFixture is a test fixture that starts a Postgres 11 instance in a docker container.\n\n```go\nfunc NewTestPgFixture(t *testing.T, expiry time.Duration) *TestPgFixture\n```\nNewTestPgFixture constructs a new TestPgFixture starting up a docker container running Postgres 11. The started container will expire in after the passed duration.\n\n```go\nfunc (f *TestPgFixture) ClearDB(t *testing.T)\n```\nClearDB clears the database.\n\n```go\nfunc (f *TestPgFixture) GetConfig() *PostgresConfig\n```\nGetConfig returns the full config of the Postgres node.\n\n```go\nfunc (f *TestPgFixture) GetDSN() string\n```\nGetDSN returns the DSN (Data Source Name) for the started Postgres node.\n\n```go\nfunc (f *TestPgFixture) TearDown(t *testing.T)\n```\nTearDown stops the underlying docker container.\n\n```go\ntype TxOptions interface {\n\t// ReadOnly returns true if the transaction should be read only.\n\tReadOnly() bool\n}\n```\nTxOptions represents a set of options one can use to control what type of database transaction is created. Transaction can whether be read or write.\n\n```go\ntype TypedStore[Q any] struct {\n\tBatchedQuerier\n}\n```\nTypedStore is similar to BaseDB but provides parameterized ExecTx. It is used in other packages expecting ExecTx operating on subset of methods.\n\n```go\nfunc NewTypedStore[Q any](db BatchedQuerier) *TypedStore[Q]\n```\nNewTypedStore wraps a db, replacing generic ExecTx method with the typed one.\n\n```go\nfunc (s *TypedStore[Q]) ExecTx(ctx context.Context,\n\ttxOptions TxOptions, txBody func(Q) error) error\n```\nExecTx 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 to allow the caller to specify if a transaction is read-only.\n\n","path":"github.com/lightninglabs/loop/loopdb","name":"loopdb","synopsis":"","isRedistributable":true}
