github.com/cosmos/cosmos-sdk@v0.50.10/types/registry/registry.go (about)

     1  package registry
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/cosmos/gogoproto/proto"
     7  	"google.golang.org/protobuf/reflect/protoreflect"
     8  	"google.golang.org/protobuf/reflect/protoregistry"
     9  
    10  	"cosmossdk.io/x/tx/signing"
    11  )
    12  
    13  var (
    14  	mergedRegistryOnce sync.Once
    15  	mergedRegistry     *protoregistry.Files
    16  	_                  signing.ProtoFileResolver = lazyProtoRegistry{}
    17  )
    18  
    19  // lazyProtoRegistry is a lazy loading wrapper around the global protobuf registry.
    20  type lazyProtoRegistry struct{}
    21  
    22  func getRegistry() *protoregistry.Files {
    23  	var err error
    24  	mergedRegistryOnce.Do(func() {
    25  		mergedRegistry, err = proto.MergedRegistry()
    26  		if err != nil {
    27  			panic(err)
    28  		}
    29  	})
    30  	return mergedRegistry
    31  }
    32  
    33  func (l lazyProtoRegistry) FindFileByPath(s string) (protoreflect.FileDescriptor, error) {
    34  	reg := getRegistry()
    35  	return reg.FindFileByPath(s)
    36  }
    37  
    38  func (l lazyProtoRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) {
    39  	reg := getRegistry()
    40  	return reg.FindDescriptorByName(name)
    41  }
    42  
    43  func (l lazyProtoRegistry) RangeFiles(f func(protoreflect.FileDescriptor) bool) {
    44  	reg := getRegistry()
    45  	reg.RangeFiles(f)
    46  }
    47  
    48  // MergedProtoRegistry returns a lazy loading wrapper around the global protobuf registry, a merged registry
    49  // containing both gogo proto and pulsar types.
    50  func MergedProtoRegistry() signing.ProtoFileResolver {
    51  	return lazyProtoRegistry{}
    52  }