Skip to content

Commit c1d7f35

Browse files
committed
Updated log decoding
1 parent ec45863 commit c1d7f35

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

pkg/solana/ccip/chainaccessor/event.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"math/big"
10-
"reflect"
1110
"slices"
1211
"strconv"
1312
"strings"
@@ -230,7 +229,7 @@ func (a *SolanaAccessor) convertCCIPMessageSent(logs []logpollertypes.Log, onram
230229
// return nil, fmt.Errorf("failed to create type to decode event into: %w", err)
231230
// }
232231
// a.lggr.Debugf("created type to decode event into: %T", item)
233-
iter, err := a.decodeLogsIntoSequences(consts.EventNameCCIPMessageSent, logs, &ccip.EventCCIPMessageSent{})
232+
iter, err := a.decodeLogsIntoSequences(consts.EventNameCCIPMessageSent, logs)
234233
if err != nil {
235234
return nil, fmt.Errorf("failed to decode logs into sequences: %w", err)
236235
}
@@ -332,7 +331,7 @@ func (a *SolanaAccessor) processCommitReports(
332331
// if err != nil {
333332
// return nil, fmt.Errorf("failed to create type to decode event into: %w", err)
334333
// }
335-
iter, err := a.decodeLogsIntoSequences(consts.EventNameCommitReportAccepted, logs, &ccip.EventCommitReportAccepted{})
334+
iter, err := a.decodeLogsIntoSequences(consts.EventNameCommitReportAccepted, logs)
336335
if err != nil {
337336
return nil, fmt.Errorf("failed to decode logs into sequences: %w", err)
338337
}
@@ -559,7 +558,7 @@ func (a *SolanaAccessor) processExecutionStateChangesEvents(logs []logpollertype
559558
// if err != nil {
560559
// return nil, fmt.Errorf("failed to create type to decode event into: %w", err)
561560
// }
562-
iter, err := a.decodeLogsIntoSequences(consts.EventNameExecutionStateChanged, logs, &ccip.EventExecutionStateChanged{})
561+
iter, err := a.decodeLogsIntoSequences(consts.EventNameExecutionStateChanged, logs)
563562
if err != nil {
564563
return nil, fmt.Errorf("failed to decode logs into sequences: %w", err)
565564
}
@@ -616,7 +615,6 @@ func validateExecutionStateChangedEvent(
616615
func (a *SolanaAccessor) decodeLogsIntoSequences(
617616
event string,
618617
logs []logpollertypes.Log,
619-
into any,
620618
) ([]types.Sequence, error) {
621619
sequences := make([]types.Sequence, len(logs))
622620

@@ -630,29 +628,38 @@ func (a *SolanaAccessor) decodeLogsIntoSequences(
630628
},
631629
}
632630

633-
var typeVal reflect.Value
631+
// var typeVal reflect.Value
634632

635-
typeInto := reflect.TypeOf(into)
636-
if typeInto.Kind() == reflect.Pointer {
637-
typeVal = reflect.New(typeInto.Elem())
638-
} else {
639-
typeVal = reflect.Indirect(reflect.New(typeInto))
640-
}
633+
// typeInto := reflect.TypeOf(into)
634+
// if typeInto.Kind() == reflect.Pointer {
635+
// typeVal = reflect.New(typeInto.Elem())
636+
// } else {
637+
// typeVal = reflect.Indirect(reflect.New(typeInto))
638+
// }
641639

642-
// create a new value of the same type as 'into' for the data to be extracted to
643-
sequences[idx].Data = typeVal.Interface()
640+
// // create a new value of the same type as 'into' for the data to be extracted to
641+
// sequences[idx].Data = typeVal.Interface()
644642

645643
// if the event is `EventCommitReportAccepted`, we need to handle it separately
646644
switch event {
647645
case consts.EventNameCommitReportAccepted:
646+
sequences[idx].Data = ccip.EventCommitReportAccepted{}
648647
derr := decodeCommitReportAcceptedEvent(logs[idx].Data, &sequences[idx].Data)
649648
if derr != nil {
650649
return nil, derr
651650
}
652-
default:
651+
case consts.EventNameCCIPMessageSent:
652+
sequences[idx].Data = ccip.EventCCIPMessageSent{}
653653
if err := bin.UnmarshalBorsh(&sequences[idx].Data, logs[idx].Data); err != nil {
654654
return nil, err
655655
}
656+
case consts.EventNameExecutionStateChanged:
657+
sequences[idx].Data = ccip.EventExecutionStateChanged{}
658+
if err := bin.UnmarshalBorsh(&sequences[idx].Data, logs[idx].Data); err != nil {
659+
return nil, err
660+
}
661+
default:
662+
return nil, fmt.Errorf("unsupported event %s", event)
656663
}
657664

658665
// if err := a.decodeLog(ctx, itemType, logs[idx], sequences[idx].Data); err != nil {

0 commit comments

Comments
 (0)