Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package app
import (
"context"
"fmt"
appparams "github.com/sei-protocol/sei-chain/app/params"
"io"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -92,10 +93,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/tendermint/starport/starport/pkg/cosmoscmd"
"github.com/tendermint/starport/starport/pkg/openapiconsole"

"github.com/sei-protocol/sei-chain/docs"
"github.com/sei-protocol/sei-chain/utils/tracing"

dexmodule "github.com/sei-protocol/sei-chain/x/dex"
Expand Down Expand Up @@ -184,10 +181,24 @@ var (
allowedReceivingModAcc = map[string]bool{
oracletypes.ModuleName: true,
}

// WasmProposalsEnabled enables all x/wasm proposals when it's value is "true"
// and EnableSpecificWasmProposals is empty. Otherwise, all x/wasm proposals
// are disabled.
WasmProposalsEnabled = "true"

// EnableSpecificWasmProposals, if set, must be comma-separated list of values
// that are all a subset of "EnableAllProposals", which takes precedence over
// WasmProposalsEnabled.
//
// See: https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificWasmProposals = ""

// EmptyWasmOpts defines a type alias for a list of wasm options.
EmptyWasmOpts []wasm.Option
)

var (
_ cosmoscmd.App = (*App)(nil)
_ servertypes.Application = (*App)(nil)
_ simapp.App = (*App)(nil)
)
Expand All @@ -201,6 +212,28 @@ func init() {
DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName)
}

// GetWasmEnabledProposals parses the WasmProposalsEnabled and
// EnableSpecificWasmProposals values to produce a list of enabled proposals to
// pass into the application.
func GetWasmEnabledProposals() []wasm.ProposalType {
if EnableSpecificWasmProposals == "" {
if WasmProposalsEnabled == "true" {
return wasm.EnableAllProposals
}

return wasm.DisableAllProposals
}

chunks := strings.Split(EnableSpecificWasmProposals, ",")

proposals, err := wasm.ConvertToProposals(chunks)
if err != nil {
panic(err)
}

return proposals
}

// App extends an ABCI application, but with most of its parameters exported.
// They are exported for convenience in creating helper functions, as object
// capabilities aren't needed for testing.
Expand Down Expand Up @@ -266,12 +299,12 @@ func New(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig cosmoscmd.EncodingConfig,
encodingConfig appparams.EncodingConfig,
enabledProposals []wasm.ProposalType,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) cosmoscmd.App {
) *App {
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
Expand Down Expand Up @@ -789,10 +822,6 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
// Register legacy and grpc-gateway routes for all modules.
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// register app's OpenAPI routes.
apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs)))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(AppName, "/static/openapi.yml"))
}

// RegisterTxService implements the Application.RegisterTxService method.
Expand Down
16 changes: 16 additions & 0 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app

import (
"github.com/cosmos/cosmos-sdk/std"
"github.com/sei-protocol/sei-chain/app/params"
)

// MakeEncodingConfig creates an EncodingConfig for testing.
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
24 changes: 24 additions & 0 deletions app/params/amino.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build test_amino
// +build test_amino

package params

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
cdc := codec.New()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewAminoCodec(cdc)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: authtypes.StdTxConfig{Cdc: cdc},
Amino: cdc,
}
}
74 changes: 74 additions & 0 deletions app/params/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package params

import (
"github.com/cosmos/cosmos-sdk/types/address"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const (
HumanCoinUnit = "sei"
BaseCoinUnit = "usei"
UseiExponent = 6

DefaultBondDenom = BaseCoinUnit

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address.
Bech32PrefixAccAddr = "sei"
)

var (
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key.
Bech32PrefixAccPub = Bech32PrefixAccAddr + "pub"
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address.
Bech32PrefixValAddr = Bech32PrefixAccAddr + "valoper"
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key.
Bech32PrefixValPub = Bech32PrefixAccAddr + "valoperpub"
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address.
Bech32PrefixConsAddr = Bech32PrefixAccAddr + "valcons"
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key.
Bech32PrefixConsPub = Bech32PrefixAccAddr + "valconspub"
)

func init() {
SetAddressPrefixes()
RegisterDenoms()
}

func RegisterDenoms() {
err := sdk.RegisterDenom(HumanCoinUnit, sdk.OneDec())
if err != nil {
panic(err)
}
err = sdk.RegisterDenom(BaseCoinUnit, sdk.NewDecWithPrec(1, UseiExponent))
if err != nil {
panic(err)
}
}

func SetAddressPrefixes() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)

// This is copied from the cosmos sdk v0.43.0-beta1
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}

if len(bytes) > address.MaxAddrLen {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}

// TODO: Do we want to allow addresses of lengths other than 20 and 32 bytes?
if len(bytes) != 20 && len(bytes) != 32 {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}

return nil
})
}
19 changes: 19 additions & 0 deletions app/params/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Package params defines the simulation parameters in the simapp.

It contains the default weights used for each transaction used on the module's
simulation. These weights define the chance for a transaction to be simulated at
any gived operation.

You can repace the default values for the weights by providing a params.json
file with the weights defined for each of the transaction operations:

{
"op_weight_msg_send": 60,
"op_weight_msg_delegate": 100,
}

In the example above, the `MsgSend` has 60% chance to be simulated, while the
`MsgDelegate` will always be simulated.
*/
package params
16 changes: 16 additions & 0 deletions app/params/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package params

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
)

// EncodingConfig 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 types.InterfaceRegistry
Marshaler codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
25 changes: 25 additions & 0 deletions app/params/proto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build !test_amino
// +build !test_amino

package params

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}
}
Loading