Skip to content

Commit

Permalink
feat: expose ParseProgramLogs logpoller function
Browse files Browse the repository at this point in the history
To be used in ccip benthos solana_logs input
  • Loading branch information
andrevmatos committed Dec 29, 2024
1 parent e2ff830 commit 4fdb371
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/solana/logpoller/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/solana/logpoller/log_data_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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") {
Expand Down
8 changes: 4 additions & 4 deletions pkg/solana/logpoller/log_data_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -60,7 +60,7 @@ func TestLogDataParse_SuccessBasic(t *testing.T) {
"Program SAGE2HAwep459SNq61LHvjxPk4pLPEJLoMETef7f7EE success",
}

output := parseProgramLogs(logs)
output := ParseProgramLogs(logs)

require.Len(t, output, 2)

Expand Down Expand Up @@ -163,7 +163,7 @@ func TestLogDataParse_SuccessComplex(t *testing.T) {
"Program HQ2UUt18uJqKaQFJhgV9zaTdQxUZjNrsKFgoEDquBkcx success",
}

output := parseProgramLogs(logs)
output := ParseProgramLogs(logs)

require.Len(t, output, 11)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4fdb371

Please sign in to comment.