From f51de891e9abe0e43efac6ee5bec3fb95594b0a3 Mon Sep 17 00:00:00 2001 From: neeraj Date: Wed, 10 Jan 2024 18:03:54 +0530 Subject: [PATCH] Fix lint errors --- ethereum/eip712/eip712.go | 19 ++++++++++--------- .../vulcanize/registry/v1beta1/registry.proto | 3 +-- x/registry/client/testutil/grpc.go | 8 ++++---- x/registry/keeper/keeper.go | 5 ++++- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ethereum/eip712/eip712.go b/ethereum/eip712/eip712.go index 1039f25d..0fd35ff3 100644 --- a/ethereum/eip712/eip712.go +++ b/ethereum/eip712/eip712.go @@ -24,6 +24,8 @@ import ( "github.com/ethereum/go-ethereum/signer/core/apitypes" ) +const bytesStr = "bytes" + // WrapTxToTypedData is an ultimate method that wraps Amino-encoded Cosmos Tx JSON data // into an EIP712-compatible TypedData request. func WrapTxToTypedData( @@ -33,7 +35,6 @@ func WrapTxToTypedData( data []byte, feeDelegation *FeeDelegationOptions, ) (apitypes.TypedData, error) { - domain := apitypes.TypedDataDomain{ Name: "Cosmos Web3", Version: "1.0.0", @@ -298,7 +299,7 @@ func traverseFields( } // convert uint8[] to bytes if fieldType.Kind() == reflect.Uint8 { - ethTyp = "bytes" + ethTyp = bytesStr } } if prefix == typeDefPrefix { @@ -448,7 +449,7 @@ func typToEth(typ reflect.Type) string { ethName := typToEth(typ.Elem()) if len(ethName) > 0 { if ethName == "uint8" { - return "bytes" + return bytesStr } return ethName + "[]" } @@ -495,7 +496,9 @@ func patchTxData(data map[string]any, schema apitypes.Types, rootType string) er for _, field := range schema[rootType] { encType := field.Type encValue := data[field.Name] - if encType[len(encType)-1:] == "]" { + + switch { + case encType[len(encType)-1:] == "]": arrayValue, ok := encValue.([]interface{}) if !ok { return dataMismatchError(encType, encValue) @@ -523,8 +526,7 @@ func patchTxData(data map[string]any, schema apitypes.Types, rootType string) er arrayValue[i] = converted } } - - } else if schema[encType] != nil { + case schema[encType] != nil: mapValue, ok := encValue.(map[string]interface{}) if !ok { return dataMismatchError(encType, encValue) @@ -533,7 +535,7 @@ func patchTxData(data map[string]any, schema apitypes.Types, rootType string) er if err != nil { return err } - } else { + default: converted, err := handleConversion(encType, encValue) if err != nil { return err @@ -545,8 +547,7 @@ func patchTxData(data map[string]any, schema apitypes.Types, rootType string) er } func handleConversion(encType string, encValue any) (any, error) { - switch encType { - case "bytes": + if encType == bytesStr { // Protobuf encodes byte strings in base64 if v, ok := encValue.(string); ok { return base64.StdEncoding.DecodeString(v) diff --git a/proto/vulcanize/registry/v1beta1/registry.proto b/proto/vulcanize/registry/v1beta1/registry.proto index b2c340f2..7d4f9824 100644 --- a/proto/vulcanize/registry/v1beta1/registry.proto +++ b/proto/vulcanize/registry/v1beta1/registry.proto @@ -5,7 +5,6 @@ import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; import "gogoproto/gogo.proto"; import "cosmos/base/v1beta1/coin.proto"; -import "google/protobuf/any.proto"; option go_package = "github.com/cerc-io/laconicd/x/registry/types"; @@ -131,4 +130,4 @@ message BlockChangeSet { message AuctionBidInfo { string auction_id = 1 [(gogoproto.moretags) = "json:\"auctionID\" yaml:\"auctionID\""]; string bidder_address = 2 [(gogoproto.moretags) = "json:\"bidderAddress\" yaml:\"bidderAddress\""]; -} \ No newline at end of file +} diff --git a/x/registry/client/testutil/grpc.go b/x/registry/client/testutil/grpc.go index 04ae5c39..a180deea 100644 --- a/x/registry/client/testutil/grpc.go +++ b/x/registry/client/testutil/grpc.go @@ -62,7 +62,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryParams() { } } -// nolint: all +//nolint:all func (s *IntegrationTestSuite) TestGRPCQueryWhoIs() { val := s.network.Validators[0] sr := s.Require() @@ -182,7 +182,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryLookup() { } } -// nolint: all +//nolint:all func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() { val := s.network.Validators[0] sr := s.Require() @@ -254,7 +254,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() { } } -// nolint: all +//nolint:all func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() { val := s.network.Validators[0] sr := s.Require() @@ -326,7 +326,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() { } } -// nolint: all +//nolint:all func (s *IntegrationTestSuite) TestGRPCQueryListRecords() { val := s.network.Validators[0] sr := s.Require() diff --git a/x/registry/keeper/keeper.go b/x/registry/keeper/keeper.go index 2f1af266..ada95b87 100644 --- a/x/registry/keeper/keeper.go +++ b/x/registry/keeper/keeper.go @@ -337,7 +337,10 @@ func (k Keeper) PutRecord(ctx sdk.Context, record types.Record) { func (k Keeper) processAttributes(ctx sdk.Context, attrs map[string]any, id string, prefix string) error { for key, value := range attrs { if subRecord, ok := value.(map[string]any); ok { - k.processAttributes(ctx, subRecord, id, key) + err := k.processAttributes(ctx, subRecord, id, key) + if err != nil { + return err + } } else { indexKey := GetAttributesIndexKey(prefix+key, value) if err := k.SetAttributeMapping(ctx, indexKey, id); err != nil {