@@ -28,18 +28,52 @@ 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/ShelleyTransEpoch 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+ shelleyTransEpoch := func () uint64 {
57+ if cfg .ShelleyTransEpoch >= 0 {
58+ //nolint:gosec // ShelleyTransEpoch is controlled config, safe conversion
59+ return uint64 (cfg .ShelleyTransEpoch )
60+ }
61+ return 0
62+ }()
63+ if slot <= endSlot {
64+ if byron .EpochLength == 0 {
65+ return 0 // avoid div by zero
66+ }
67+ return slot / byron .EpochLength
68+ }
69+ shelleyStartEpoch := shelleyTransEpoch
70+ shelleyStartSlot := endSlot + 1
71+ if shelley .EpochLength == 0 {
72+ return shelleyStartEpoch // avoid div by zero
73+ }
74+ return shelleyStartEpoch + (slot - shelleyStartSlot )/ shelley .EpochLength
75+ }
76+
4377const (
4478 // Size of cache for recent chainsync cursors
4579 cursorCacheSize = 20
@@ -84,6 +118,7 @@ type ChainSyncStatus struct {
84118 TipBlockHash string
85119 SlotNumber uint64
86120 BlockNumber uint64
121+ EpochNumber uint64
87122 TipSlotNumber uint64
88123 TipReached bool
89124}
@@ -522,6 +557,7 @@ func (c *ChainSync) updateStatus(
522557 c .status .SlotNumber = slotNumber
523558 c .status .BlockNumber = blockNumber
524559 c .status .BlockHash = blockHash
560+ c .status .EpochNumber = EpochFromSlot (slotNumber )
525561 c .status .TipSlotNumber = tipSlotNumber
526562 c .status .TipBlockHash = tipBlockHash
527563 if c .statusUpdateFunc != nil {
@@ -621,9 +657,9 @@ func resolveTransactionInputs(
621657 )
622658 defer cancel ()
623659
624- matches , err := k . Matches ( ctx ,
625- kugo . TxOut ( chainsync . NewTxID ( txId , txIndex )),
626- )
660+ // Create a simple transaction identifier
661+ txID := fmt . Sprintf ( "%d@%s" , txIndex , txId )
662+ matches , err := k . Matches ( ctx , kugo . Transaction ( txID ) )
627663 if err != nil {
628664 if errors .Is (err , context .DeadlineExceeded ) {
629665 return nil , fmt .Errorf (
0 commit comments