Skip to content

Commit

Permalink
feat: fix interface registry
Browse files Browse the repository at this point in the history
  • Loading branch information
kienn6034 committed Mar 28, 2024
1 parent 983f896 commit 71c9228
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 25 deletions.
49 changes: 39 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"path/filepath"

nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/std"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/gogoproto/proto"
wasm08 "github.com/cosmos/ibc-go/modules/light-clients/08-wasm"
wasm08keeper "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/keeper"
tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
Expand All @@ -21,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
Expand All @@ -38,11 +41,11 @@ import (
"github.com/notional-labs/composable/v6/app/upgrades/v6_5_0"

// bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

"cosmossdk.io/x/evidence"
evidencetypes "cosmossdk.io/x/evidence/types"
"cosmossdk.io/x/feegrant"
feegrantmodule "cosmossdk.io/x/feegrant/module"
"cosmossdk.io/x/tx/signing"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -241,12 +244,13 @@ type ComposableApp struct {
cdc *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
txConfig client.TxConfig
invCheckPeriod uint

invCheckPeriod uint

mm *module.Manager
sm *module.SimulationManager
configurator module.Configurator
mm *module.Manager
basicModuleManger module.BasicManager
sm *module.SimulationManager
configurator module.Configurator
}

// RUN GOSEC
Expand All @@ -265,22 +269,43 @@ func NewComposableApp(
devnetGov *string,
baseAppOptions ...func(*baseapp.BaseApp),
) *ComposableApp {
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.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)
}

appCodec := codec.NewProtoCodec(interfaceRegistry)
legacyAmino := codec.NewLegacyAmino()
txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes)

std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)

bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(encodingConfig.TxConfig.TxEncoder())
bApp.SetTxEncoder(txConfig.TxEncoder())

app := &ComposableApp{
BaseApp: bApp,
AppKeepers: keepers.AppKeepers{},
cdc: cdc,
cdc: legacyAmino,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
txConfig: txConfig,
}

app.InitSpecialKeepers(
Expand Down Expand Up @@ -361,6 +386,10 @@ func NewComposableApp(
// this line is used by starport scaffolding # stargate/app/appModule
)

app.basicModuleManger = ModuleBasics
app.basicModuleManger.RegisterLegacyAminoCodec(legacyAmino)
app.basicModuleManger.RegisterInterfaces(interfaceRegistry)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
Expand Down
21 changes: 20 additions & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package app

import (
"cosmossdk.io/x/tx/signing"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/gogoproto/proto"
)

// This data structure (EncodingConfig) is heavily inspired by Quicksilver. https://github.com/ingenuity-build/quicksilver/blob/main/app/encoding.go
Expand All @@ -19,7 +23,22 @@ type EncodingConfig struct {
// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
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)
}

marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

Expand Down
13 changes: 11 additions & 2 deletions cmd/centaurid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

"github.com/cosmos/cosmos-sdk/types/module"
"github.com/notional-labs/composable/v6/app"
// "github.com/notional-labs/composable/v6/app/params"
// this line is used by starport scaffolding # stargate/root/import
Expand Down Expand Up @@ -192,6 +193,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {
// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
server.StatusCommand(),
genesisCommand(encodingConfig.TxConfig, app.ModuleBasics),
queryCommand(),
txCommand(),
keys.Commands(),
Expand Down Expand Up @@ -250,8 +252,6 @@ func txCommand() *cobra.Command {
flags.LineBreak,
)

app.ModuleBasics.AddTxCommands(cmd)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")
return cmd
}

Expand Down Expand Up @@ -343,3 +343,12 @@ func (a appCreator) appExport(

return anApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
}

func genesisCommand(txConfig client.TxConfig, basicManager module.BasicManager, cmds ...*cobra.Command) *cobra.Command {
cmd := genutilcli.Commands(txConfig, basicManager, app.DefaultNodeHome)

for _, subCmd := range cmds {
cmd.AddCommand(subCmd)
}
return cmd
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ require (
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 v8.0.2
github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.0
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc
github.com/cosmos/ibc-go/v8 v8.1.1
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d
github.com/cosmos/ibc-go/v8 v8.0.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.4
github.com/golangci/golangci-lint v1.52.0
Expand Down Expand Up @@ -372,4 +372,5 @@ replace (
github.com/prometheus/common => github.com/prometheus/common v0.47.0

github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,10 @@ github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.0 h1:nKP2+Rzlz2iyvTosY5mvP+
github.com/cosmos/ibc-apps/modules/async-icq/v8 v8.0.0/go.mod h1:D3Q380FpWRFtmUQWLosPxachi6w24Og2t5u/Tww5wtY=
github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE=
github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc h1:Y8ooMzd4YJGCSKRTMTMatp1/09bJPdnAmnPoM/ff2vw=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240307202658-3f7320cd66dc/go.mod h1:TSp/mbQtVR4lwh+69Q0etnVB6JeZl4Rym4F4bRtStHI=
github.com/cosmos/ibc-go/v8 v8.1.1 h1:N2+GA86yACcXnKWCKtqdbCwP0/Eo8pH79+6e7TicULU=
github.com/cosmos/ibc-go/v8 v8.1.1/go.mod h1:o1ipS95xpdjqNcB8Drq0eI3Sn4FRLigjll42ec1ECuU=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d h1:F4mhR61RZU4KJ38n5CeZrnNINU/KxMfP1sKfk5fTlHA=
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.1.1-0.20231213092650-57fcdb9a9a9d/go.mod h1:u2FXNcSxzzn5IwjWBA51HKMwiYMRK6/G35VmSJULhP0=
github.com/cosmos/ibc-go/v8 v8.0.0 h1:QKipnr/NGwc+9L7NZipURvmSIu+nw9jOIWTJuDBqOhg=
github.com/cosmos/ibc-go/v8 v8.0.0/go.mod h1:C6IiJom0F3cIQCD5fKwVPDrDK9j/xTu563AWuOmXois=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
Expand Down
12 changes: 6 additions & 6 deletions scripts/testnode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ TRACE=""
# remove existing daemon
rm -rf ~/.banksy*

centaurid config keyring-backend $KEYRING
centaurid config chain-id $CHAINID
# centaurid config keyring-backend $KEYRING
# centaurid config chain-id $CHAINID

# if $KEY exists it should be deleted
echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | centaurid keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover

centaurid init $MONIKER --chain-id $CHAINID
centaurid init $MONIKER --chain-id $CHAINID > /dev/null 2>&1


# Allocate genesis accounts (cosmos formatted addresses)
centaurid add-genesis-account $KEY 100000000000000000000000000stake --keyring-backend $KEYRING
centaurid genesis add-genesis-account $KEY 100000000000000000000000000stake --keyring-backend $KEYRING

# Sign genesis transaction
centaurid gentx $KEY 1000000000000000000000stake --keyring-backend $KEYRING --chain-id $CHAINID

centaurid genesis gentx $KEY 1000000000000000000000stake --keyring-backend $KEYRING --chain-id $CHAINID
# Collect genesis tx
centaurid collect-gentxs

Expand Down

0 comments on commit 71c9228

Please sign in to comment.