@@ -16,6 +16,7 @@ module BtcLsp.Storage.Model.SwapIntoLn
1616 getByUuidSql ,
1717 getByFundAddressSql ,
1818 withLockedRowSql ,
19+ getSwapsInPsbtThreadSql ,
1920 UtxoInfo (.. ),
2021 SwapInfo (.. ),
2122 )
@@ -25,6 +26,7 @@ import BtcLsp.Import hiding (Storage (..))
2526import qualified BtcLsp.Import.Psql as Psql
2627import qualified BtcLsp.Math.Swap as Math
2728import qualified BtcLsp.Storage.Util as Util
29+ import qualified LndClient as Lnd
2830
2931createIgnoreSql ::
3032 ( MonadIO m
@@ -58,6 +60,7 @@ createIgnoreSql userEnt fundAddr feeAndChangeAddr refundAddr expAt chanPrivacy =
5860 swapIntoLnFeeMiner = Money 0 ,
5961 swapIntoLnStatus = SwapWaitingFundChain ,
6062 swapIntoLnPrivacy = chanPrivacy,
63+ swapIntoLnPsbtPendingChanId = Nothing ,
6164 swapIntoLnExpiresAt = expAt,
6265 swapIntoLnInsertedAt = ct,
6366 swapIntoLnUpdatedAt = ct
@@ -126,16 +129,19 @@ updateInPsbtThreadSql ::
126129 ( MonadIO m
127130 ) =>
128131 SwapIntoLnId ->
132+ Lnd. PendingChannelId ->
129133 ReaderT Psql. SqlBackend m ()
130- updateInPsbtThreadSql id0 = do
134+ updateInPsbtThreadSql id0 pcid = do
131135 ct <- getCurrentTime
132136 Psql. update $ \ row -> do
133137 Psql. set
134138 row
135139 [ SwapIntoLnStatus
136140 Psql. =. Psql. val SwapInPsbtThread ,
137141 SwapIntoLnUpdatedAt
138- Psql. =. Psql. val ct
142+ Psql. =. Psql. val ct,
143+ SwapIntoLnPsbtPendingChanId
144+ Psql. =. Psql. val (Just pcid)
139145 ]
140146 Psql. where_ $
141147 ( row Psql. ^. SwapIntoLnId
@@ -158,7 +164,9 @@ updateRevertInPsbtThreadSql id0 = do
158164 [ SwapIntoLnStatus
159165 Psql. =. Psql. val SwapWaitingPeer ,
160166 SwapIntoLnUpdatedAt
161- Psql. =. Psql. val ct
167+ Psql. =. Psql. val ct,
168+ SwapIntoLnPsbtPendingChanId
169+ Psql. =. Psql. val Nothing
162170 ]
163171 Psql. where_ $
164172 ( row Psql. ^. SwapIntoLnId
@@ -180,13 +188,32 @@ updateRevertAllInPsbtThreadSql = do
180188 [ SwapIntoLnStatus
181189 Psql. =. Psql. val SwapWaitingPeer ,
182190 SwapIntoLnUpdatedAt
183- Psql. =. Psql. val ct
191+ Psql. =. Psql. val ct,
192+ SwapIntoLnPsbtPendingChanId
193+ Psql. =. Psql. val Nothing
184194 ]
185195 Psql. where_
186196 ( row Psql. ^. SwapIntoLnStatus
187197 Psql. ==. Psql. val SwapInPsbtThread
188198 )
189199
200+ getSwapsInPsbtThreadSql ::
201+ ( MonadIO m
202+ ) =>
203+ ReaderT
204+ Psql. SqlBackend
205+ m
206+ [Entity SwapIntoLn ]
207+ getSwapsInPsbtThreadSql =
208+ Psql. select $
209+ Psql. from $ \ swap -> do
210+ Psql. locking Psql. ForUpdate
211+ Psql. where_
212+ ( swap Psql. ^. SwapIntoLnStatus
213+ Psql. ==. Psql. val SwapInPsbtThread
214+ )
215+ pure swap
216+
190217updateExpiredSql ::
191218 ( MonadIO m ,
192219 KatipContext m
0 commit comments