-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmessages.go
More file actions
782 lines (611 loc) · 26.2 KB
/
Copy pathmessages.go
File metadata and controls
782 lines (611 loc) · 26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
package chainsource
import (
"iter"
"github.com/btcsuite/btcd/btcutil/v2"
"github.com/btcsuite/btcd/chainhash/v2"
"github.com/btcsuite/btcd/wire/v2"
"github.com/lightninglabs/wavelength/baselib/actor"
fn "github.com/lightningnetwork/lnd/fn/v2"
)
// ChainSourceMsg is the sealed interface for all messages that can be sent to
// the ChainSource actor. The sealed interface pattern ensures type safety by
// preventing external packages from implementing the interface.
type ChainSourceMsg interface {
actor.Message
chainSourceMsgSealed()
}
// ChainSourceResp is the sealed interface for all response messages from the
// ChainSource actor.
type ChainSourceResp interface {
actor.Message
chainSourceRespSealed()
}
// FeeEstimateRequest requests a fee estimation for a given confirmation
// target. The fee estimator will provide the satoshis per vbyte needed to
// confirm within the target number of blocks.
type FeeEstimateRequest struct {
actor.BaseMessage
// TargetConf is the desired number of blocks within which the
// transaction should confirm.
TargetConf uint32
}
// MessageType returns the message type identifier for logging and debugging.
func (m *FeeEstimateRequest) MessageType() string {
return "FeeEstimateRequest"
}
// chainSourceMsgSealed implements the sealed ChainSourceMsg interface.
func (m *FeeEstimateRequest) chainSourceMsgSealed() {}
// FeeEstimateResponse contains the estimated fee rate in satoshis per vbyte
// for the requested confirmation target.
type FeeEstimateResponse struct {
actor.BaseMessage
// SatPerVByte is the estimated fee rate in satoshis per virtual byte.
SatPerVByte btcutil.Amount
}
// MessageType returns the message type identifier for logging and debugging.
func (m *FeeEstimateResponse) MessageType() string {
return "FeeEstimateResponse"
}
// chainSourceRespSealed implements the sealed ChainSourceResp interface.
func (m *FeeEstimateResponse) chainSourceRespSealed() {}
// BestHeightRequest requests the current best known block height and hash
// from the blockchain backend.
type BestHeightRequest struct {
actor.BaseMessage
}
// MessageType returns the message type identifier for logging and debugging.
func (m *BestHeightRequest) MessageType() string {
return "BestHeightRequest"
}
// chainSourceMsgSealed implements the sealed ChainSourceMsg interface.
func (m *BestHeightRequest) chainSourceMsgSealed() {}
// BestHeightResponse contains the current best block height and hash from the
// blockchain.
type BestHeightResponse struct {
actor.BaseMessage
// Height is the current best block height.
Height int32
// Hash is the current best block hash.
Hash chainhash.Hash
}
// MessageType returns the message type identifier for logging and debugging.
func (m *BestHeightResponse) MessageType() string {
return "BestHeightResponse"
}
// chainSourceRespSealed implements the sealed ChainSourceResp interface.
func (m *BestHeightResponse) chainSourceRespSealed() {}
// TestMempoolAcceptRequest requests a test of whether one or more
// transactions would be accepted by the mempool without actually
// broadcasting them. Passing more than one transaction asks the backend
// to evaluate the set as a package (per Bitcoin Core's
// testmempoolaccept RPC).
type TestMempoolAcceptRequest struct {
actor.BaseMessage
// Txs are the transactions to test for mempool acceptance. One
// transaction performs a single-tx test; multiple transactions
// request a package test.
Txs []*wire.MsgTx
}
// MessageType returns the message type identifier for logging and debugging.
func (m *TestMempoolAcceptRequest) MessageType() string {
return "TestMempoolAcceptRequest"
}
// chainSourceMsgSealed implements the sealed ChainSourceMsg interface.
func (m *TestMempoolAcceptRequest) chainSourceMsgSealed() {}
// TestMempoolAcceptResponse contains the per-transaction results of a
// mempool acceptance test.
type TestMempoolAcceptResponse struct {
actor.BaseMessage
// Results has one entry per tx in the original request, in the
// same order.
Results []MempoolAcceptResult
}
// MessageType returns the message type identifier for logging and debugging.
func (m *TestMempoolAcceptResponse) MessageType() string {
return "TestMempoolAcceptResponse"
}
// chainSourceRespSealed implements the sealed ChainSourceResp interface.
func (m *TestMempoolAcceptResponse) chainSourceRespSealed() {}
// BroadcastTxRequest requests that a transaction be broadcast to the network.
// An optional label can be provided for wallet tracking purposes.
type BroadcastTxRequest struct {
actor.BaseMessage
// Tx is the transaction to broadcast.
Tx *wire.MsgTx
// Label is an optional label for tracking this transaction in the
// wallet. Can be empty.
Label string
}
// MessageType returns the message type identifier for logging and debugging.
func (m *BroadcastTxRequest) MessageType() string {
return "BroadcastTxRequest"
}
// chainSourceMsgSealed implements the sealed ChainSourceMsg interface.
func (m *BroadcastTxRequest) chainSourceMsgSealed() {}
// BroadcastTxResponse contains the transaction ID of the successfully
// broadcast transaction.
type BroadcastTxResponse struct {
actor.BaseMessage
// Txid is the transaction ID of the broadcast transaction.
Txid chainhash.Hash
}
// MessageType returns the message type identifier for logging and debugging.
func (m *BroadcastTxResponse) MessageType() string {
return "BroadcastTxResponse"
}
// chainSourceRespSealed implements the sealed ChainSourceResp interface.
func (m *BroadcastTxResponse) chainSourceRespSealed() {}
// RemoveTxRequest asks the backend to remove a previously broadcast
// transaction from the wallet so it stops being rebroadcast. It is a no-op on
// backends that do not implement the optional TxRemover capability
// (wavelength#609).
type RemoveTxRequest struct {
actor.BaseMessage
// Txid is the hash of the transaction to remove.
Txid chainhash.Hash
}
// MessageType returns the message type identifier for logging and debugging.
func (m *RemoveTxRequest) MessageType() string {
return "RemoveTxRequest"
}
// chainSourceMsgSealed implements the sealed ChainSourceMsg interface.
func (m *RemoveTxRequest) chainSourceMsgSealed() {}
// RemoveTxResponse acknowledges a RemoveTxRequest.
type RemoveTxResponse struct {
actor.BaseMessage
// Txid is the hash of the transaction that was removed (or the no-op
// target on a backend without the TxRemover capability).
Txid chainhash.Hash
}
// MessageType returns the message type identifier for logging and debugging.
func (m *RemoveTxResponse) MessageType() string {
return "RemoveTxResponse"
}
// chainSourceRespSealed implements the sealed ChainSourceResp interface.
func (m *RemoveTxResponse) chainSourceRespSealed() {}
// SubmitPackageRequest requests atomic submission of a parent+child
// transaction package. The parents must be in dependency order and the
// child pays the package fee.
type SubmitPackageRequest struct {
actor.BaseMessage
// Parents is the list of parent transactions in dependency order.
Parents []*wire.MsgTx
// Child is the fee-paying child transaction.
Child *wire.MsgTx
}
// MessageType returns the message type identifier for logging and debugging.
func (m *SubmitPackageRequest) MessageType() string {
return "SubmitPackageRequest"
}
// chainSourceMsgSealed implements the sealed ChainSourceMsg interface.
func (m *SubmitPackageRequest) chainSourceMsgSealed() {}
// SubmitPackageResponse indicates successful package submission.
type SubmitPackageResponse struct {
actor.BaseMessage
}
// MessageType returns the message type identifier for logging and debugging.
func (m *SubmitPackageResponse) MessageType() string {
return "SubmitPackageResponse"
}
// chainSourceRespSealed implements the sealed ChainSourceResp interface.
func (m *SubmitPackageResponse) chainSourceRespSealed() {}
// ConfMsg is the sealed interface for all messages that can be sent to a
// ConfActor sub-actor for confirmation monitoring.
type ConfMsg interface {
actor.Message
confMsgSealed()
}
// ConfResp is the sealed interface for all response messages from a ConfActor.
type ConfResp interface {
actor.Message
confRespSealed()
}
// RegisterConfRequest requests monitoring of a transaction for a specified
// number of confirmations. The actor supports dual-mode operation: if
// NotifyActor is None, a Future is returned for blocking await; if NotifyActor
// is Some, events are sent to that actor asynchronously.
type RegisterConfRequest struct {
actor.BaseMessage
// CallerID is a unique identifier provided by the caller. This is used
// to construct the service key for the dedicated actor, enabling
// deterministic cancellation.
CallerID string
// Txid is the transaction ID to monitor. Can be nil to match by script
// only.
Txid *chainhash.Hash
// PkScript is the public key script to monitor.
PkScript []byte
// TargetConfs is the number of confirmations to wait for.
TargetConfs uint32
// HeightHint is an optional height hint indicating the earliest block
// that could contain the transaction. This is an optimization for
// light clients. Set to 0 if unknown.
HeightHint uint32
// IncludeBlock indicates whether the confirmation event should include
// the full block containing the transaction. This is needed for
// constructing merkle proofs. When true, the ConfirmationEvent.Block
// field will be populated.
IncludeBlock bool
// NotifyActor is an optional actor reference. If Some, confirmation
// events will be sent to this actor asynchronously. If None, a Future
// is returned in the response for blocking await.
NotifyActor fn.Option[actor.TellOnlyRef[ConfirmationEvent]]
// NotifyReorged is an optional actor reference for negative
// confirmation events. It is only used in async actor mode.
NotifyReorged fn.Option[actor.TellOnlyRef[ConfReorgedEvent]]
// NotifyDone is an optional actor reference notified when the
// confirmation watch is beyond the backend's reorg tracking horizon.
// It is only used in async actor mode.
NotifyDone fn.Option[actor.TellOnlyRef[ConfDoneEvent]]
}
// MessageType returns the message type identifier for logging and debugging.
func (m *RegisterConfRequest) MessageType() string {
return "RegisterConfRequest"
}
// chainSourceMsgSealed implements the ChainSourceMsg interface so confirmation
// requests can be routed through the ChainSource actor.
func (m *RegisterConfRequest) chainSourceMsgSealed() {}
// confMsgSealed implements the sealed ConfMsg interface.
func (m *RegisterConfRequest) confMsgSealed() {}
// RegisterConfResponse contains either a Future for blocking on confirmation
// or nothing if actor-mode notification was requested. The subscription can
// be cancelled later using UnregisterConfRequest with the original CallerID.
type RegisterConfResponse struct {
actor.BaseMessage
// Future provides a blocking await interface for confirmation. Only
// present if NotifyActor was None in the request.
Future actor.Future[ConfirmationEvent]
}
// MessageType returns the message type identifier for logging and debugging.
func (m *RegisterConfResponse) MessageType() string {
return "RegisterConfResponse"
}
// confRespSealed implements the sealed ConfResp interface.
func (m *RegisterConfResponse) confRespSealed() {}
// chainSourceRespSealed implements the ChainSourceResp interface so responses
// can be returned via the ChainSource actor.
func (m *RegisterConfResponse) chainSourceRespSealed() {}
// ConfirmationEvent is sent when a monitored transaction reaches the target
// number of confirmations. This can be delivered either via a Future (for
// blocking await) or by sending to a registered actor (for async notification).
type ConfirmationEvent struct {
actor.BaseMessage
// Txid is the transaction ID.
Txid chainhash.Hash
// BlockHeight is the height of the block containing the transaction.
BlockHeight int32
// BlockHash is the hash of the block containing the transaction.
BlockHash chainhash.Hash
// NumConfs is the actual number of confirmations at the time of this
// event.
NumConfs uint32
// Tx is the confirmed transaction. This allows consumers to inspect
// transaction outputs without making additional chain queries.
Tx *wire.MsgTx
// Block is the full block containing the confirmed transaction. This
// is only populated when the confirmation was registered with
// IncludeBlock=true. Used for constructing merkle proofs.
Block *wire.MsgBlock
}
// MessageType returns the message type identifier for logging and debugging.
func (m ConfirmationEvent) MessageType() string {
return "ConfirmationEvent"
}
// ConfReorgedEvent is sent when a previously reported confirmation is
// reorged out of the canonical chain. After receiving this event a consumer
// should consider the prior confirmation no longer valid; if the transaction
// re-confirms on the new canonical chain a fresh ConfirmationEvent will
// follow on the same registration.
//
// No block hash, height, or reorg depth is carried because the lndclient
// gRPC transport does not preserve that information and we do not want to
// expose fields that are always zero in production. Consumers that need to
// invalidate cached block metadata should match on Txid and use the data
// from the most recent ConfirmationEvent they observed on this watch.
type ConfReorgedEvent struct {
actor.BaseMessage
// Txid is the transaction ID whose confirmation was reorged. This
// matches the Txid carried on the originating ConfirmationEvent.
Txid chainhash.Hash
}
// MessageType returns the message type identifier for logging and debugging.
func (m ConfReorgedEvent) MessageType() string {
return "ConfReorgedEvent"
}
// ConfDoneEvent is sent when a confirmation watch has matured past the
// backend's reorg-safety depth and will receive no further events.
// Consumers may use this signal to drop any reorg-recovery bookkeeping they
// were holding for the registration. Not all backends synthesize this
// event; consumers must treat its absence as a normal operating condition
// rather than an error.
type ConfDoneEvent struct {
actor.BaseMessage
// Txid is the transaction ID whose registration matured.
Txid chainhash.Hash
}
// MessageType returns the message type identifier for logging and debugging.
func (m ConfDoneEvent) MessageType() string {
return "ConfDoneEvent"
}
// UnregisterConfRequest requests cancellation of a confirmation subscription.
// The ChainSource actor uses the fields to construct the service key and
// cancel the dedicated actor.
type UnregisterConfRequest struct {
actor.BaseMessage
// CallerID is the unique identifier provided in the original
// RegisterConfRequest. Required to reconstruct the service key.
CallerID string
// Txid is the transaction ID being monitored. Can be nil to match by
// script only (must match the original registration).
Txid *chainhash.Hash
// PkScript is the public key script being monitored. Required if Txid
// is nil.
PkScript []byte
// TargetConfs is the number of confirmations from the original
// request. Required to reconstruct the service key.
TargetConfs uint32
}
// MessageType returns the message type identifier for logging and debugging.
func (m *UnregisterConfRequest) MessageType() string {
return "UnregisterConfRequest"
}
// chainSourceMsgSealed implements the ChainSourceMsg interface.
func (m *UnregisterConfRequest) chainSourceMsgSealed() {}
// UnregisterConfResponse indicates successful cancellation.
type UnregisterConfResponse struct {
actor.BaseMessage
}
// MessageType returns the message type identifier for logging and debugging.
func (m *UnregisterConfResponse) MessageType() string {
return "UnregisterConfResponse"
}
// chainSourceRespSealed implements the ChainSourceResp interface.
func (m *UnregisterConfResponse) chainSourceRespSealed() {}
// SpendMsg is the sealed interface for all messages that can be sent to a
// SpendActor sub-actor for spend monitoring.
type SpendMsg interface {
actor.Message
spendMsgSealed()
}
// SpendResp is the sealed interface for all response messages from a
// SpendActor.
type SpendResp interface {
actor.Message
spendRespSealed()
}
// RegisterSpendRequest requests monitoring of an outpoint for spend events.
// The actor supports dual-mode operation similar to RegisterConfRequest.
type RegisterSpendRequest struct {
actor.BaseMessage
// CallerID is a unique identifier provided by the caller. This is used
// to construct the service key for the dedicated actor, enabling
// deterministic cancellation.
CallerID string
// Outpoint is the transaction output to monitor for spends. Can be nil
// to match by script only.
Outpoint *wire.OutPoint
// PkScript is the public key script of the output to monitor.
PkScript []byte
// HeightHint is an optional height hint indicating the earliest block
// that could contain a spending transaction. Set to 0 if unknown.
HeightHint uint32
// NotifyActor is an optional actor reference. If Some, spend events
// will be sent to this actor asynchronously. If None, a Future is
// returned for blocking await.
NotifyActor fn.Option[actor.TellOnlyRef[SpendEvent]]
// NotifyReorged is an optional actor reference for spend reorg events.
// It is only used in async actor mode.
NotifyReorged fn.Option[actor.TellOnlyRef[SpendReorgedEvent]]
// NotifyDone is an optional actor reference notified when the spend
// watch is beyond the backend's reorg tracking horizon. It is only used
// in async actor mode.
NotifyDone fn.Option[actor.TellOnlyRef[SpendDoneEvent]]
}
// MessageType returns the message type identifier for logging and debugging.
func (m *RegisterSpendRequest) MessageType() string {
return "RegisterSpendRequest"
}
// chainSourceMsgSealed implements the ChainSourceMsg interface.
func (m *RegisterSpendRequest) chainSourceMsgSealed() {}
// spendMsgSealed implements the sealed SpendMsg interface.
func (m *RegisterSpendRequest) spendMsgSealed() {}
// RegisterSpendResponse contains either a Future for blocking on spend
// notification or nothing if actor-mode notification was requested. The
// subscription can be cancelled later using UnregisterSpendRequest with the
// original CallerID.
type RegisterSpendResponse struct {
actor.BaseMessage
// Future provides a blocking await interface for spend notification.
// Only present if NotifyActor was None in the request.
Future actor.Future[SpendEvent]
}
// MessageType returns the message type identifier for logging and debugging.
func (m *RegisterSpendResponse) MessageType() string {
return "RegisterSpendResponse"
}
// spendRespSealed implements the sealed SpendResp interface.
func (m *RegisterSpendResponse) spendRespSealed() {}
// chainSourceRespSealed implements the ChainSourceResp interface.
func (m *RegisterSpendResponse) chainSourceRespSealed() {}
// SpendEvent is sent when a monitored outpoint is spent in a transaction with
// at least one confirmation.
type SpendEvent struct {
actor.BaseMessage
// Outpoint is the output that was spent.
Outpoint wire.OutPoint
// SpendingTxid is the transaction ID of the spending transaction.
SpendingTxid chainhash.Hash
// SpendingTx is the full spending transaction.
SpendingTx *wire.MsgTx
// SpenderInputIndex is the input index within the spending transaction
// that consumes the monitored outpoint.
SpenderInputIndex uint32
// SpendingHeight is the block height where the spending transaction
// was confirmed.
SpendingHeight int32
}
// MessageType returns the message type identifier for logging and debugging.
func (m SpendEvent) MessageType() string {
return "SpendEvent"
}
// SpendReorgedEvent is sent when a previously reported spend is reorged out
// of the canonical chain. After receiving this event a consumer should
// consider the prior spend no longer valid; if the outpoint is re-spent on
// the new canonical chain a fresh SpendEvent will follow on the same
// registration.
//
// No spending txid, height, or block hash is carried because the lndclient
// gRPC transport does not preserve that information and we do not want to
// expose fields that are always zero in production. Consumers that need to
// invalidate cached spending metadata should match on Outpoint and use the
// data from the most recent SpendEvent they observed on this watch.
type SpendReorgedEvent struct {
actor.BaseMessage
// Outpoint is the output whose spend was reorged.
Outpoint wire.OutPoint
}
// MessageType returns the message type identifier for logging and debugging.
func (m SpendReorgedEvent) MessageType() string {
return "SpendReorgedEvent"
}
// SpendDoneEvent is sent when a spend watch has matured past the backend's
// reorg-safety depth and will receive no further events. Not all backends
// synthesize this event; consumers must treat its absence as a normal
// operating condition rather than an error.
type SpendDoneEvent struct {
actor.BaseMessage
// Outpoint is the output whose spend registration matured.
Outpoint wire.OutPoint
}
// MessageType returns the message type identifier for logging and debugging.
func (m SpendDoneEvent) MessageType() string {
return "SpendDoneEvent"
}
// UnregisterSpendRequest requests cancellation of a spend subscription.
// The ChainSource actor uses the fields to construct the service key and
// cancel the dedicated actor.
type UnregisterSpendRequest struct {
actor.BaseMessage
// CallerID is the unique identifier provided in the original
// RegisterSpendRequest. Required to reconstruct the service key.
CallerID string
// Outpoint is the transaction output being monitored. Can be nil to
// match by script only (must match the original registration).
Outpoint *wire.OutPoint
// PkScript is the public key script being monitored. Required if
// Outpoint is nil.
PkScript []byte
}
// MessageType returns the message type identifier for logging and debugging.
func (m *UnregisterSpendRequest) MessageType() string {
return "UnregisterSpendRequest"
}
// chainSourceMsgSealed implements the ChainSourceMsg interface.
func (m *UnregisterSpendRequest) chainSourceMsgSealed() {}
// UnregisterSpendResponse indicates successful cancellation.
type UnregisterSpendResponse struct {
actor.BaseMessage
}
// MessageType returns the message type identifier for logging and debugging.
func (m *UnregisterSpendResponse) MessageType() string {
return "UnregisterSpendResponse"
}
// chainSourceRespSealed implements the ChainSourceResp interface.
func (m *UnregisterSpendResponse) chainSourceRespSealed() {}
// EpochMsg is the sealed interface for all messages that can be sent to a
// BlockEpochActor sub-actor for block subscription.
type EpochMsg interface {
actor.Message
epochMsgSealed()
}
// EpochResp is the sealed interface for all response messages from a
// BlockEpochActor.
type EpochResp interface {
actor.Message
epochRespSealed()
}
// SubscribeBlocksRequest requests subscription to new block notifications.
// The actor supports dual-mode operation: if NotifyActor is None, an iterator
// is returned for range loops; if NotifyActor is Some, events are sent to
// that actor asynchronously.
type SubscribeBlocksRequest struct {
actor.BaseMessage
// CallerID is a unique identifier provided by the caller. This is used
// to construct the service key for the dedicated actor, enabling
// deterministic cancellation.
CallerID string
// NotifyActor is an optional actor reference. If Some, block events
// will be sent to this actor asynchronously. If None, an iterator is
// returned for use in range loops.
NotifyActor fn.Option[actor.TellOnlyRef[BlockEpoch]]
}
// MessageType returns the message type identifier for logging and debugging.
func (m *SubscribeBlocksRequest) MessageType() string {
return "SubscribeBlocksRequest"
}
// chainSourceMsgSealed implements the ChainSourceMsg interface.
func (m *SubscribeBlocksRequest) chainSourceMsgSealed() {}
// epochMsgSealed implements the sealed EpochMsg interface.
func (m *SubscribeBlocksRequest) epochMsgSealed() {}
// SubscribeBlocksResponse contains either an iterator for range loops or
// nothing if actor-mode notification was requested. The subscription can
// be cancelled later using UnsubscribeBlocksRequest with the original CallerID.
type SubscribeBlocksResponse struct {
actor.BaseMessage
// Iterator provides an iterator for iterating over block epochs using
// Go's range-over-function feature (Go 1.23+). Only present if
// NotifyActor was None in the request.
Iterator iter.Seq[BlockEpoch]
// Cancel terminates the subscription and cleans up backend resources.
// It is safe to call multiple times.
Cancel func()
}
// MessageType returns the message type identifier for logging and debugging.
func (m *SubscribeBlocksResponse) MessageType() string {
return "SubscribeBlocksResponse"
}
// epochRespSealed implements the sealed EpochResp interface.
func (m *SubscribeBlocksResponse) epochRespSealed() {}
// chainSourceRespSealed implements the ChainSourceResp interface.
func (m *SubscribeBlocksResponse) chainSourceRespSealed() {}
// BlockEpoch represents a new block connected to the blockchain. This event is
// sent for each new block and can include backfilled blocks if the client
// fell behind.
type BlockEpoch struct {
actor.BaseMessage
// Height is the block height.
Height int32
// Hash is the block hash.
Hash chainhash.Hash
// Timestamp is the block timestamp from the header.
Timestamp int64
}
// MessageType returns the message type identifier for logging and debugging.
func (m BlockEpoch) MessageType() string {
return "BlockEpoch"
}
// UnsubscribeBlocksRequest requests cancellation of a block subscription.
// The ChainSource actor uses the CallerID to construct the service key and
// cancel the dedicated actor.
type UnsubscribeBlocksRequest struct {
actor.BaseMessage
// CallerID is the unique identifier provided in the original
// SubscribeBlocksRequest. Required to reconstruct the service key.
CallerID string
}
// MessageType returns the message type identifier for logging and debugging.
func (m *UnsubscribeBlocksRequest) MessageType() string {
return "UnsubscribeBlocksRequest"
}
// chainSourceMsgSealed implements the ChainSourceMsg interface.
func (m *UnsubscribeBlocksRequest) chainSourceMsgSealed() {}
// UnsubscribeBlocksResponse indicates successful cancellation.
type UnsubscribeBlocksResponse struct {
actor.BaseMessage
}
// MessageType returns the message type identifier for logging and debugging.
func (m *UnsubscribeBlocksResponse) MessageType() string {
return "UnsubscribeBlocksResponse"
}
// chainSourceRespSealed implements the ChainSourceResp interface.
func (m *UnsubscribeBlocksResponse) chainSourceRespSealed() {}