From 4fdb371d0f8620b9371cb387e8aaac7dc118ef0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Vitor=20de=20Lima=20Matos?= Date: Sat, 28 Dec 2024 19:21:16 -0300 Subject: [PATCH] feat: expose ParseProgramLogs logpoller function To be used in ccip benthos solana_logs input --- pkg/solana/logpoller/job.go | 2 +- pkg/solana/logpoller/log_data_parser.go | 7 +++++-- pkg/solana/logpoller/log_data_parser_test.go | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/solana/logpoller/job.go b/pkg/solana/logpoller/job.go index 165c0b5fe..a8dce73d4 100644 --- a/pkg/solana/logpoller/job.go +++ b/pkg/solana/logpoller/job.go @@ -138,7 +138,7 @@ func (j *getTransactionsFromBlockJob) Run(ctx context.Context) error { func messagesToEvents(messages []string, parser ProgramEventProcessor, detail eventDetail, chJobs chan Job) { var logIdx uint - for _, outputs := range parseProgramLogs(messages) { + for _, outputs := range ParseProgramLogs(messages) { for _, event := range outputs.Events { event.SlotNumber = detail.slotNumber event.BlockHeight = detail.blockHeight diff --git a/pkg/solana/logpoller/log_data_parser.go b/pkg/solana/logpoller/log_data_parser.go index 4080a09e2..11488619a 100644 --- a/pkg/solana/logpoller/log_data_parser.go +++ b/pkg/solana/logpoller/log_data_parser.go @@ -50,13 +50,13 @@ func prefixBuilder(depth int) string { return strings.Repeat(">", depth) } -func parseProgramLogs(logs []string) []ProgramOutput { +func ParseProgramLogs(logs []string) []ProgramOutput { var depth int instLogs := []ProgramOutput{} lastLogIdx := -1 - for _, log := range logs { + for i, log := range logs { if strings.HasPrefix(log, "Program log:") { logDataMatches := logMatcher.FindStringSubmatch(log) @@ -80,6 +80,9 @@ func parseProgramLogs(logs []string) []ProgramOutput { instLogs[lastLogIdx].Events = append(instLogs[lastLogIdx].Events, ProgramEvent{ Prefix: prefixBuilder(depth), Data: dataMatches[1], + BlockData: BlockData{ + TransactionLogIndex: uint(i), //nolint:gosec // disable G115 + }, }) } } else if strings.HasPrefix(log, "Log truncated") { diff --git a/pkg/solana/logpoller/log_data_parser_test.go b/pkg/solana/logpoller/log_data_parser_test.go index 49123638c..52b69ef7d 100644 --- a/pkg/solana/logpoller/log_data_parser_test.go +++ b/pkg/solana/logpoller/log_data_parser_test.go @@ -20,7 +20,7 @@ func TestLogDataParse_Error(t *testing.T) { "Program cjg3oHmg9uuPsP8D6g29NWvhySJkdYdAo9D25PRbKXJ failed: custom program error: 0x1773", } - output := parseProgramLogs(logs) + output := ParseProgramLogs(logs) require.Len(t, output, 2) @@ -60,7 +60,7 @@ func TestLogDataParse_SuccessBasic(t *testing.T) { "Program SAGE2HAwep459SNq61LHvjxPk4pLPEJLoMETef7f7EE success", } - output := parseProgramLogs(logs) + output := ParseProgramLogs(logs) require.Len(t, output, 2) @@ -163,7 +163,7 @@ func TestLogDataParse_SuccessComplex(t *testing.T) { "Program HQ2UUt18uJqKaQFJhgV9zaTdQxUZjNrsKFgoEDquBkcx success", } - output := parseProgramLogs(logs) + output := ParseProgramLogs(logs) require.Len(t, output, 11) @@ -196,7 +196,7 @@ func TestLogDataParse_Events(t *testing.T) { "Program J1zQwrBNBngz26jRPNWsUSZMHJwBwpkoDitXRV95LdK4 success", } - output := parseProgramLogs(logs) + output := ParseProgramLogs(logs) require.Len(t, output, 1) assert.Len(t, output[0].Events, 1)