Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose ParseProgramLogs logpoller function #994

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading