Skip to content

Commit

Permalink
Merge pull request #850 from crypto-com/fix/tendermint-blcokresult-at…
Browse files Browse the repository at this point in the history
…tributes-decode

Update tendermint block result attributes decode
  • Loading branch information
davcrypto authored Oct 13, 2023
2 parents 39dfb19 + 5c59a3f commit 59c19af
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions infrastructure/tendermint/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,17 @@ func parseBlockResultsEvents(rawEvents []RawBlockResultsEvent) []model.BlockResu
for _, rawEvent := range rawEvents {
attributes := make([]model.BlockResultsEventAttribute, 0, len(rawEvent.Attributes))
for _, rawAttribute := range rawEvent.Attributes {
key, err := base64Decode(rawAttribute.Key)
if err != nil {
key = rawAttribute.Key
}
value, err := base64Decode(rawAttribute.Value)
if err != nil {
value = rawAttribute.Value
}
attributes = append(attributes, model.BlockResultsEventAttribute{
Key: mustBase64Decode(rawAttribute.Key),
Value: mustBase64Decode(rawAttribute.Value),
Key: key,
Value: value,
Index: rawAttribute.Index,
})
}
Expand Down Expand Up @@ -262,6 +270,14 @@ func mustBase64Decode(s string) string {
return string(decoded)
}

func base64Decode(s string) (string, error) {
decoded, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return "", err
}
return string(decoded), nil
}

func parseBlockResultsConsensusParamsUpdates(rawUpdates RawBlockResultsConsensusParamUpdates) model.BlockResultsConsensusParamUpdates {
var validatorPubKeyTypes []string
if rawUpdates.Validator.PubKeyTypes == nil {
Expand Down

0 comments on commit 59c19af

Please sign in to comment.