From 2fda2b9a93447150404628af42006ad52479343d Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:07:43 -0800 Subject: [PATCH] WIP --- pkg/solana/logpoller/log_poller.go | 34 +++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/pkg/solana/logpoller/log_poller.go b/pkg/solana/logpoller/log_poller.go index 37f897aa2..1088f565a 100644 --- a/pkg/solana/logpoller/log_poller.go +++ b/pkg/solana/logpoller/log_poller.go @@ -3,6 +3,8 @@ package logpoller import ( "context" "errors" + "fmt" + "math" "sync" "time" @@ -19,10 +21,11 @@ var ( //go:generate mockery --name ORM --inpackage --structname mockORM --filename mock_orm.go type ORM interface { - InsertFilter(ctx context.Context, filter Filter) (id int64, err error) - SelectFilters(ctx context.Context) ([]Filter, error) - DeleteFilters(ctx context.Context, filters map[int64]Filter) error + InsertFilter(context.Context, filter Filter) (id int64, err error) + SelectFilters(context.Context) ([]Filter, error) + DeleteFilters(context.Context, filters map[int64]Filter) error MarkFilterDeleted(ctx context.Context, id int64) (err error) + InsertLogs(context.Context, []Log) (err error) } type ILogPoller interface { @@ -57,9 +60,34 @@ func NewLogPoller(lggr logger.SugaredLogger, orm ORM, cl internal.Loader[client. return &lp } +func makeLogIndex(txIndex int, txLogIndex uint) int64 { + if txIndex < 0 || txIndex > math.MaxUint32 || txLogIndex > math.MaxUint32 { + panic(fmt.Sprintf("txIndex or txLogIndex out of range: txIndex=%d, txLogIndex=%d", txIndex, txLogIndex)) + } + return int64(math.MaxUint32 * uint32(txIndex) + uint32(txLogIndex)) +} + func (lp *LogPoller) Process(event ProgramEvent) error { // process stream of events coming from event loader + + Decode(event.Data) // Borsch decode + + log := Log{ + FilterID: filterID, + ChainID: lp.chainID, + LogIndex: makeLogIndex(event.TransactionIndex, event.TransactionLogIndex), + BlockHash: Hash(event.BlockHash), + BlockNumber: int64(event.BlockHeight), + BlockTimestamp: , + Address:, + EventSig:, + + } + + logs := []Log{log} + lp.events = append(lp.events, event) + return nil }