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(baseapp): integrate the appdata.Listener in baseapp #21965

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
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
42 changes: 36 additions & 6 deletions baseapp/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,45 @@ type listenerWrapper struct {

func (p listenerWrapper) ListenFinalizeBlock(_ context.Context, req abci.FinalizeBlockRequest, res abci.FinalizeBlockResponse) error {
if p.listener.StartBlock != nil {
err := p.listener.StartBlock(appdata.StartBlockData{
Height: uint64(req.Height),
})
if err != nil {
if err := p.listener.StartBlock(appdata.StartBlockData{
Height: uint64(req.Height),
HeaderBytes: nil, // TODO: need to define a header struct including enc/decoding
HeaderJSON: nil, // TODO: need to define a header json struct
}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Address TODOs for HeaderBytes and HeaderJSON in StartBlockData.

The HeaderBytes and HeaderJSON fields are currently set to nil, with TODO comments indicating the need to define a header struct including encoding and decoding. Implementing these fields is important for proper handling of header information in the listener.

Would you like assistance in defining the header struct and implementing the necessary encoding/decoding functions?

return err
}
}

//// TODO txs, events
if p.listener.OnTx != nil {
for i, tx := range req.Txs {
if err := p.listener.OnTx(appdata.TxData{
TxIndex: int32(i),
Bytes: func() ([]byte, error) { return tx, nil },
JSON: nil, // TODO: need to define a tx json struct
}); err != nil {
return err
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implement JSON representation for transactions in TxData.

In the OnTx listener invocation, the JSON field of TxData is set to nil, with a TODO comment indicating the need to define a JSON struct for transactions. Providing a JSON representation of transactions may be important for downstream processing or indexing.

Do you need help in defining the transaction JSON struct and implementing its encoding?

if p.listener.OnEvent != nil {
events := make([]appdata.Event, len(res.Events))
for i, event := range res.Events {
events[i] = appdata.Event{
BlockStage: appdata.UnknownBlockStage,
Type: event.Type,
Data: nil,
Attributes: func() ([]appdata.EventAttribute, error) {
attrs := make([]appdata.EventAttribute, len(event.Attributes))
for j, attr := range event.Attributes {
attrs[j] = appdata.EventAttribute{
Key: attr.Key,
Value: attr.Value,
}
}
return attrs, nil
},
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Events are constructed but not processed; missing call to OnEvent method.

After constructing the events slice from res.Events, the code does not invoke any method to process these events. This may result in events not being properly handled by the listener.

You may need to call p.listener.OnEvent with the constructed events slice to ensure events are processed correctly. For example:

if err := p.listener.OnEvent(events); err != nil {
    return err
}


return nil
}
Expand Down
Loading