Fix lint errors

This commit is contained in:
neeraj 2024-01-10 18:03:54 +05:30 committed by Nabarun
parent cffaf547a9
commit f51de891e9
4 changed files with 19 additions and 16 deletions

View File

@ -24,6 +24,8 @@ import (
"github.com/ethereum/go-ethereum/signer/core/apitypes" "github.com/ethereum/go-ethereum/signer/core/apitypes"
) )
const bytesStr = "bytes"
// WrapTxToTypedData is an ultimate method that wraps Amino-encoded Cosmos Tx JSON data // WrapTxToTypedData is an ultimate method that wraps Amino-encoded Cosmos Tx JSON data
// into an EIP712-compatible TypedData request. // into an EIP712-compatible TypedData request.
func WrapTxToTypedData( func WrapTxToTypedData(
@ -33,7 +35,6 @@ func WrapTxToTypedData(
data []byte, data []byte,
feeDelegation *FeeDelegationOptions, feeDelegation *FeeDelegationOptions,
) (apitypes.TypedData, error) { ) (apitypes.TypedData, error) {
domain := apitypes.TypedDataDomain{ domain := apitypes.TypedDataDomain{
Name: "Cosmos Web3", Name: "Cosmos Web3",
Version: "1.0.0", Version: "1.0.0",
@ -298,7 +299,7 @@ func traverseFields(
} }
// convert uint8[] to bytes // convert uint8[] to bytes
if fieldType.Kind() == reflect.Uint8 { if fieldType.Kind() == reflect.Uint8 {
ethTyp = "bytes" ethTyp = bytesStr
} }
} }
if prefix == typeDefPrefix { if prefix == typeDefPrefix {
@ -448,7 +449,7 @@ func typToEth(typ reflect.Type) string {
ethName := typToEth(typ.Elem()) ethName := typToEth(typ.Elem())
if len(ethName) > 0 { if len(ethName) > 0 {
if ethName == "uint8" { if ethName == "uint8" {
return "bytes" return bytesStr
} }
return ethName + "[]" return ethName + "[]"
} }
@ -495,7 +496,9 @@ func patchTxData(data map[string]any, schema apitypes.Types, rootType string) er
for _, field := range schema[rootType] { for _, field := range schema[rootType] {
encType := field.Type encType := field.Type
encValue := data[field.Name] encValue := data[field.Name]
if encType[len(encType)-1:] == "]" {
switch {
case encType[len(encType)-1:] == "]":
arrayValue, ok := encValue.([]interface{}) arrayValue, ok := encValue.([]interface{})
if !ok { if !ok {
return dataMismatchError(encType, encValue) return dataMismatchError(encType, encValue)
@ -523,8 +526,7 @@ func patchTxData(data map[string]any, schema apitypes.Types, rootType string) er
arrayValue[i] = converted arrayValue[i] = converted
} }
} }
case schema[encType] != nil:
} else if schema[encType] != nil {
mapValue, ok := encValue.(map[string]interface{}) mapValue, ok := encValue.(map[string]interface{})
if !ok { if !ok {
return dataMismatchError(encType, encValue) return dataMismatchError(encType, encValue)
@ -533,7 +535,7 @@ func patchTxData(data map[string]any, schema apitypes.Types, rootType string) er
if err != nil { if err != nil {
return err return err
} }
} else { default:
converted, err := handleConversion(encType, encValue) converted, err := handleConversion(encType, encValue)
if err != nil { if err != nil {
return err 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) { func handleConversion(encType string, encValue any) (any, error) {
switch encType { if encType == bytesStr {
case "bytes":
// Protobuf encodes byte strings in base64 // Protobuf encodes byte strings in base64
if v, ok := encValue.(string); ok { if v, ok := encValue.(string); ok {
return base64.StdEncoding.DecodeString(v) return base64.StdEncoding.DecodeString(v)

View File

@ -5,7 +5,6 @@ import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
import "gogoproto/gogo.proto"; import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto"; import "cosmos/base/v1beta1/coin.proto";
import "google/protobuf/any.proto";
option go_package = "github.com/cerc-io/laconicd/x/registry/types"; option go_package = "github.com/cerc-io/laconicd/x/registry/types";

View File

@ -62,7 +62,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryParams() {
} }
} }
// nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryWhoIs() { func (s *IntegrationTestSuite) TestGRPCQueryWhoIs() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()
@ -182,7 +182,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryLookup() {
} }
} }
// nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() { func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()
@ -254,7 +254,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() {
} }
} }
// nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() { func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()
@ -326,7 +326,7 @@ func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() {
} }
} }
// nolint: all //nolint:all
func (s *IntegrationTestSuite) TestGRPCQueryListRecords() { func (s *IntegrationTestSuite) TestGRPCQueryListRecords() {
val := s.network.Validators[0] val := s.network.Validators[0]
sr := s.Require() sr := s.Require()

View File

@ -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 { func (k Keeper) processAttributes(ctx sdk.Context, attrs map[string]any, id string, prefix string) error {
for key, value := range attrs { for key, value := range attrs {
if subRecord, ok := value.(map[string]any); ok { 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 { } else {
indexKey := GetAttributesIndexKey(prefix+key, value) indexKey := GetAttributesIndexKey(prefix+key, value)
if err := k.SetAttributeMapping(ctx, indexKey, id); err != nil { if err := k.SetAttributeMapping(ctx, indexKey, id); err != nil {