Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Dec 16, 2024
1 parent f119c69 commit 2fda2b9
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions pkg/solana/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package logpoller
import (
"context"
"errors"
"fmt"
"math"
"sync"
"time"

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 2fda2b9

Please sign in to comment.