Skip to content

Commit

Permalink
Merge pull request #5582 from onflow/petera/backport-tx-results-fix
Browse files Browse the repository at this point in the history
[Access] Fix event conversion in local TxResults endpoint
  • Loading branch information
peterargue authored Mar 26, 2024
2 parents 5e65e12 + 2d9d4b5 commit d89c1c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
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

0 comments on commit d89c1c3

Please sign in to comment.