mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
Regular → Executable
+36
-3
@@ -1,18 +1,26 @@
|
||||
// Package app provides encoding utilities for the Sonr blockchain application.
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/x/tx/signing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/sonr-io/snrd/app/params"
|
||||
"github.com/sonr-io/sonr/app/params"
|
||||
)
|
||||
|
||||
// MakeEncodingConfig creates a new EncodingConfig with all modules registered. For testing only
|
||||
// MakeEncodingConfig creates a new EncodingConfig with all modules registered.
|
||||
// This function is intended for testing purposes only, as it creates a temporary
|
||||
// application instance to extract the encoding configuration.
|
||||
func MakeEncodingConfig(t testing.TB) params.EncodingConfig {
|
||||
t.Helper()
|
||||
// we "pre"-instantiate the application for getting the injected/configured encoding configuration
|
||||
@@ -23,11 +31,15 @@ func MakeEncodingConfig(t testing.TB) params.EncodingConfig {
|
||||
nil,
|
||||
true,
|
||||
simtestutil.NewAppOptionsWithFlagHome(t.TempDir()),
|
||||
EVMAppOptions,
|
||||
)
|
||||
return makeEncodingConfig(tempApp)
|
||||
}
|
||||
|
||||
func makeEncodingConfig(tempApp *SonrApp) params.EncodingConfig {
|
||||
// makeEncodingConfig extracts the encoding configuration from a ChainApp instance.
|
||||
// It returns an EncodingConfig struct containing the interface registry, codec,
|
||||
// transaction config, and amino codec.
|
||||
func makeEncodingConfig(tempApp *ChainApp) params.EncodingConfig {
|
||||
encodingConfig := params.EncodingConfig{
|
||||
InterfaceRegistry: tempApp.InterfaceRegistry(),
|
||||
Codec: tempApp.AppCodec(),
|
||||
@@ -36,3 +48,24 @@ func makeEncodingConfig(tempApp *SonrApp) params.EncodingConfig {
|
||||
}
|
||||
return encodingConfig
|
||||
}
|
||||
|
||||
// GetInterfaceRegistry creates and returns a new interface registry with proper
|
||||
// address codecs configured. This registry is used for protobuf Any type
|
||||
// registration and message routing.
|
||||
func GetInterfaceRegistry() types.InterfaceRegistry {
|
||||
interfaceRegistry, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
|
||||
ProtoFiles: proto.HybridResolver,
|
||||
SigningOptions: signing.Options{
|
||||
AddressCodec: address.Bech32Codec{
|
||||
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
|
||||
},
|
||||
ValidatorAddressCodec: address.Bech32Codec{
|
||||
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return interfaceRegistry
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user