Skip to content

Commit

Permalink
move cometbft block results helper methods and types to their own go …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
jtieri committed Oct 19, 2023
1 parent 500e8b2 commit 1dd3ff1
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions relayer/chains/comet_rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package chains

import (
abci "github.com/cometbft/cometbft/abci/types"
legacyabci "github.com/strangelove-ventures/cometbft/abci/types"
)

// Results is a generalized type used in the relayer to handle the breaking changes in the CometBFT type,
// ResultBlockResults, that were introduced in v0.38.0.
type Results struct {
TxsResults []*TxResult
Events []abci.Event
}

// TxResult is a generalized type used in the relayer to handle the breaking changes in the CometBFT type,
// ResultBlockResults, that were introduced in v0.38.0.
type TxResult struct {
Code uint32
Events []abci.Event
}

// ConvertEvents converts a slice of the abci Event type imported from our forked CometBFT repo into
// a slice of the abci Event type imported from the upstream CometBFT repo.
func ConvertEvents(events []legacyabci.Event) []abci.Event {
var cometEvents []abci.Event

for _, event := range events {
newEvent := abci.Event{
Type: event.Type,
}

var attributes []abci.EventAttribute
for _, attr := range event.Attributes {
attributes = append(attributes, abci.EventAttribute{
Key: attr.Key,
Value: attr.Value,
Index: attr.Index,
})
}

newEvent.Attributes = attributes

cometEvents = append(cometEvents, newEvent)
}

return cometEvents
}

// ConvertTxResults converts a slice of the ResponseDeliverTx type imported from our forked CometBFT repo
// into a slice of our generalized TxResult type, so that we can properly handle the breaking changes introduced
// in CometBFT v0.38.0.
func ConvertTxResults(results []*legacyabci.ResponseDeliverTx) []*TxResult {
var res []*TxResult

for _, r := range results {
newResult := &TxResult{
Code: r.Code,
Events: ConvertEvents(r.Events),
}

res = append(res, newResult)
}

return res
}

0 comments on commit 1dd3ff1

Please sign in to comment.