@@ -28,25 +28,36 @@ import (
28
28
)
29
29
30
30
type ChainSync struct {
31
- oConn * ouroboros.Connection
32
- network string
33
- networkMagic uint32
34
- address string
35
- socketPath string
36
- ntcTcp bool
37
- intersectTip bool
38
- intersectPoints []ocommon.Point
39
- includeCbor bool
40
- errorChan chan error
41
- eventChan chan event.Event
31
+ oConn * ouroboros.Connection
32
+ network string
33
+ networkMagic uint32
34
+ address string
35
+ socketPath string
36
+ ntcTcp bool
37
+ intersectTip bool
38
+ intersectPoints []ocommon.Point
39
+ includeCbor bool
40
+ statusUpdateFunc StatusUpdateFunc
41
+ status * ChainSyncStatus
42
+ errorChan chan error
43
+ eventChan chan event.Event
42
44
}
43
45
46
+ type ChainSyncStatus struct {
47
+ SlotNumber uint64
48
+ BlockNumber uint64
49
+ BlockHash string
50
+ }
51
+
52
+ type StatusUpdateFunc func (ChainSyncStatus )
53
+
44
54
// New returns a new ChainSync object with the specified options applied
45
55
func New (options ... ChainSyncOptionFunc ) * ChainSync {
46
56
c := & ChainSync {
47
57
errorChan : make (chan error ),
48
58
eventChan : make (chan event.Event , 10 ),
49
59
intersectPoints : []ocommon.Point {},
60
+ status : & ChainSyncStatus {},
50
61
}
51
62
for _ , option := range options {
52
63
option (c )
@@ -176,6 +187,7 @@ func (c *ChainSync) handleRollForward(blockType uint, blockData interface{}, tip
176
187
case ledger.Block :
177
188
evt := event .New ("chainsync.block" , time .Now (), NewBlockEvent (v , c .includeCbor ))
178
189
c .eventChan <- evt
190
+ c .updateStatus (v .SlotNumber (), v .BlockNumber (), v .Hash ())
179
191
case ledger.BlockHeader :
180
192
blockSlot := v .SlotNumber ()
181
193
blockHash , _ := hex .DecodeString (v .Hash ())
@@ -189,6 +201,16 @@ func (c *ChainSync) handleRollForward(blockType uint, blockData interface{}, tip
189
201
txEvt := event .New ("chainsync.transaction" , time .Now (), NewTransactionEvent (block , transaction , c .includeCbor ))
190
202
c .eventChan <- txEvt
191
203
}
204
+ c .updateStatus (v .SlotNumber (), v .BlockNumber (), v .Hash ())
192
205
}
193
206
return nil
194
207
}
208
+
209
+ func (c * ChainSync ) updateStatus (slotNumber uint64 , blockNumber uint64 , blockHash string ) {
210
+ c .status .SlotNumber = slotNumber
211
+ c .status .BlockNumber = blockNumber
212
+ c .status .BlockHash = blockHash
213
+ if c .statusUpdateFunc != nil {
214
+ c .statusUpdateFunc (* (c .status ))
215
+ }
216
+ }
0 commit comments