Skip to content

Commit

Permalink
fix: merge conflict resolution errors, config
Browse files Browse the repository at this point in the history
  • Loading branch information
JeancarloBarrios committed Nov 25, 2024
1 parent 920c0c4 commit 227e3a6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
52 changes: 52 additions & 0 deletions types/registry/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package registry

import (
"sync"

"github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"

"cosmossdk.io/x/tx/signing"
)

var (
mergedRegistryOnce sync.Once
mergedRegistry *protoregistry.Files
_ signing.ProtoFileResolver = lazyProtoRegistry{}
)

// lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry.
type lazyProtoRegistry struct{}

func getRegistry() *protoregistry.Files {
var err error
mergedRegistryOnce.Do(func() {
mergedRegistry, err = proto.MergedRegistry()
if err != nil {
panic(err)
}
})
return mergedRegistry
}

func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) {
reg := getRegistry()
return reg.FindFileByPath(s)
}

func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) {
reg := getRegistry()
return reg.FindDescriptorByName(name)
}

func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) {
reg := getRegistry()
reg.RangeFiles(f)
}

// MergedProtoRegistry returns a lazy loading wrapper around the global protobuf registry, a merged registry
// containing both gogo proto and pulsar types.
func MergedProtoRegistry() signing.ProtoFileResolver {
return lazyProtoRegistry{}
}
12 changes: 5 additions & 7 deletions x/auth/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ package types

import (
"encoding/json"
"errors"
"fmt"
"sort"

"github.com/cosmos/gogoproto/proto"
gogoprotoany "github.com/cosmos/gogoproto/types/any"
proto "github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
)

var _ gogoprotoany.UnpackInterfacesMessage = GenesisState{}
var _ types.UnpackInterfacesMessage = GenesisState{}

// RandomGenesisAccountsFn defines the function required to generate custom account types
type RandomGenesisAccountsFn func(simState *module.SimulationState) GenesisAccounts
Expand All @@ -33,7 +31,7 @@ func NewGenesisState(params Params, accounts GenesisAccounts) *GenesisState {
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (g GenesisState) UnpackInterfaces(unpacker gogoprotoany.AnyUnpacker) error {
func (g GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error {
for _, any := range g.Accounts {
var account GenesisAccount
err := unpacker.UnpackAny(any, &account)
Expand Down Expand Up @@ -138,7 +136,7 @@ func ValidateGenAccounts(accounts GenesisAccounts) error {

// check account specific validation
if err := acc.Validate(); err != nil {
return fmt.Errorf("invalid account found in genesis state; address: %s, error: %w", addrStr, err)
return fmt.Errorf("invalid account found in genesis state; address: %s, error: %s", addrStr, err.Error())
}
}
return nil
Expand Down Expand Up @@ -188,7 +186,7 @@ func UnpackAccounts(accountsAny []*types.Any) (GenesisAccounts, error) {
for i, any := range accountsAny {
acc, ok := any.GetCachedValue().(GenesisAccount)
if !ok {
return nil, errors.New("expected genesis account")
return nil, fmt.Errorf("expected genesis account")
}
accounts[i] = acc
}
Expand Down

0 comments on commit 227e3a6

Please sign in to comment.