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

[Access] Fix event conversion in local TxResults endpoint #5582

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
30 changes: 9 additions & 21 deletions engine/access/rpc/backend/transactions_local_data_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ func (t *TransactionsLocalDataProvider) GetTransactionResultFromStorage(

// events are encoded in CCF format in storage. convert to JSON-CDC if requested
if requiredEventEncodingVersion == entities.EventEncodingVersion_JSON_CDC_V0 {
for _, e := range events {
payload, err := convert.CcfPayloadToJsonPayload(e.Payload)
if err != nil {
err = fmt.Errorf("failed to convert event payload for block %s: %w", blockID, err)
return nil, rpc.ConvertError(err, "failed to convert event payload", codes.Internal)
}
e.Payload = payload
events, err = convert.CcfEventsToJsonEvents(events)
if err != nil {
return nil, rpc.ConvertError(err, "failed to convert event payload", codes.Internal)
}
}

Expand Down Expand Up @@ -197,13 +193,9 @@ func (t *TransactionsLocalDataProvider) GetTransactionResultsByBlockIDFromStorag

// events are encoded in CCF format in storage. convert to JSON-CDC if requested
if requiredEventEncodingVersion == entities.EventEncodingVersion_JSON_CDC_V0 {
for _, e := range events {
payload, err := convert.CcfPayloadToJsonPayload(e.Payload)
if err != nil {
err = fmt.Errorf("failed to convert event payload for block %s: %w", blockID, err)
return nil, rpc.ConvertError(err, "failed to convert event payload", codes.Internal)
}
e.Payload = payload
events, err = convert.CcfEventsToJsonEvents(events)
if err != nil {
return nil, rpc.ConvertError(err, "failed to convert event payload", codes.Internal)
}
}

Expand Down Expand Up @@ -278,13 +270,9 @@ func (t *TransactionsLocalDataProvider) GetTransactionResultByIndexFromStorage(

// events are encoded in CCF format in storage. convert to JSON-CDC if requested
if requiredEventEncodingVersion == entities.EventEncodingVersion_JSON_CDC_V0 {
for _, e := range events {
payload, err := convert.CcfPayloadToJsonPayload(e.Payload)
if err != nil {
err = fmt.Errorf("failed to convert event payload for block %s: %w", blockID, err)
return nil, rpc.ConvertError(err, "failed to convert event payload", codes.Internal)
}
e.Payload = payload
events, err = convert.CcfEventsToJsonEvents(events)
if err != nil {
return nil, rpc.ConvertError(err, "failed to convert event payload", codes.Internal)
}
}

Expand Down
14 changes: 14 additions & 0 deletions engine/common/rpc/convert/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ func CcfEventToJsonEvent(e flow.Event) (*flow.Event, error) {
}, nil
}

// CcfEventsToJsonEvents returns a new event with the payload converted from CCF to JSON
func CcfEventsToJsonEvents(events []flow.Event) ([]flow.Event, error) {
convertedEvents := make([]flow.Event, len(events))
for i, e := range events {
payload, err := CcfPayloadToJsonPayload(e.Payload)
if err != nil {
return nil, fmt.Errorf("failed to convert event payload for event %d: %w", i, err)
}
e.Payload = payload
convertedEvents[i] = e
}
return convertedEvents, nil
}

// MessagesToBlockEvents converts a protobuf EventsResponse_Result messages to a slice of flow.BlockEvents.
func MessagesToBlockEvents(blocksEvents []*accessproto.EventsResponse_Result) []flow.BlockEvents {
evs := make([]flow.BlockEvents, len(blocksEvents))
Expand Down
Loading