@@ -173,8 +173,6 @@ func NewService(
173
173
sweeper : newSweeper (
174
174
wallet , repoManager , builder , scheduler , noteUriPrefix ,
175
175
),
176
- eventsCh : make (chan []domain.Event ),
177
- transactionEventsCh : make (chan TransactionEvent ),
178
176
boardingExitDelay : boardingExitDelay ,
179
177
operatorPrvkey : operatorSigningKey ,
180
178
operatorPubkey : operatorSigningKey .PubKey (),
@@ -186,7 +184,9 @@ func NewService(
186
184
vtxoMaxAmount : vtxoMaxAmount ,
187
185
vtxoMinSettlementAmount : vtxoMinSettlementAmount ,
188
186
vtxoMinOffchainTxAmount : vtxoMinOffchainTxAmount ,
189
- indexerTxEventsCh : make (chan TransactionEvent ),
187
+ eventsCh : make (chan []domain.Event , 64 ),
188
+ transactionEventsCh : make (chan TransactionEvent , 64 ),
189
+ indexerTxEventsCh : make (chan TransactionEvent , 64 ),
190
190
stop : cancel ,
191
191
ctx : ctx ,
192
192
wg : & sync.WaitGroup {},
@@ -203,32 +203,47 @@ func NewService(
203
203
repoManager .Events ().RegisterEventsHandler (
204
204
domain .RoundTopic , func (events []domain.Event ) {
205
205
round := domain .NewRoundFromEvents (events )
206
-
207
206
go svc .propagateEvents (round )
208
207
208
+ lastEvent := events [len (events )- 1 ]
209
+ if lastEvent .GetType () == domain .EventTypeBatchSwept {
210
+ batchSweptEvent := lastEvent .(domain.BatchSwept )
211
+ sweptVtxosOutpoints := append (
212
+ batchSweptEvent .LeafVtxos ,
213
+ batchSweptEvent .PreconfirmedVtxos ... )
214
+ sweptVtxos , err := svc .repoManager .Vtxos ().GetVtxos (ctx , sweptVtxosOutpoints )
215
+ if err != nil {
216
+ log .WithError (err ).Warn ("failed to get swept vtxos" )
217
+ return
218
+ }
219
+ go svc .stopWatchingVtxos (sweptVtxos )
220
+
221
+ // sweep tx event
222
+ txEvent := TransactionEvent {
223
+ TxData : TxData {Tx : batchSweptEvent .Tx , Txid : batchSweptEvent .Txid },
224
+ Type : SweepTxType ,
225
+ SweptVtxos : sweptVtxos ,
226
+ }
227
+ svc .propagateTransactionEvent (txEvent )
228
+ return
229
+ }
230
+
209
231
if ! round .IsEnded () {
210
232
return
211
233
}
212
234
213
235
spentVtxos := svc .getSpentVtxos (round .Intents )
214
236
newVtxos := getNewVtxosFromRound (round )
215
237
216
- go func () {
217
- svc .transactionEventsCh <- TransactionEvent {
218
- TxData : TxData {Tx : round .CommitmentTx , Txid : round .CommitmentTxid },
219
- Type : CommitmentTxType ,
220
- SpentVtxos : spentVtxos ,
221
- SpendableVtxos : newVtxos ,
222
- }
223
- }()
224
- go func () {
225
- svc .indexerTxEventsCh <- TransactionEvent {
226
- TxData : TxData {Tx : round .CommitmentTx , Txid : round .CommitmentTxid },
227
- Type : CommitmentTxType ,
228
- SpentVtxos : spentVtxos ,
229
- SpendableVtxos : newVtxos ,
230
- }
231
- }()
238
+ // commitment tx event
239
+ txEvent := TransactionEvent {
240
+ TxData : TxData {Tx : round .CommitmentTx , Txid : round .CommitmentTxid },
241
+ Type : CommitmentTxType ,
242
+ SpentVtxos : spentVtxos ,
243
+ SpendableVtxos : newVtxos ,
244
+ }
245
+
246
+ svc .propagateTransactionEvent (txEvent )
232
247
233
248
go func () {
234
249
if err := svc .startWatchingVtxos (newVtxos ); err != nil {
@@ -271,24 +286,16 @@ func NewService(
271
286
}
272
287
}
273
288
274
- go func () {
275
- svc .transactionEventsCh <- TransactionEvent {
276
- TxData : TxData {Txid : txid , Tx : offchainTx .ArkTx },
277
- Type : ArkTxType ,
278
- SpentVtxos : spentVtxos ,
279
- SpendableVtxos : newVtxos ,
280
- CheckpointTxs : checkpointTxsByOutpoint ,
281
- }
282
- }()
283
- go func () {
284
- svc .indexerTxEventsCh <- TransactionEvent {
285
- TxData : TxData {Txid : txid , Tx : offchainTx .ArkTx },
286
- Type : ArkTxType ,
287
- SpentVtxos : spentVtxos ,
288
- SpendableVtxos : newVtxos ,
289
- CheckpointTxs : checkpointTxsByOutpoint ,
290
- }
291
- }()
289
+ // ark tx event
290
+ txEvent := TransactionEvent {
291
+ TxData : TxData {Txid : txid , Tx : offchainTx .ArkTx },
292
+ Type : ArkTxType ,
293
+ SpentVtxos : spentVtxos ,
294
+ SpendableVtxos : newVtxos ,
295
+ CheckpointTxs : checkpointTxsByOutpoint ,
296
+ }
297
+
298
+ svc .propagateTransactionEvent (txEvent )
292
299
293
300
go func () {
294
301
if err := svc .startWatchingVtxos (newVtxos ); err != nil {
@@ -1163,7 +1170,7 @@ func (s *service) GetTxEventsChannel(ctx context.Context) <-chan TransactionEven
1163
1170
return s .transactionEventsCh
1164
1171
}
1165
1172
1166
- // TODO remove this in v7
1173
+ // TODO remove this when detaching the indexer service
1167
1174
func (s * service ) GetIndexerTxChannel (ctx context.Context ) <- chan TransactionEvent {
1168
1175
return s .indexerTxEventsCh
1169
1176
}
@@ -2481,3 +2488,13 @@ func (s *service) verifyForfeitTxsSigs(txs []string) error {
2481
2488
return nil
2482
2489
}
2483
2490
}
2491
+
2492
+ // propagateTransactionEvent propagates the transaction event to the indexer and the transaction events channels
2493
+ func (s * service ) propagateTransactionEvent (event TransactionEvent ) {
2494
+ go func () {
2495
+ s .indexerTxEventsCh <- event
2496
+ }()
2497
+ go func () {
2498
+ s .transactionEventsCh <- event
2499
+ }()
2500
+ }
0 commit comments