Skip to content

Commit 409b2e9

Browse files
sputn1ckhieblmi
authored andcommitted
staticaddr/sql_store: Add fetching loop in by hash
1 parent 216aebb commit 409b2e9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

staticaddr/loopin/interface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ type StaticAddressLoopInStore interface {
6464

6565
// IsStored checks if the loop-in is already stored in the database.
6666
IsStored(ctx context.Context, swapHash lntypes.Hash) (bool, error)
67+
68+
// GetLoopInByHash returns the loop-in swap with the given hash.
69+
GetLoopInByHash(ctx context.Context, swapHash lntypes.Hash) (
70+
*StaticAddressLoopIn, error)
6771
}
6872

6973
type QuoteGetter interface {

staticaddr/loopin/sql_store.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ func NewSqlStore(db BaseDB, clock clock.Clock,
100100
}
101101
}
102102

103+
// GetLoopInByHash returns the loop-in swap with the given hash.
104+
func (s *SqlStore) GetLoopInByHash(ctx context.Context,
105+
swapHash lntypes.Hash) (*StaticAddressLoopIn, error) {
106+
107+
var (
108+
err error
109+
row sqlc.GetStaticAddressLoopInSwapRow
110+
updates []sqlc.StaticAddressSwapUpdate
111+
)
112+
row, err = s.baseDB.GetStaticAddressLoopInSwap(ctx, swapHash[:])
113+
if err != nil {
114+
return nil, err
115+
}
116+
117+
updates, err = s.baseDB.GetLoopInSwapUpdates(ctx, swapHash[:])
118+
if err != nil {
119+
return nil, err
120+
}
121+
122+
return toStaticAddressLoopIn(
123+
ctx, s.network, row, updates,
124+
)
125+
}
126+
103127
// GetStaticAddressLoopInSwapsByStates returns all static address loop-ins from
104128
// the db that are in the given states.
105129
func (s *SqlStore) GetStaticAddressLoopInSwapsByStates(ctx context.Context,

0 commit comments

Comments
 (0)