From 5c59a3f88a2a14167280ec31d457f1a288f9a48a Mon Sep 17 00:00:00 2001 From: David So Date: Fri, 13 Oct 2023 15:57:39 +0800 Subject: [PATCH] UPT fendermint blcok result attributes decode --- infrastructure/tendermint/parser.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/infrastructure/tendermint/parser.go b/infrastructure/tendermint/parser.go index 9deb7afd4..2b07a743d 100644 --- a/infrastructure/tendermint/parser.go +++ b/infrastructure/tendermint/parser.go @@ -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, }) } @@ -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 {