From 89506df76b31069ad9ae5eab8e1ac287e1ac2093 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Mon, 14 Oct 2024 10:27:34 +0700 Subject: [PATCH 1/2] refactor: add close body after used and fix lint --- collections/quad.go | 3 --- schema/indexer/start.go | 2 +- server/v2/cometbft/abci.go | 2 +- .../integration/tx/aminojson/aminojson_test.go | 18 ------------------ tools/hubl/internal/registry.go | 5 ++++- 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/collections/quad.go b/collections/quad.go index 2e0678e69ea2..cf17cc32eaba 100644 --- a/collections/quad.go +++ b/collections/quad.go @@ -106,7 +106,6 @@ type quadKeyCodec[K1, K2, K3, K4 any] struct { type jsonQuadKey [4]json.RawMessage - // EncodeJSON encodes Quads to json func (t quadKeyCodec[K1, K2, K3, K4]) EncodeJSON(value Quad[K1, K2, K3, K4]) ([]byte, error) { json1, err := t.keyCodec1.EncodeJSON(*value.k1) @@ -210,7 +209,6 @@ func (t quadKeyCodec[K1, K2, K3, K4]) KeyType() string { return fmt.Sprintf("Quad[%s,%s,%s,%s]", t.keyCodec1.KeyType(), t.keyCodec2.KeyType(), t.keyCodec3.KeyType(), t.keyCodec4.KeyType()) } - func (t quadKeyCodec[K1, K2, K3, K4]) Encode(buffer []byte, key Quad[K1, K2, K3, K4]) (int, error) { writtenTotal := 0 if key.k1 != nil { @@ -244,7 +242,6 @@ func (t quadKeyCodec[K1, K2, K3, K4]) Encode(buffer []byte, key Quad[K1, K2, K3, return writtenTotal, nil } - func (t quadKeyCodec[K1, K2, K3, K4]) Decode(buffer []byte) (int, Quad[K1, K2, K3, K4], error) { readTotal := 0 read, key1, err := t.keyCodec1.DecodeNonTerminal(buffer) diff --git a/schema/indexer/start.go b/schema/indexer/start.go index f675c2916026..cc5110046eee 100644 --- a/schema/indexer/start.go +++ b/schema/indexer/start.go @@ -120,7 +120,7 @@ func StartIndexing(opts IndexingOptions) (IndexingTarget, error) { targetCfg.Config, err = unmarshalIndexerCustomConfig(targetCfg.Config, init.ConfigType) if err != nil { - return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err) + return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %w", targetName, err) } initRes, err := init.InitFunc(InitParams{ diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 95eeec9bb5da..fe0cc412ab39 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -105,7 +105,7 @@ func NewConsensus[T transaction.Tx]( indexedEvents: indexedEvents, initialHeight: 0, queryHandlersMap: queryHandlersMap, - getProtoRegistry: sync.OnceValues(func() (*protoregistry.Files, error) { return gogoproto.MergedRegistry() }), + getProtoRegistry: sync.OnceValues(gogoproto.MergedRegistry), } } diff --git a/tests/integration/tx/aminojson/aminojson_test.go b/tests/integration/tx/aminojson/aminojson_test.go index c68f24e97865..38aecaa9b30f 100644 --- a/tests/integration/tx/aminojson/aminojson_test.go +++ b/tests/integration/tx/aminojson/aminojson_test.go @@ -2,7 +2,6 @@ package aminojson import ( "bytes" - "encoding/json" "fmt" stdmath "math" "testing" @@ -454,20 +453,3 @@ func postFixPulsarMessage(msg proto.Message) { } } } - -// sortJson sorts the JSON bytes by way of the side effect of unmarshalling and remarshalling the JSON -// using encoding/json. This hacky way of sorting JSON fields was used by the legacy amino JSON encoding in -// x/auth/migrations/legacytx.StdSignBytes. It is used here ensure the x/tx JSON encoding is equivalent to -// the legacy amino JSON encoding. -func sortJson(bz []byte) ([]byte, error) { - var c any - err := json.Unmarshal(bz, &c) - if err != nil { - return nil, err - } - js, err := json.Marshal(c) - if err != nil { - return nil, err - } - return js, nil -} diff --git a/tools/hubl/internal/registry.go b/tools/hubl/internal/registry.go index a3eea12391e4..945e0ff4296c 100644 --- a/tools/hubl/internal/registry.go +++ b/tools/hubl/internal/registry.go @@ -26,12 +26,15 @@ func GetChainRegistryEntry(chain string) (*ChainRegistryEntry, error) { if err != nil { return nil, err } - bz, err := io.ReadAll(res.Body) if err != nil { return nil, err } + if err = res.Body.Close(); err != nil { + return nil, err + } + data := &ChainRegistryEntry{} if err = json.Unmarshal(bz, data); err != nil { return nil, err From dbe05c5441e3e9d78813cfeb8811bf077b3fa0f7 Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Mon, 14 Oct 2024 14:17:54 +0700 Subject: [PATCH 2/2] bet --- schema/indexer/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema/indexer/start.go b/schema/indexer/start.go index cc5110046eee..f675c2916026 100644 --- a/schema/indexer/start.go +++ b/schema/indexer/start.go @@ -120,7 +120,7 @@ func StartIndexing(opts IndexingOptions) (IndexingTarget, error) { targetCfg.Config, err = unmarshalIndexerCustomConfig(targetCfg.Config, init.ConfigType) if err != nil { - return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %w", targetName, err) + return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err) } initRes, err := init.InitFunc(InitParams{