staticaddr/sql_store: Add fetching loop in by hash

This commit is contained in:
sputn1ck 2024-11-14 15:04:18 +01:00 committed by Slyghtning
parent 216aebbbbf
commit 409b2e9929
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
2 changed files with 28 additions and 0 deletions

View file

@ -64,6 +64,10 @@ type StaticAddressLoopInStore interface {
// IsStored checks if the loop-in is already stored in the database.
IsStored(ctx context.Context, swapHash lntypes.Hash) (bool, error)
// GetLoopInByHash returns the loop-in swap with the given hash.
GetLoopInByHash(ctx context.Context, swapHash lntypes.Hash) (
*StaticAddressLoopIn, error)
}
type QuoteGetter interface {

View file

@ -100,6 +100,30 @@ func NewSqlStore(db BaseDB, clock clock.Clock,
}
}
// GetLoopInByHash returns the loop-in swap with the given hash.
func (s *SqlStore) GetLoopInByHash(ctx context.Context,
swapHash lntypes.Hash) (*StaticAddressLoopIn, error) {
var (
err error
row sqlc.GetStaticAddressLoopInSwapRow
updates []sqlc.StaticAddressSwapUpdate
)
row, err = s.baseDB.GetStaticAddressLoopInSwap(ctx, swapHash[:])
if err != nil {
return nil, err
}
updates, err = s.baseDB.GetLoopInSwapUpdates(ctx, swapHash[:])
if err != nil {
return nil, err
}
return toStaticAddressLoopIn(
ctx, s.network, row, updates,
)
}
// GetStaticAddressLoopInSwapsByStates returns all static address loop-ins from
// the db that are in the given states.
func (s *SqlStore) GetStaticAddressLoopInSwapsByStates(ctx context.Context,