Skip to content

Commit

Permalink
smaller app.go (#1009)
Browse files Browse the repository at this point in the history
* create keys.go and blocked.go to make app.go easier

* flatten NewOsmosisApp

* Update app.go

* fmt

* eliminate keys.go and move store keys to keepers.go
  • Loading branch information
faddat authored Mar 3, 2022
1 parent db5fe2b commit 265890f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 123 deletions.
141 changes: 18 additions & 123 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

// Authz: Authorization for accounts to perform actions on behalf of other accounts.
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"

// Bank: allows users to transfer tokens
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

// Capability: allows developers to atomically define what a module can and cannot do
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand All @@ -66,29 +59,15 @@ import (

// Evidence handling for double signing, misbehaviour, etc.
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"

// Governance: Allows stakeholders to make decisions concering a Cosmos-SDK blockchain's economy and development
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

// Params: Parameters that are always available
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

// Slashing:
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"

// Staking: Allows the Tendermint validator set to be chosen based on bonded stake.
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

// Upgrade: Software upgrades handling and coordination.
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

// IBC Transfer: Defines the "transfer" IBC port
transfer "github.com/cosmos/ibc-go/v2/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"

// IBC: Inter-blockchain communication
ibchost "github.com/cosmos/ibc-go/v2/modules/core/24-host"

// Osmosis application prarmeters
appparams "github.com/osmosis-labs/osmosis/v7/app/params"
Expand All @@ -99,38 +78,11 @@ import (
v7 "github.com/osmosis-labs/osmosis/v7/app/upgrades/v7"
_ "github.com/osmosis-labs/osmosis/v7/client/docs/statik"

// Modules that live in the Osmosis repository and are specific to Osmosis
claimtypes "github.com/osmosis-labs/osmosis/v7/x/claim/types"

// Epochs: gives Osmosis a sense of "clock time" so that events can be based on days instead of "number of blocks"
epochstypes "github.com/osmosis-labs/osmosis/v7/x/epochs/types"

// Generalized Automated Market Maker
gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types"

// Incentives: Allows Osmosis and foriegn chain communities to incentivize users to provide liquidity
incentivestypes "github.com/osmosis-labs/osmosis/v7/x/incentives/types"

// Lockup: allows tokens to be locked (made non-transferrable)
lockuptypes "github.com/osmosis-labs/osmosis/v7/x/lockup/types"

// Mint: Our modified version of github.com/cosmos/cosmos-sdk/x/mint
minttypes "github.com/osmosis-labs/osmosis/v7/x/mint/types"

// Pool incentives:
poolincentivestypes "github.com/osmosis-labs/osmosis/v7/x/pool-incentives/types"

// Superfluid: Allows users to stake gamm (bonded liquidity)
superfluidtypes "github.com/osmosis-labs/osmosis/v7/x/superfluid/types"

// Txfees: Allows Osmosis to charge transaction fees without harming IBC user experience
txfeestypes "github.com/osmosis-labs/osmosis/v7/x/txfees/types"

// Wasm: Allows Osmosis to interact with web assembly smart contracts
"github.com/CosmWasm/wasmd/x/wasm"

// Modules related to bech32-ibc, which allows new ibc funcationality based on the bech32 prefix of addresses
bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types"
)

const appName = "OsmosisApp"
Expand Down Expand Up @@ -226,9 +178,17 @@ func init() {

// NewOsmosis returns a reference to an initialized Osmosis.
func NewOsmosisApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig, appOpts servertypes.AppOptions,
wasmEnabledProposals []wasm.ProposalType, wasmOpts []wasm.Option,
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig appparams.EncodingConfig,
appOpts servertypes.AppOptions,
wasmEnabledProposals []wasm.ProposalType,
wasmOpts []wasm.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *OsmosisApp {

Expand All @@ -243,32 +203,9 @@ func NewOsmosisApp(

// Define what keys will be used in the cosmos-sdk key/value store.
// Cosmos-SDK modules each have a "key" that allows the application to reference what they've stored on the chain.
keys := sdk.NewKVStoreKeys(
authtypes.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
minttypes.StoreKey,
distrtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
paramstypes.StoreKey,
ibchost.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
gammtypes.StoreKey,
lockuptypes.StoreKey,
claimtypes.StoreKey,
incentivestypes.StoreKey,
epochstypes.StoreKey,
poolincentivestypes.StoreKey,
authzkeeper.StoreKey,
txfeestypes.StoreKey,
superfluidtypes.StoreKey,
bech32ibctypes.StoreKey,
wasm.StoreKey,
)
// Keys are in keys.go to kep app.go as brief as possible.
keys := sdk.NewKVStoreKeys(KVStoreKeys()...)

// Define transient store keys
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)

Expand Down Expand Up @@ -364,8 +301,10 @@ func NewOsmosisApp(
appOpts,
wasmConfig,
keys[wasm.StoreKey],
app.AccountKeeper, app.BankKeeper,
app.TxFeesKeeper, app.GAMMKeeper,
app.AccountKeeper,
app.BankKeeper,
app.TxFeesKeeper,
app.GAMMKeeper,
ante.DefaultSigVerificationGasConsumer,
encodingConfig.TxConfig.SignModeHandler(),
app.IBCKeeper.ChannelKeeper,
Expand Down Expand Up @@ -428,50 +367,6 @@ func (app *OsmosisApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
}

// BlockedAddrs returns all the app's module account addresses that are not
// allowed to receive external tokens.
func (app *OsmosisApp) BlockedAddrs() map[string]bool {
blockedAddrs := make(map[string]bool)
for acc := range maccPerms {
blockedAddrs[authtypes.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
}

// We block all OFAC-blocked ETH addresses from receiving tokens as well
// The list is sourced from: https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml
ofacRawEthAddrs := []string{
"0x7F367cC41522cE07553e823bf3be79A889DEbe1B",
"0xd882cfc20f52f2599d84b8e8d58c7fb62cfe344b",
"0x901bb9583b24d97e995513c6778dc6888ab6870e",
"0xa7e5d5a720f06526557c513402f2e6b5fa20b008",
"0x8576acc5c05d6ce88f4e49bf65bdf0c62f91353c",
"0x1da5821544e25c636c1417ba96ade4cf6d2f9b5a",
"0x7Db418b5D567A4e0E8c59Ad71BE1FcE48f3E6107",
"0x72a5843cc08275C8171E582972Aa4fDa8C397B2A",
"0x7F19720A857F834887FC9A7bC0a0fBe7Fc7f8102",
"0x9f4cda013e354b8fc285bf4b9a60460cee7f7ea9",
"0x3cbded43efdaf0fc77b9c55f6fc9988fcc9b757d",
"0x2f389ce8bd8ff92de3402ffce4691d17fc4f6535",
"0x19aa5fe80d33a56d56c78e82ea5e50e5d80b4dff",
"0xe7aa314c77f4233c18c6cc84384a9247c0cf367b",
"0x308ed4b7b49797e1a98d3818bff6fe5385410370",
"0x2f389ce8bd8ff92de3402ffce4691d17fc4f6535",
"0x19aa5fe80d33a56d56c78e82ea5e50e5d80b4dff",
"0x67d40EE1A85bf4a4Bb7Ffae16De985e8427B6b45",
"0x6f1ca141a28907f78ebaa64fb83a9088b02a8352",
"0x6acdfba02d390b97ac2b2d42a63e85293bcc160e",
"0x48549a34ae37b12f6a30566245176994e17c6b4a",
"0x5512d943ed1f7c8a43f3435c85f7ab68b30121b0",
"0xc455f7fd3e0e12afd51fba5c106909934d8a0e4a",
"0xfec8a60023265364d066a1212fde3930f6ae8da7",
}
for _, addr := range ofacRawEthAddrs {
blockedAddrs[addr] = true
blockedAddrs[strings.ToLower(addr)] = true
}

return blockedAddrs
}

// LegacyAmino returns SimApp's amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
Expand Down
51 changes: 51 additions & 0 deletions app/blocked.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package app

import (
"strings"

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

// BlockedAddrs returns all the app's module account addresses that are not
// allowed to receive external tokens.
func (app *OsmosisApp) BlockedAddrs() map[string]bool {
blockedAddrs := make(map[string]bool)
for acc := range maccPerms {
blockedAddrs[authtypes.NewModuleAddress(acc).String()] = !allowedReceivingModAcc[acc]
}

// We block all OFAC-blocked ETH addresses from receiving tokens as well
// The list is sourced from: https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml
ofacRawEthAddrs := []string{
"0x7F367cC41522cE07553e823bf3be79A889DEbe1B",
"0xd882cfc20f52f2599d84b8e8d58c7fb62cfe344b",
"0x901bb9583b24d97e995513c6778dc6888ab6870e",
"0xa7e5d5a720f06526557c513402f2e6b5fa20b008",
"0x8576acc5c05d6ce88f4e49bf65bdf0c62f91353c",
"0x1da5821544e25c636c1417ba96ade4cf6d2f9b5a",
"0x7Db418b5D567A4e0E8c59Ad71BE1FcE48f3E6107",
"0x72a5843cc08275C8171E582972Aa4fDa8C397B2A",
"0x7F19720A857F834887FC9A7bC0a0fBe7Fc7f8102",
"0x9f4cda013e354b8fc285bf4b9a60460cee7f7ea9",
"03cbded43efdaf0fc77b9c55f6fc9988fcc9b757d",
"0x2f389ce8bd8ff92de3402ffce4691d17fc4f6535",
"0x19aa5fe80d33a56d56c78e82ea5e50e5d80b4dff",
"0xe7aa314c77f4233c18c6cc84384a9247c0cf367b",
"0x308ed4b7b49797e1a98d3818bff6fe5385410370",
"0x2f389ce8bd8ff92de3402ffce4691d17fc4f6535",
"0x19aa5fe80d33a56d56c78e82ea5e50e5d80b4dff",
"0x67d40EE1A85bf4a4Bb7Ffae16De985e8427B6b45",
"0x6f1ca141a28907f78ebaa64fb83a9088b02a8352",
"0x6acdfba02d390b97ac2b2d42a63e85293bcc160e",
"0x48549a34ae37b12f6a30566245176994e17c6b4a",
"0x5512d943ed1f7c8a43f3435c85f7ab68b30121b0",
"0xc455f7fd3e0e12afd51fba5c106909934d8a0e4a",
"0xfec8a60023265364d066a1212fde3930f6ae8da7",
}
for _, addr := range ofacRawEthAddrs {
blockedAddrs[addr] = true
blockedAddrs[strings.ToLower(addr)] = true
}

return blockedAddrs
}
29 changes: 29 additions & 0 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,32 @@ func (app *OsmosisApp) initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino

return paramsKeeper
}

func KVStoreKeys() []string {
return []string{
authtypes.StoreKey,
banktypes.StoreKey,
stakingtypes.StoreKey,
minttypes.StoreKey,
distrtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
paramstypes.StoreKey,
ibchost.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
gammtypes.StoreKey,
lockuptypes.StoreKey,
claimtypes.StoreKey,
incentivestypes.StoreKey,
epochstypes.StoreKey,
poolincentivestypes.StoreKey,
authzkeeper.StoreKey,
txfeestypes.StoreKey,
superfluidtypes.StoreKey,
bech32ibctypes.StoreKey,
wasm.StoreKey,
}
}

0 comments on commit 265890f

Please sign in to comment.