@@ -28,18 +28,51 @@ import (
2828 "time"
2929
3030 "github.com/SundaeSwap-finance/kugo"
31- "github.com/SundaeSwap-finance/ogmigo/v6/ouroboros/chainsync"
3231 "github.com/blinklabs-io/adder/event"
3332 "github.com/blinklabs-io/adder/internal/config"
3433 "github.com/blinklabs-io/adder/internal/logging"
3534 "github.com/blinklabs-io/adder/plugin"
3635 ouroboros "github.com/blinklabs-io/gouroboros"
3736 "github.com/blinklabs-io/gouroboros/ledger"
38- "github.com/blinklabs-io/gouroboros/protocol/blockfetch"
37+ blockfetch "github.com/blinklabs-io/gouroboros/protocol/blockfetch"
3938 ochainsync "github.com/blinklabs-io/gouroboros/protocol/chainsync"
4039 ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
4140)
4241
42+ // EpochFromSlot derives an epoch from a slot using Byron/Shelley genesis params.
43+ // Byron slots: 0..EndSlot inclusive. Explicit zero EndSlot/Epochs means no Byron era.
44+ // Zero epoch length in either era yields a safe fallback (0 Byron / starting Shelley epoch).
45+ func EpochFromSlot (slot uint64 ) uint64 {
46+ cfg := config .GetConfig ()
47+ byron := cfg .ByronGenesis
48+ shelley := cfg .ShelleyGenesis
49+
50+ endSlot := func () uint64 {
51+ if byron .EndSlot != nil {
52+ return * byron .EndSlot
53+ }
54+ return 0
55+ }()
56+ byronEpochs := func () uint64 {
57+ if byron .Epochs != nil {
58+ return * byron .Epochs
59+ }
60+ return 0
61+ }()
62+ if slot <= endSlot {
63+ if byron .EpochLength == 0 {
64+ return 0 // avoid div by zero
65+ }
66+ return slot / byron .EpochLength
67+ }
68+ shelleyStartEpoch := byronEpochs
69+ shelleyStartSlot := endSlot + 1
70+ if shelley .EpochLength == 0 {
71+ return shelleyStartEpoch // avoid div by zero
72+ }
73+ return shelleyStartEpoch + (slot - shelleyStartSlot )/ shelley .EpochLength
74+ }
75+
4376const (
4477 // Size of cache for recent chainsync cursors
4578 cursorCacheSize = 20
@@ -84,6 +117,7 @@ type ChainSyncStatus struct {
84117 TipBlockHash string
85118 SlotNumber uint64
86119 BlockNumber uint64
120+ EpochNumber uint64
87121 TipSlotNumber uint64
88122 TipReached bool
89123}
@@ -522,6 +556,7 @@ func (c *ChainSync) updateStatus(
522556 c .status .SlotNumber = slotNumber
523557 c .status .BlockNumber = blockNumber
524558 c .status .BlockHash = blockHash
559+ c .status .EpochNumber = EpochFromSlot (slotNumber )
525560 c .status .TipSlotNumber = tipSlotNumber
526561 c .status .TipBlockHash = tipBlockHash
527562 if c .statusUpdateFunc != nil {
@@ -621,9 +656,9 @@ func resolveTransactionInputs(
621656 )
622657 defer cancel ()
623658
624- matches , err := k . Matches ( ctx ,
625- kugo . TxOut ( chainsync . NewTxID ( txId , txIndex )),
626- )
659+ // Create a simple transaction identifier
660+ txID := fmt . Sprintf ( "%d@%s" , txIndex , txId )
661+ matches , err := k . Matches ( ctx , kugo . Transaction ( txID ) )
627662 if err != nil {
628663 if errors .Is (err , context .DeadlineExceeded ) {
629664 return nil , fmt .Errorf (
0 commit comments