example_chain

package module
v0.0.0-...-d14323f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 143 Imported by: 0

README

Example evmOS Chain

This directory contains an example chain that uses the evmOS modules. It is based on the simapp implementation on the Cosmos SDK repository, which itself is a simplified version of a Cosmos SDK-based blockchain.

This chain implementation is used to demonstrate the integration of evmOS as well as to provide a chain object for testing purposes within the repository.

Config

By default, this chain has the following configuration:

Option Value
Binary osd
Chain ID os_9005-1
Custom Opcodes -
Default Token Pairs 1 for the native token
Denomination aevmos
EVM flavor permissionless
Enabled Precompiles all

Running The Chain

To run the example, execute the local node script found within this repository:

./local_node.sh [FLAGS]

Available flags are:

  • -y: Overwrite previous database
  • -n: Do not overwrite previous database
  • --no-install: Skip installation of the binary
  • --remote-debugging: Build a binary suitable for remote debugging

Available Cosmos SDK Modules

As mentioned above, this exemplary chain implementation is a reduced version of simapp. Specifically, instead of offering access to all Cosmos SDK modules, it just includes the following:

  • auth
  • authz
  • bank
  • capability
  • consensus
  • distribution
  • evidence
  • feegrant
  • genutil
  • gov
  • mint
  • params
  • slashing
  • staking
  • upgrade

Documentation

Overview

Copyright Tharsis Labs Ltd.(Evmos) SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)

Index

Constants

View Source
const (
	// ExampleChainDenom is the denomination of the evmOS example chain's base coin.
	ExampleChainDenom = "aevmos"

	// ExampleDisplayDenom is the display denomination of the evmOS example chain's base coin.
	ExampleDisplayDenom = "evmos"

	// EighteenDecimalsChainID is the chain ID for the 18 decimals chain.
	EighteenDecimalsChainID = "os_9001"

	// SixDecimalsChainID is the chain ID for the 6 decimals chain.
	SixDecimalsChainID = "ossix_9002"
)
View Source
const WEVMOSContractMainnet = "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517"

WEVMOSContractMainnet is the WEVMOS contract address for mainnet

Variables

View Source
var ChainsCoinInfo = map[string]evmtypes.EvmCoinInfo{
	EighteenDecimalsChainID: {
		Denom:        ExampleChainDenom,
		DisplayDenom: ExampleDisplayDenom,
		Decimals:     evmtypes.EighteenDecimals,
	},
}

ChainsCoinInfo is a map of the chain id and its corresponding EvmCoinInfo that allows initializing the app with different coin info based on the chain id

View Source
var (
	// DefaultNodeHome default home directories for the application daemon
	DefaultNodeHome string
)
View Source
var ExampleTokenPairs = []erc20types.TokenPair{
	{
		Erc20Address:  WEVMOSContractMainnet,
		Denom:         ExampleChainDenom,
		Enabled:       true,
		ContractOwner: erc20types.OWNER_MODULE,
	},
}

ExampleTokenPairs creates a slice of token pairs, that contains a pair for the native denom of the example chain implementation.

Functions

func BlockedAddresses

func BlockedAddresses() map[string]bool

BlockedAddresses returns all the app's blocked account addresses.

Note, this includes:

  • module accounts
  • Ethereum's native precompiled smart contracts
  • evmOS' available static precompiled contracts

func EvmosAppOptions

func EvmosAppOptions(chainID string) error

EvmosAppOptions allows to setup the global configuration for the Evmos chain.

func GetMaccPerms

func GetMaccPerms() map[string][]string

GetMaccPerms returns a copy of the module account permissions

func NewAvailableStaticPrecompiles

func NewAvailableStaticPrecompiles(
	stakingKeeper stakingkeeper.Keeper,
	distributionKeeper distributionkeeper.Keeper,
	bankKeeper bankkeeper.Keeper,
	erc20Keeper erc20Keeper.Keeper,
	authzKeeper authzkeeper.Keeper,
	transferKeeper transferkeeper.Keeper,
	channelKeeper channelkeeper.Keeper,
	evmKeeper *evmkeeper.Keeper,
	govKeeper govkeeper.Keeper,
	slashingKeeper slashingkeeper.Keeper,
	evidenceKeeper evidencekeeper.Keeper,
) map[common.Address]vm.PrecompiledContract

NewAvailableStaticPrecompiles returns the list of all available static precompiled contracts from evmOS.

NOTE: this should only be used during initialization of the Keeper.

func NewEVMGenesisState

func NewEVMGenesisState() *evmtypes.GenesisState

NewEVMGenesisState returns the default genesis state for the EVM module.

NOTE: for the example chain implementation we need to set the default EVM denomination and enable ALL precompiles.

func NewErc20GenesisState

func NewErc20GenesisState() *erc20types.GenesisState

NewErc20GenesisState returns the default genesis state for the ERC20 module.

NOTE: for the example chain implementation we are also adding a default token pair, which is the base denomination of the chain (i.e. the WEVMOS contract).

func NewMintGenesisState

func NewMintGenesisState() *minttypes.GenesisState

NewMintGenesisState returns the default genesis state for the mint module.

NOTE: for the example chain implementation we are also adding a default minter.

func NoOpEvmosOptions

func NoOpEvmosOptions(_ string) error

NoOpEvmosOptions is a no-op function that can be used when the app does not need any specific configuration.

func SetupTestingApp

func SetupTestingApp(chainID string) func() (ibctesting.TestingApp, map[string]json.RawMessage)

SetupTestingApp initializes the IBC-go testing application need to keep this design to comply with the ibctesting SetupTestingApp func and be able to set the chainID for the tests properly

Types

type EvmosOptionsFn

type EvmosOptionsFn func(string) error

EvmosOptionsFn defines a function type for setting app options specifically for the Evmos app. The function should receive the chainID and return an error if any.

type ExampleChain

type ExampleChain struct {
	*baseapp.BaseApp

	// keepers
	AccountKeeper         authkeeper.AccountKeeper
	BankKeeper            bankkeeper.Keeper
	CapabilityKeeper      *capabilitykeeper.Keeper
	StakingKeeper         *stakingkeeper.Keeper
	SlashingKeeper        slashingkeeper.Keeper
	MintKeeper            mintkeeper.Keeper
	DistrKeeper           distrkeeper.Keeper
	GovKeeper             govkeeper.Keeper
	UpgradeKeeper         *upgradekeeper.Keeper
	ParamsKeeper          paramskeeper.Keeper
	AuthzKeeper           authzkeeper.Keeper
	EvidenceKeeper        evidencekeeper.Keeper
	FeeGrantKeeper        feegrantkeeper.Keeper
	ConsensusParamsKeeper consensusparamkeeper.Keeper

	// IBC keepers
	IBCKeeper      *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
	TransferKeeper transferkeeper.Keeper

	ScopedTransferKeeper capabilitykeeper.ScopedKeeper

	// evmOS keepers
	FeeMarketKeeper feemarketkeeper.Keeper
	EVMKeeper       *evmkeeper.Keeper
	Erc20Keeper     erc20keeper.Keeper

	// the module manager
	ModuleManager      *module.Manager
	BasicModuleManager module.BasicManager
	// contains filtered or unexported fields
}

ExampleChain 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.

func NewExampleApp

func NewExampleApp(
	logger log.Logger,
	db dbm.DB,
	traceStore io.Writer,
	loadLatest bool,
	appOpts servertypes.AppOptions,
	evmosAppOptions EvmosOptionsFn,
	baseAppOptions ...func(*baseapp.BaseApp),
) *ExampleChain

NewExampleApp returns a reference to an initialized ExampleChain.

func Setup

func Setup(t *testing.T, chainID string) *ExampleChain

Setup initializes a new ExampleChain. A Nop logger is set in ExampleChain.

func SetupWithGenesisValSet

func SetupWithGenesisValSet(t *testing.T, chainID string, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *ExampleChain

SetupWithGenesisValSet initializes a new ExampleChain with a validator set and genesis accounts that also act as delegators. For simplicity, each validator is bonded with a delegation of one consensus engine unit in the default token of the simapp from first genesis account. A Nop logger is set in ExampleChain.

func (*ExampleChain) AppCodec

func (app *ExampleChain) AppCodec() codec.Codec

AppCodec returns ExampleChain's app codec.

NOTE: This is solely to be used for testing purposes as it may be desirable for modules to register their own custom testing types.

func (*ExampleChain) AutoCliOpts

func (app *ExampleChain) AutoCliOpts() autocli.AppOptions

AutoCliOpts returns the autocli options for the app.

func (*ExampleChain) BeginBlocker

func (app *ExampleChain) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error)

BeginBlocker application updates every begin block

func (*ExampleChain) Configurator

func (a *ExampleChain) Configurator() module.Configurator

func (*ExampleChain) DefaultGenesis

func (a *ExampleChain) DefaultGenesis() map[string]json.RawMessage

DefaultGenesis returns a default genesis from the registered AppModuleBasic's.

TODO: change all receivers to osApp

func (*ExampleChain) EndBlocker

func (app *ExampleChain) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error)

EndBlocker application updates every end block

func (*ExampleChain) ExportAppStateAndValidators

func (app *ExampleChain) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error)

ExportAppStateAndValidators exports the state of the application for a genesis file.

func (*ExampleChain) FinalizeBlock

func (app *ExampleChain) FinalizeBlock(req *abci.RequestFinalizeBlock) (res *abci.ResponseFinalizeBlock, err error)

func (*ExampleChain) GetBaseApp

func (app *ExampleChain) GetBaseApp() *baseapp.BaseApp

GetBaseApp implements the TestingApp interface.

func (*ExampleChain) GetIBCKeeper

func (app *ExampleChain) GetIBCKeeper() *ibckeeper.Keeper

GetIBCKeeper implements the TestingApp interface.

func (*ExampleChain) GetKey

func (app *ExampleChain) GetKey(storeKey string) *storetypes.KVStoreKey

GetKey returns the KVStoreKey for the provided store key.

NOTE: This is solely to be used for testing purposes.

func (*ExampleChain) GetMemKey

func (app *ExampleChain) GetMemKey(storeKey string) *storetypes.MemoryStoreKey

GetMemKey returns the MemStoreKey for the provided mem key.

NOTE: This is solely used for testing purposes.

func (*ExampleChain) GetScopedIBCKeeper

func (app *ExampleChain) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper

GetScopedIBCKeeper implements the TestingApp interface.

func (*ExampleChain) GetStakingKeeper

func (app *ExampleChain) GetStakingKeeper() ibctestingtypes.StakingKeeper

GetStakingKeeper implements the TestingApp interface.

func (*ExampleChain) GetStakingKeeperSDK

func (app *ExampleChain) GetStakingKeeperSDK() stakingkeeper.Keeper

GetStakingKeeperSDK implements the TestingApp interface.

func (*ExampleChain) GetSubspace

func (app *ExampleChain) GetSubspace(moduleName string) paramstypes.Subspace

GetSubspace returns a param subspace for a given module name.

NOTE: This is solely to be used for testing purposes.

func (*ExampleChain) GetTKey

func (app *ExampleChain) GetTKey(storeKey string) *storetypes.TransientStoreKey

GetTKey returns the TransientStoreKey for the provided store key.

NOTE: This is solely to be used for testing purposes.

func (*ExampleChain) GetTxConfig

func (app *ExampleChain) GetTxConfig() client.TxConfig

GetTxConfig implements the TestingApp interface.

func (*ExampleChain) InitChainer

func (app *ExampleChain) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error)

InitChainer application update at chain initialization

func (*ExampleChain) InterfaceRegistry

func (app *ExampleChain) InterfaceRegistry() types.InterfaceRegistry

InterfaceRegistry returns ExampleChain's InterfaceRegistry

func (*ExampleChain) LegacyAmino

func (app *ExampleChain) LegacyAmino() *codec.LegacyAmino

LegacyAmino returns ExampleChain's amino codec.

NOTE: This is solely to be used for testing purposes as it may be desirable for modules to register their own custom testing types.

func (*ExampleChain) LoadHeight

func (app *ExampleChain) LoadHeight(height int64) error

LoadHeight loads a particular height

func (*ExampleChain) Name

func (app *ExampleChain) Name() string

Name returns the name of the App

func (*ExampleChain) PreBlocker

func (*ExampleChain) RegisterAPIRoutes

func (app *ExampleChain) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig)

RegisterAPIRoutes registers all application module routes with the provided API server.

func (*ExampleChain) RegisterNodeService

func (app *ExampleChain) RegisterNodeService(clientCtx client.Context, cfg config.Config)

func (*ExampleChain) RegisterTendermintService

func (app *ExampleChain) RegisterTendermintService(clientCtx client.Context)

RegisterTendermintService implements the Application.RegisterTendermintService method.

func (*ExampleChain) RegisterTxService

func (app *ExampleChain) RegisterTxService(clientCtx client.Context)

RegisterTxService implements the Application.RegisterTxService method.

func (ExampleChain) RegisterUpgradeHandlers

func (app ExampleChain) RegisterUpgradeHandlers()

func (*ExampleChain) SimulationManager

func (app *ExampleChain) SimulationManager() *module.SimulationManager

SimulationManager implements the SimulationApp interface

func (*ExampleChain) TxConfig

func (app *ExampleChain) TxConfig() client.TxConfig

TxConfig returns ExampleChain's TxConfig

type GenesisState

type GenesisState map[string]json.RawMessage

GenesisState of the blockchain is represented here as a map of raw json messages key'd by an identifier string. The identifier is used to determine which module genesis information belongs to so it may be appropriately routed during init chain. Within this application default genesis information is retrieved from the ModuleBasicManager which populates json from each BasicModule object provided to it during init.

type SetupOptions

type SetupOptions struct {
	Logger  log.Logger
	DB      *dbm.MemDB
	AppOpts servertypes.AppOptions
}

SetupOptions defines arguments that are passed into `Simapp` constructor.

Directories

Path Synopsis
osd
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳