Skip to content

Commit 4fdb371

Browse files
committed
feat: expose ParseProgramLogs logpoller function
To be used in ccip benthos solana_logs input
1 parent e2ff830 commit 4fdb371

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

pkg/solana/logpoller/job.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (j *getTransactionsFromBlockJob) Run(ctx context.Context) error {
138138

139139
func messagesToEvents(messages []string, parser ProgramEventProcessor, detail eventDetail, chJobs chan Job) {
140140
var logIdx uint
141-
for _, outputs := range parseProgramLogs(messages) {
141+
for _, outputs := range ParseProgramLogs(messages) {
142142
for _, event := range outputs.Events {
143143
event.SlotNumber = detail.slotNumber
144144
event.BlockHeight = detail.blockHeight

pkg/solana/logpoller/log_data_parser.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ func prefixBuilder(depth int) string {
5050
return strings.Repeat(">", depth)
5151
}
5252

53-
func parseProgramLogs(logs []string) []ProgramOutput {
53+
func ParseProgramLogs(logs []string) []ProgramOutput {
5454
var depth int
5555

5656
instLogs := []ProgramOutput{}
5757
lastLogIdx := -1
5858

59-
for _, log := range logs {
59+
for i, log := range logs {
6060
if strings.HasPrefix(log, "Program log:") {
6161
logDataMatches := logMatcher.FindStringSubmatch(log)
6262

@@ -80,6 +80,9 @@ func parseProgramLogs(logs []string) []ProgramOutput {
8080
instLogs[lastLogIdx].Events = append(instLogs[lastLogIdx].Events, ProgramEvent{
8181
Prefix: prefixBuilder(depth),
8282
Data: dataMatches[1],
83+
BlockData: BlockData{
84+
TransactionLogIndex: uint(i), //nolint:gosec // disable G115
85+
},
8386
})
8487
}
8588
} else if strings.HasPrefix(log, "Log truncated") {

pkg/solana/logpoller/log_data_parser_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestLogDataParse_Error(t *testing.T) {
2020
"Program cjg3oHmg9uuPsP8D6g29NWvhySJkdYdAo9D25PRbKXJ failed: custom program error: 0x1773",
2121
}
2222

23-
output := parseProgramLogs(logs)
23+
output := ParseProgramLogs(logs)
2424

2525
require.Len(t, output, 2)
2626

@@ -60,7 +60,7 @@ func TestLogDataParse_SuccessBasic(t *testing.T) {
6060
"Program SAGE2HAwep459SNq61LHvjxPk4pLPEJLoMETef7f7EE success",
6161
}
6262

63-
output := parseProgramLogs(logs)
63+
output := ParseProgramLogs(logs)
6464

6565
require.Len(t, output, 2)
6666

@@ -163,7 +163,7 @@ func TestLogDataParse_SuccessComplex(t *testing.T) {
163163
"Program HQ2UUt18uJqKaQFJhgV9zaTdQxUZjNrsKFgoEDquBkcx success",
164164
}
165165

166-
output := parseProgramLogs(logs)
166+
output := ParseProgramLogs(logs)
167167

168168
require.Len(t, output, 11)
169169

@@ -196,7 +196,7 @@ func TestLogDataParse_Events(t *testing.T) {
196196
"Program J1zQwrBNBngz26jRPNWsUSZMHJwBwpkoDitXRV95LdK4 success",
197197
}
198198

199-
output := parseProgramLogs(logs)
199+
output := ParseProgramLogs(logs)
200200

201201
require.Len(t, output, 1)
202202
assert.Len(t, output[0].Events, 1)

0 commit comments

Comments
 (0)