-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,572 additions
and
492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/std" | ||
"github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
) | ||
|
||
type ModuleRegister interface { | ||
RegisterLegacyAminoCodec(*codec.LegacyAmino) | ||
RegisterInterfaces(codectypes.InterfaceRegistry) | ||
} | ||
|
||
// Config specifies the concrete encoding types to use for a given app. | ||
// This is provided for compatibility between protobuf and amino implementations. | ||
type EncodingConfig struct { | ||
InterfaceRegistry codectypes.InterfaceRegistry | ||
Codec codec.Codec | ||
TxConfig client.TxConfig | ||
Amino *codec.LegacyAmino | ||
} | ||
|
||
// MakeConfig returns an encoding config for the app. | ||
func MakeEncodingConfig(moduleRegisters ...ModuleRegister) EncodingConfig { | ||
interfaceRegistry := codectypes.NewInterfaceRegistry() | ||
amino := codec.NewLegacyAmino() | ||
|
||
// Register the standard types from the Cosmos SDK on interfaceRegistry and | ||
// amino. | ||
std.RegisterInterfaces(interfaceRegistry) | ||
std.RegisterLegacyAminoCodec(amino) | ||
|
||
// Register types from the moduleRegisters on interfaceRegistry and amino. | ||
for _, moduleRegister := range moduleRegisters { | ||
moduleRegister.RegisterInterfaces(interfaceRegistry) | ||
moduleRegister.RegisterLegacyAminoCodec(amino) | ||
} | ||
|
||
protoCodec := codec.NewProtoCodec(interfaceRegistry) | ||
txConfig := tx.NewTxConfig(protoCodec, tx.DefaultSignModes) | ||
|
||
return EncodingConfig{ | ||
InterfaceRegistry: interfaceRegistry, | ||
Codec: protoCodec, | ||
TxConfig: txConfig, | ||
Amino: amino, | ||
} | ||
} |
Oops, something went wrong.