-
Notifications
You must be signed in to change notification settings - Fork 0
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
15 changed files
with
4,233 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.authority | ||
.idea | ||
build | ||
coverage.out |
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,6 @@ | ||
go 1.22 | ||
|
||
use ( | ||
. | ||
simapp | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,33 @@ | ||
alias authorityd=./simapp/build/simd | ||
|
||
for arg in "$@" | ||
do | ||
case $arg in | ||
-r|--reset) | ||
rm -rf .authority | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
if ! [ -f .authority/data/priv_validator_state.json ]; then | ||
authorityd init validator --chain-id "authority-1" --home .authority &> /dev/null | ||
|
||
authorityd keys add validator --home .authority --keyring-backend test &> /dev/null | ||
authorityd genesis add-genesis-account validator 1000000ustake --home .authority --keyring-backend test | ||
OWNER=$(authorityd keys add owner --home .authority --keyring-backend test --output json | jq .address) | ||
authorityd genesis add-genesis-account owner 2500000uusdc --home .authority --keyring-backend test | ||
PENDING_OWNER=$(authorityd keys add pending-owner --home .authority --keyring-backend test --output json | jq .address) | ||
authorityd genesis add-genesis-account pending-owner 2500000uusdc --home .authority --keyring-backend test | ||
|
||
TEMP=.authority/genesis.json | ||
touch $TEMP && jq '.app_state.authority.owner = '$OWNER'' .authority/config/genesis.json > $TEMP && mv $TEMP .authority/config/genesis.json | ||
touch $TEMP && jq '.app_state.staking.params.bond_denom = "ustake"' .authority/config/genesis.json > $TEMP && mv $TEMP .authority/config/genesis.json | ||
|
||
authorityd genesis gentx validator 1000000ustake --chain-id "authority-1" --home .authority --keyring-backend test &> /dev/null | ||
authorityd genesis collect-gentxs --home .authority &> /dev/null | ||
|
||
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' .authority/config/config.toml | ||
fi | ||
|
||
authorityd start --home .authority |
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,27 @@ | ||
BRANCH := $(shell git rev-parse --abbrev-ref HEAD) | ||
COMMIT := $(shell git log -1 --format='%H') | ||
|
||
ifeq (,$(VERSION)) | ||
VERSION := $(shell git describe --exact-match 2>/dev/null) | ||
ifeq (,$(VERSION)) | ||
ifeq ($(shell git status --porcelain),) | ||
VERSION := $(BRANCH) | ||
else | ||
VERSION := $(BRANCH)-dirty | ||
endif | ||
endif | ||
endif | ||
|
||
ldflags := $(LDFLAGS) | ||
ldflags += -X github.com/cosmos/cosmos-sdk/version.Name=simapp \ | ||
-X github.com/cosmos/cosmos-sdk/version.AppName=simd \ | ||
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ | ||
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) | ||
ldflags := $(strip $(ldflags)) | ||
|
||
BUILD_FLAGS := -ldflags '$(ldflags)' | ||
|
||
build: | ||
@go build -mod=readonly $(BUILD_FLAGS) -o $(PWD)/build/ ./... | ||
|
||
.PHONY: build |
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,173 @@ | ||
package simapp | ||
|
||
import ( | ||
_ "embed" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"cosmossdk.io/core/appconfig" | ||
"cosmossdk.io/depinject" | ||
"cosmossdk.io/log" | ||
storetypes "cosmossdk.io/store/types" | ||
upgradekeeper "cosmossdk.io/x/upgrade/keeper" | ||
|
||
dbm "github.com/cosmos/cosmos-db" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"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/runtime" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/genutil" | ||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
|
||
authoritykeeper "github.com/noble-assets/authority/x/authority/keeper" | ||
|
||
_ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side effects | ||
_ "cosmossdk.io/x/upgrade" // import for side effects | ||
_ "github.com/cosmos/cosmos-sdk/x/auth" // import for side effects | ||
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side effects | ||
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side effects | ||
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side effects | ||
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side effects | ||
_ "github.com/noble-assets/authority/x/authority" // import for side effects | ||
) | ||
|
||
var DefaultNodeHome string | ||
|
||
//go:embed app.yaml | ||
var AppConfigYAML []byte | ||
|
||
var ( | ||
_ runtime.AppI = (*SimApp)(nil) | ||
_ servertypes.Application = (*SimApp)(nil) | ||
) | ||
|
||
// SimApp 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. | ||
type SimApp struct { | ||
*runtime.App | ||
legacyAmino *codec.LegacyAmino | ||
appCodec codec.Codec | ||
txConfig client.TxConfig | ||
interfaceRegistry codectypes.InterfaceRegistry | ||
|
||
// Cosmos SDK Modules | ||
AccountKeeper authkeeper.AccountKeeper | ||
BankKeeper bankkeeper.Keeper | ||
ConsensusKeeper consensuskeeper.Keeper | ||
StakingKeeper *stakingkeeper.Keeper | ||
UpgradeKeeper *upgradekeeper.Keeper | ||
// Custom Modules | ||
AuthorityKeeper *authoritykeeper.Keeper | ||
} | ||
|
||
func init() { | ||
userHomeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
DefaultNodeHome = filepath.Join(userHomeDir, ".simapp") | ||
} | ||
|
||
// AppConfig returns the default app config. | ||
func AppConfig() depinject.Config { | ||
return depinject.Configs( | ||
appconfig.LoadYAML(AppConfigYAML), | ||
depinject.Supply( | ||
// supply custom module basics | ||
map[string]module.AppModuleBasic{ | ||
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), | ||
}, | ||
), | ||
) | ||
} | ||
|
||
// NewSimApp returns a reference to an initialized SimApp. | ||
func NewSimApp( | ||
logger log.Logger, | ||
db dbm.DB, | ||
traceStore io.Writer, | ||
loadLatest bool, | ||
appOpts servertypes.AppOptions, | ||
baseAppOptions ...func(*baseapp.BaseApp), | ||
) (*SimApp, error) { | ||
var ( | ||
app = &SimApp{} | ||
appBuilder *runtime.AppBuilder | ||
) | ||
|
||
if err := depinject.Inject( | ||
depinject.Configs( | ||
AppConfig(), | ||
depinject.Supply( | ||
logger, | ||
appOpts, | ||
), | ||
), | ||
&appBuilder, | ||
&app.appCodec, | ||
&app.legacyAmino, | ||
&app.txConfig, | ||
&app.interfaceRegistry, | ||
// Cosmos SDK Modules | ||
&app.AccountKeeper, | ||
&app.BankKeeper, | ||
&app.ConsensusKeeper, | ||
&app.StakingKeeper, | ||
&app.UpgradeKeeper, | ||
// Custom Modules | ||
&app.AuthorityKeeper, | ||
); err != nil { | ||
return nil, err | ||
} | ||
|
||
app.App = appBuilder.Build(db, traceStore, baseAppOptions...) | ||
|
||
if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := app.Load(loadLatest); err != nil { | ||
return nil, err | ||
} | ||
|
||
return app, nil | ||
} | ||
|
||
func (app *SimApp) LegacyAmino() *codec.LegacyAmino { | ||
return app.legacyAmino | ||
} | ||
|
||
func (app *SimApp) SimulationManager() *module.SimulationManager { | ||
return nil | ||
} | ||
|
||
func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { | ||
key, _ := app.UnsafeFindStoreKey(storeKey).(*storetypes.KVStoreKey) | ||
return key | ||
} | ||
|
||
func (app *SimApp) GetMemKey(memKey string) *storetypes.MemoryStoreKey { | ||
key, _ := app.UnsafeFindStoreKey(memKey).(*storetypes.MemoryStoreKey) | ||
return key | ||
} | ||
|
||
func (app *SimApp) kvStoreKeys() map[string]*storetypes.KVStoreKey { | ||
keys := make(map[string]*storetypes.KVStoreKey) | ||
for _, k := range app.GetStoreKeys() { | ||
if kv, ok := k.(*storetypes.KVStoreKey); ok { | ||
keys[kv.Name()] = kv | ||
} | ||
} | ||
|
||
return keys | ||
} |
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,51 @@ | ||
modules: | ||
- name: runtime | ||
config: | ||
"@type": cosmos.app.runtime.v1alpha1.Module | ||
app_name: SimApp | ||
pre_blockers: [ upgrade ] | ||
begin_blockers: [ staking ] | ||
end_blockers: [ staking ] | ||
init_genesis: [ auth, bank, staking, genutil, upgrade, authority ] | ||
override_store_keys: | ||
- module_name: auth | ||
kv_store_key: acc | ||
- name: auth | ||
config: | ||
"@type": cosmos.auth.module.v1.Module | ||
bech32_prefix: noble | ||
module_account_permissions: | ||
- account: fee_collector | ||
- account: bonded_tokens_pool | ||
permissions: [ burner, staking ] | ||
- account: not_bonded_tokens_pool | ||
permissions: [ burner, staking ] | ||
authority: authority # Utilize our custom x/authority module. | ||
- name: bank | ||
config: | ||
"@type": cosmos.bank.module.v1.Module | ||
blocked_module_accounts_override: | ||
[ auth, distribution, bonded_tokens_pool, not_bonded_tokens_pool ] | ||
authority: authority # Utilize our custom x/authority module. | ||
- name: consensus | ||
config: | ||
"@type": cosmos.consensus.module.v1.Module | ||
authority: authority # Utilize our custom x/authority module. | ||
- name: genutil | ||
config: | ||
"@type": cosmos.genutil.module.v1.Module | ||
- name: staking | ||
config: | ||
"@type": cosmos.staking.module.v1.Module | ||
authority: authority # Utilize our custom x/authority module. | ||
- name: tx | ||
config: | ||
"@type": cosmos.tx.config.v1.Config | ||
- name: upgrade | ||
config: | ||
"@type": cosmos.upgrade.module.v1.Module | ||
authority: authority # Utilize our custom x/authority module. | ||
|
||
- name: authority | ||
config: | ||
"@type": noble.authority.module.v1.Module |
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,53 @@ | ||
package simapp | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/staking" | ||
) | ||
|
||
// ExportAppStateAndValidators exports the state of the application for a genesis file. | ||
func (app *SimApp) ExportAppStateAndValidators( | ||
forZeroHeight bool, | ||
jailAllowedAddrs []string, | ||
_ []string, | ||
) (servertypes.ExportedApp, error) { | ||
// as if they could withdraw from the start of the next block | ||
ctx := app.NewContextLegacy(true, tmproto.Header{Height: app.LastBlockHeight()}) | ||
|
||
// We export at last height + 1, because that's the height at which | ||
// CometBFT will start InitChain. | ||
height := app.LastBlockHeight() + 1 | ||
if forZeroHeight { | ||
height = 0 | ||
app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) | ||
} | ||
|
||
genState, err := app.ModuleManager.ExportGenesis(ctx, app.appCodec) | ||
if err != nil { | ||
return servertypes.ExportedApp{}, fmt.Errorf("failed to export genesis state: %w", err) | ||
} | ||
|
||
appState, err := json.MarshalIndent(genState, "", " ") | ||
if err != nil { | ||
return servertypes.ExportedApp{}, err | ||
} | ||
|
||
validators, err := staking.WriteValidators(ctx, app.StakingKeeper) | ||
return servertypes.ExportedApp{ | ||
AppState: appState, | ||
Validators: validators, | ||
Height: height, | ||
ConsensusParams: app.BaseApp.GetConsensusParams(ctx), | ||
}, err | ||
} | ||
|
||
// prepare for fresh start at zero height | ||
// NOTE zero height genesis is a temporary feature, which will be deprecated in favour of export at a block height | ||
func (app *SimApp) prepForZeroHeightGenesis(_ sdk.Context, _ []string) { | ||
panic("unimplemented") | ||
} |
Oops, something went wrong.