Add a minimal chain and placeholders for bond module (#1)
* Setup minimal chain * Change app and command name * Rename command folder * Add run instructions * Add placeholder files for bond module * Missing new line
This commit is contained in:
parent
e17bb26169
commit
e513f79b81
83
Makefile
Normal file
83
Makefile
Normal file
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
DOCKER := $(shell which docker)
|
||||
|
||||
LACONIC_BINARY = laconic2d
|
||||
|
||||
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
COMMIT := $(shell git log -1 --format='%H')
|
||||
|
||||
# don't override user values
|
||||
ifeq (,$(VERSION))
|
||||
VERSION := $(shell git describe --exact-match 2>/dev/null)
|
||||
# if VERSION is empty, then populate it with branch's name and raw commit hash
|
||||
ifeq (,$(VERSION))
|
||||
VERSION := $(BRANCH)-$(COMMIT)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Update the ldflags with the app, client & server names
|
||||
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=laconic \
|
||||
-X github.com/cosmos/cosmos-sdk/version.AppName=$(LACONIC_BINARY) \
|
||||
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
|
||||
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT)
|
||||
|
||||
BUILD_FLAGS := -ldflags '$(ldflags)'
|
||||
|
||||
###########
|
||||
# Install #
|
||||
###########
|
||||
|
||||
all: install
|
||||
|
||||
install:
|
||||
@echo "--> ensure dependencies have not been modified"
|
||||
@go mod verify
|
||||
@echo "--> installing laconic2d"
|
||||
@go install $(BUILD_FLAGS) -mod=readonly ./cmd/laconic2d
|
||||
|
||||
init:
|
||||
./scripts/init.sh
|
||||
|
||||
##################
|
||||
### Protobuf ###
|
||||
##################
|
||||
|
||||
|
||||
protoVer=0.14.0
|
||||
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
|
||||
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
|
||||
|
||||
proto-all: proto-format proto-lint proto-gen
|
||||
|
||||
proto-gen:
|
||||
@echo "Generating protobuf files..."
|
||||
@$(protoImage) sh ./scripts/protocgen.sh
|
||||
@go mod tidy
|
||||
|
||||
proto-format:
|
||||
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
|
||||
|
||||
proto-lint:
|
||||
@$(protoImage) buf lint proto/ --error-format=json
|
||||
|
||||
.PHONY: proto-all proto-gen proto-format proto-lint
|
||||
|
||||
#################
|
||||
### Linting ###
|
||||
#################
|
||||
|
||||
golangci_lint_cmd=golangci-lint
|
||||
golangci_version=v1.51.2
|
||||
|
||||
lint:
|
||||
@echo "--> Running linter"
|
||||
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
|
||||
@$(golangci_lint_cmd) run ./... --timeout 15m
|
||||
|
||||
lint-fix:
|
||||
@echo "--> Running linter and fixing issues"
|
||||
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
|
||||
@$(golangci_lint_cmd) run ./... --fix --timeout 15m
|
||||
|
||||
.PHONY: lint lint-fix
|
15
README.md
15
README.md
@ -1 +1,14 @@
|
||||
# laconic2d
|
||||
# laconic2d
|
||||
|
||||
Install and run `laconic2d`:
|
||||
|
||||
```bash
|
||||
# install the laconic2d binary
|
||||
make install
|
||||
|
||||
# initialize the chain
|
||||
make init
|
||||
|
||||
# start the chain
|
||||
laconic2d start
|
||||
```
|
||||
|
194
app/app.go
Normal file
194
app/app.go
Normal file
@ -0,0 +1,194 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
|
||||
"cosmossdk.io/core/appconfig"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
"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"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/server/api"
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
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"
|
||||
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/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"
|
||||
|
||||
_ "cosmossdk.io/api/cosmos/tx/config/v1" // 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/distribution" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects
|
||||
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
|
||||
)
|
||||
|
||||
// DefaultNodeHome default home directories for the application daemon
|
||||
var DefaultNodeHome string
|
||||
|
||||
//go:embed app.yaml
|
||||
var AppConfigYAML []byte
|
||||
|
||||
var (
|
||||
_ runtime.AppI = (*LaconicApp)(nil)
|
||||
_ servertypes.Application = (*LaconicApp)(nil)
|
||||
)
|
||||
|
||||
// LaconicApp 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 LaconicApp struct {
|
||||
*runtime.App
|
||||
legacyAmino *codec.LegacyAmino
|
||||
appCodec codec.Codec
|
||||
txConfig client.TxConfig
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
|
||||
// keepers
|
||||
AccountKeeper authkeeper.AccountKeeper
|
||||
BankKeeper bankkeeper.Keeper
|
||||
StakingKeeper *stakingkeeper.Keeper
|
||||
DistrKeeper distrkeeper.Keeper
|
||||
ConsensusParamsKeeper consensuskeeper.Keeper
|
||||
|
||||
// simulation manager
|
||||
sm *module.SimulationManager
|
||||
}
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, ".laconic2d")
|
||||
}
|
||||
|
||||
// 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),
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// NewLaconicApp returns a reference to an initialized LaconicApp.
|
||||
func NewLaconicApp(
|
||||
logger log.Logger,
|
||||
db dbm.DB,
|
||||
traceStore io.Writer,
|
||||
loadLatest bool,
|
||||
appOpts servertypes.AppOptions,
|
||||
baseAppOptions ...func(*baseapp.BaseApp),
|
||||
) (*LaconicApp, error) {
|
||||
var (
|
||||
app = &LaconicApp{}
|
||||
appBuilder *runtime.AppBuilder
|
||||
)
|
||||
|
||||
if err := depinject.Inject(
|
||||
depinject.Configs(
|
||||
AppConfig(),
|
||||
depinject.Supply(
|
||||
logger,
|
||||
appOpts,
|
||||
),
|
||||
),
|
||||
&appBuilder,
|
||||
&app.appCodec,
|
||||
&app.legacyAmino,
|
||||
&app.txConfig,
|
||||
&app.interfaceRegistry,
|
||||
&app.AccountKeeper,
|
||||
&app.BankKeeper,
|
||||
&app.StakingKeeper,
|
||||
&app.DistrKeeper,
|
||||
&app.ConsensusParamsKeeper,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
app.App = appBuilder.Build(db, traceStore, baseAppOptions...)
|
||||
|
||||
// register streaming services
|
||||
if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
/**** Module Options ****/
|
||||
|
||||
// create the simulation manager and define the order of the modules for deterministic simulations
|
||||
// NOTE: this is not required apps that don't use the simulator for fuzz testing transactions
|
||||
app.sm = module.NewSimulationManagerFromAppModules(app.ModuleManager.Modules, make(map[string]module.AppModuleSimulation, 0))
|
||||
app.sm.RegisterStoreDecoders()
|
||||
|
||||
if err := app.Load(loadLatest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return app, nil
|
||||
}
|
||||
|
||||
// LegacyAmino returns LaconicApp's amino codec.
|
||||
func (app *LaconicApp) LegacyAmino() *codec.LegacyAmino {
|
||||
return app.legacyAmino
|
||||
}
|
||||
|
||||
// GetKey returns the KVStoreKey for the provided store key.
|
||||
func (app *LaconicApp) GetKey(storeKey string) *storetypes.KVStoreKey {
|
||||
sk := app.UnsafeFindStoreKey(storeKey)
|
||||
kvStoreKey, ok := sk.(*storetypes.KVStoreKey)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return kvStoreKey
|
||||
}
|
||||
|
||||
func (app *LaconicApp) 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
|
||||
}
|
||||
|
||||
// SimulationManager implements the SimulationApp interface
|
||||
func (app *LaconicApp) SimulationManager() *module.SimulationManager {
|
||||
return app.sm
|
||||
}
|
||||
|
||||
// RegisterAPIRoutes registers all application module routes with the provided
|
||||
// API server.
|
||||
func (app *LaconicApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
|
||||
app.App.RegisterAPIRoutes(apiSvr, apiConfig)
|
||||
// register swagger API in app.go so that other applications can override easily
|
||||
if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
48
app/app.yaml
Normal file
48
app/app.yaml
Normal file
@ -0,0 +1,48 @@
|
||||
modules:
|
||||
- name: runtime
|
||||
config:
|
||||
"@type": cosmos.app.runtime.v1alpha1.Module
|
||||
app_name: LaconicApp
|
||||
# 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.
|
||||
# NOTE: staking module is required if HistoricalEntries param > 0
|
||||
begin_blockers: [distribution, staking]
|
||||
end_blockers: [staking]
|
||||
# NOTE: The genutils module must occur after staking so that pools are properly initialized with tokens from genesis accounts.
|
||||
# NOTE: The genutils module must also occur after auth so that it can access the params from auth.
|
||||
init_genesis: [auth, bank, distribution, staking, genutil]
|
||||
override_store_keys:
|
||||
- module_name: auth
|
||||
kv_store_key: acc
|
||||
- name: auth
|
||||
config:
|
||||
"@type": cosmos.auth.module.v1.Module
|
||||
bech32_prefix: photon
|
||||
module_account_permissions:
|
||||
- account: fee_collector
|
||||
- account: distribution
|
||||
- account: bonded_tokens_pool
|
||||
permissions: [burner, staking]
|
||||
- account: not_bonded_tokens_pool
|
||||
permissions: [burner, staking]
|
||||
- name: bank
|
||||
config:
|
||||
"@type": cosmos.bank.module.v1.Module
|
||||
blocked_module_accounts_override:
|
||||
[auth, distribution, bonded_tokens_pool, not_bonded_tokens_pool]
|
||||
- name: staking
|
||||
config:
|
||||
"@type": cosmos.staking.module.v1.Module
|
||||
- name: distribution
|
||||
config:
|
||||
"@type": cosmos.distribution.module.v1.Module
|
||||
- name: consensus
|
||||
config:
|
||||
"@type": cosmos.consensus.module.v1.Module
|
||||
- name: genutil
|
||||
config:
|
||||
"@type": cosmos.genutil.module.v1.Module
|
||||
- name: tx
|
||||
config:
|
||||
"@type": cosmos.tx.config.v1.Config
|
||||
# Add bond module
|
224
app/export.go
Normal file
224
app/export.go
Normal file
@ -0,0 +1,224 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
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"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// ExportAppStateAndValidators exports the state of the application for a genesis file.
|
||||
func (app *LaconicApp) ExportAppStateAndValidators(
|
||||
forZeroHeight bool,
|
||||
jailAllowedAddrs []string,
|
||||
modulesToExport []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 *LaconicApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
|
||||
applyAllowedAddrs := false
|
||||
|
||||
// check if there is a allowed address list
|
||||
if len(jailAllowedAddrs) > 0 {
|
||||
applyAllowedAddrs = true
|
||||
}
|
||||
|
||||
allowedAddrsMap := make(map[string]bool)
|
||||
|
||||
for _, addr := range jailAllowedAddrs {
|
||||
_, err := sdk.ValAddressFromBech32(addr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
allowedAddrsMap[addr] = true
|
||||
}
|
||||
|
||||
/* Handle fee distribution state. */
|
||||
|
||||
// withdraw all validator commission
|
||||
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
|
||||
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz)
|
||||
return false
|
||||
})
|
||||
|
||||
// withdraw all delegator rewards
|
||||
dels, err := app.StakingKeeper.GetAllDelegations(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, delegation := range dels {
|
||||
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
|
||||
}
|
||||
|
||||
// clear validator slash events
|
||||
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
|
||||
|
||||
// clear validator historical rewards
|
||||
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
|
||||
|
||||
// set context height to zero
|
||||
height := ctx.BlockHeight()
|
||||
ctx = ctx.WithBlockHeight(0)
|
||||
|
||||
// reinitialize all validators
|
||||
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
|
||||
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
|
||||
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
|
||||
if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
// reinitialize all delegations
|
||||
for _, del := range dels {
|
||||
valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
|
||||
// never called as BeforeDelegationCreated always returns nil
|
||||
panic(fmt.Errorf("error while incrementing period: %w", err))
|
||||
}
|
||||
|
||||
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
|
||||
// never called as AfterDelegationModified always returns nil
|
||||
panic(fmt.Errorf("error while creating a new delegation period record: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
// reset context height
|
||||
ctx = ctx.WithBlockHeight(height)
|
||||
|
||||
/* Handle staking state. */
|
||||
|
||||
// iterate through redelegations, reset creation height
|
||||
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
|
||||
for i := range red.Entries {
|
||||
red.Entries[i].CreationHeight = 0
|
||||
}
|
||||
app.StakingKeeper.SetRedelegation(ctx, red)
|
||||
return false
|
||||
})
|
||||
|
||||
// iterate through unbonding delegations, reset creation height
|
||||
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
|
||||
for i := range ubd.Entries {
|
||||
ubd.Entries[i].CreationHeight = 0
|
||||
}
|
||||
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
|
||||
return false
|
||||
})
|
||||
|
||||
// Iterate through validators by power descending, reset bond heights, and
|
||||
// update bond intra-tx counters.
|
||||
store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey))
|
||||
iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
|
||||
counter := int16(0)
|
||||
|
||||
for ; iter.Valid(); iter.Next() {
|
||||
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
|
||||
validator, err := app.StakingKeeper.GetValidator(ctx, addr)
|
||||
if errors.Is(err, stakingtypes.ErrNoValidatorFound) {
|
||||
panic("expected validator, not found")
|
||||
} else if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
validator.UnbondingHeight = 0
|
||||
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
|
||||
validator.Jailed = true
|
||||
}
|
||||
|
||||
app.StakingKeeper.SetValidator(ctx, validator)
|
||||
counter++
|
||||
}
|
||||
|
||||
if err := iter.Close(); err != nil {
|
||||
app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
69
app/params/config.go
Normal file
69
app/params/config.go
Normal file
@ -0,0 +1,69 @@
|
||||
package params
|
||||
|
||||
import (
|
||||
"cosmossdk.io/errors"
|
||||
"cosmossdk.io/math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
CoinUnit = "photon"
|
||||
|
||||
DefaultBondDenom = CoinUnit
|
||||
|
||||
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address.
|
||||
Bech32PrefixAccAddr = "photon"
|
||||
)
|
||||
|
||||
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(CoinUnit, math.LegacyOneDec())
|
||||
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 errors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
|
||||
}
|
||||
|
||||
if len(bytes) > address.MaxAddrLen {
|
||||
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
|
||||
}
|
||||
|
||||
if len(bytes) != 20 && len(bytes) != 32 {
|
||||
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
16
app/params/encoding.go
Normal file
16
app/params/encoding.go
Normal file
@ -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
|
||||
Codec codec.Codec
|
||||
TxConfig client.TxConfig
|
||||
Amino *codec.LegacyAmino
|
||||
}
|
161
cmd/laconic2d/cmd/commands.go
Normal file
161
cmd/laconic2d/cmd/commands.go
Normal file
@ -0,0 +1,161 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
confixcmd "cosmossdk.io/tools/confix/cmd"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/debug"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/client/pruning"
|
||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
"github.com/cosmos/cosmos-sdk/client/snapshot"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||
|
||||
"git.vdb.to/cerc-io/laconic2d/app"
|
||||
)
|
||||
|
||||
func initRootCmd(rootCmd *cobra.Command, txConfig client.TxConfig, basicManager module.BasicManager) {
|
||||
cfg := sdk.GetConfig()
|
||||
cfg.Seal()
|
||||
|
||||
rootCmd.AddCommand(
|
||||
genutilcli.InitCmd(basicManager, app.DefaultNodeHome),
|
||||
debug.Cmd(),
|
||||
confixcmd.ConfigCommand(),
|
||||
pruning.Cmd(newApp, app.DefaultNodeHome),
|
||||
snapshot.Cmd(newApp),
|
||||
)
|
||||
|
||||
server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, appExport, func(startCmd *cobra.Command) {})
|
||||
|
||||
// add keybase, auxiliary RPC, query, genesis, and tx child commands
|
||||
rootCmd.AddCommand(
|
||||
server.StatusCommand(),
|
||||
genutilcli.Commands(txConfig, basicManager, app.DefaultNodeHome),
|
||||
queryCommand(),
|
||||
txCommand(),
|
||||
keys.Commands(),
|
||||
)
|
||||
}
|
||||
|
||||
func queryCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "query",
|
||||
Aliases: []string{"q"},
|
||||
Short: "Querying subcommands",
|
||||
DisableFlagParsing: false,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
rpc.ValidatorCommand(),
|
||||
server.QueryBlockCmd(),
|
||||
authcmd.QueryTxsByEventsCmd(),
|
||||
server.QueryBlocksCmd(),
|
||||
authcmd.QueryTxCmd(),
|
||||
server.QueryBlockResultsCmd(),
|
||||
)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func txCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "tx",
|
||||
Short: "Transactions subcommands",
|
||||
DisableFlagParsing: false,
|
||||
SuggestionsMinimumDistance: 2,
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
authcmd.GetSignCommand(),
|
||||
authcmd.GetSignBatchCommand(),
|
||||
authcmd.GetMultiSignCommand(),
|
||||
authcmd.GetMultiSignBatchCmd(),
|
||||
authcmd.GetValidateSignaturesCommand(),
|
||||
authcmd.GetBroadcastCommand(),
|
||||
authcmd.GetEncodeCommand(),
|
||||
authcmd.GetDecodeCommand(),
|
||||
authcmd.GetSimulateCmd(),
|
||||
)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// newApp is an appCreator
|
||||
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts servertypes.AppOptions) servertypes.Application {
|
||||
baseappOptions := server.DefaultBaseappOptions(appOpts)
|
||||
app, err := app.NewLaconicApp(logger, db, traceStore, true, appOpts, baseappOptions...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
// appExport creates a new app (optionally at a given height) and exports state.
|
||||
func appExport(
|
||||
logger log.Logger,
|
||||
db dbm.DB,
|
||||
traceStore io.Writer,
|
||||
height int64,
|
||||
forZeroHeight bool,
|
||||
jailAllowedAddrs []string,
|
||||
appOpts servertypes.AppOptions,
|
||||
modulesToExport []string,
|
||||
) (servertypes.ExportedApp, error) {
|
||||
var (
|
||||
laconicApp *app.LaconicApp
|
||||
err error
|
||||
)
|
||||
|
||||
// this check is necessary as we use the flag in x/upgrade.
|
||||
// we can exit more gracefully by checking the flag here.
|
||||
homePath, ok := appOpts.Get(flags.FlagHome).(string)
|
||||
if !ok || homePath == "" {
|
||||
return servertypes.ExportedApp{}, errors.New("application home not set")
|
||||
}
|
||||
|
||||
viperAppOpts, ok := appOpts.(*viper.Viper)
|
||||
if !ok {
|
||||
return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper")
|
||||
}
|
||||
|
||||
// overwrite the FlagInvCheckPeriod
|
||||
viperAppOpts.Set(server.FlagInvCheckPeriod, 1)
|
||||
appOpts = viperAppOpts
|
||||
|
||||
if height != -1 {
|
||||
laconicApp, err = app.NewLaconicApp(logger, db, traceStore, false, appOpts)
|
||||
if err != nil {
|
||||
return servertypes.ExportedApp{}, err
|
||||
}
|
||||
|
||||
if err := laconicApp.LoadHeight(height); err != nil {
|
||||
return servertypes.ExportedApp{}, err
|
||||
}
|
||||
} else {
|
||||
laconicApp, err = app.NewLaconicApp(logger, db, traceStore, true, appOpts)
|
||||
if err != nil {
|
||||
return servertypes.ExportedApp{}, err
|
||||
}
|
||||
}
|
||||
|
||||
return laconicApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
|
||||
}
|
153
cmd/laconic2d/cmd/root.go
Normal file
153
cmd/laconic2d/cmd/root.go
Normal file
@ -0,0 +1,153 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
cmtcfg "github.com/cometbft/cometbft/config"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/client/v2/autocli"
|
||||
clientv2keyring "cosmossdk.io/client/v2/autocli/keyring"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/config"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconic2d/app"
|
||||
)
|
||||
|
||||
const EnvPrefix = "LACONIC"
|
||||
|
||||
// NewRootCmd creates a new root command for laconic2d. It is called once in the
|
||||
// main function.
|
||||
func NewRootCmd() *cobra.Command {
|
||||
var (
|
||||
txConfigOpts tx.ConfigOptions
|
||||
autoCliOpts autocli.AppOptions
|
||||
moduleBasicManager module.BasicManager
|
||||
clientCtx client.Context
|
||||
)
|
||||
|
||||
if err := depinject.Inject(
|
||||
depinject.Configs(app.AppConfig(),
|
||||
depinject.Supply(
|
||||
log.NewNopLogger(),
|
||||
),
|
||||
depinject.Provide(
|
||||
ProvideClientContext,
|
||||
ProvideKeyring,
|
||||
),
|
||||
),
|
||||
&txConfigOpts,
|
||||
&autoCliOpts,
|
||||
&moduleBasicManager,
|
||||
&clientCtx,
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "laconic2d",
|
||||
Short: "Laconic Daemon",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||
// set the default command outputs
|
||||
cmd.SetOut(cmd.OutOrStdout())
|
||||
cmd.SetErr(cmd.ErrOrStderr())
|
||||
|
||||
clientCtx = clientCtx.WithCmdContext(cmd.Context())
|
||||
clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx, err = config.ReadFromClientConfig(clientCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// sign mode textual is only available in online mode
|
||||
if !clientCtx.Offline {
|
||||
// This needs to go after ReadFromClientConfig, as that function ets the RPC client needed for SIGN_MODE_TEXTUAL.
|
||||
txConfigOpts.EnabledSignModes = append(txConfigOpts.EnabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
|
||||
txConfigOpts.TextualCoinMetadataQueryFn = txmodule.NewGRPCCoinMetadataQueryFn(clientCtx)
|
||||
txConfigWithTextual, err := tx.NewTxConfigWithOptions(codec.NewProtoCodec(clientCtx.InterfaceRegistry), txConfigOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx = clientCtx.WithTxConfig(txConfigWithTextual)
|
||||
}
|
||||
|
||||
if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// overwrite the minimum gas price from the app configuration
|
||||
srvCfg := serverconfig.DefaultConfig()
|
||||
srvCfg.MinGasPrices = "0photon"
|
||||
|
||||
// overwrite the block timeout
|
||||
cmtCfg := cmtcfg.DefaultConfig()
|
||||
cmtCfg.Consensus.TimeoutCommit = 3 * time.Second
|
||||
cmtCfg.LogLevel = "*:error,p2p:info,state:info" // better default logging
|
||||
|
||||
return server.InterceptConfigsPreRunHandler(cmd, serverconfig.DefaultConfigTemplate, srvCfg, cmtCfg)
|
||||
},
|
||||
}
|
||||
|
||||
initRootCmd(rootCmd, clientCtx.TxConfig, moduleBasicManager)
|
||||
|
||||
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
func ProvideClientContext(
|
||||
appCodec codec.Codec,
|
||||
interfaceRegistry codectypes.InterfaceRegistry,
|
||||
txConfig client.TxConfig,
|
||||
legacyAmino *codec.LegacyAmino,
|
||||
) client.Context {
|
||||
clientCtx := client.Context{}.
|
||||
WithCodec(appCodec).
|
||||
WithInterfaceRegistry(interfaceRegistry).
|
||||
WithTxConfig(txConfig).
|
||||
WithLegacyAmino(legacyAmino).
|
||||
WithInput(os.Stdin).
|
||||
WithAccountRetriever(types.AccountRetriever{}).
|
||||
WithHomeDir(app.DefaultNodeHome).
|
||||
WithViper(EnvPrefix) // env variable prefix
|
||||
|
||||
// Read the config again to overwrite the default values with the values from the config file
|
||||
clientCtx, _ = config.ReadFromClientConfig(clientCtx)
|
||||
|
||||
return clientCtx
|
||||
}
|
||||
|
||||
func ProvideKeyring(clientCtx client.Context, addressCodec address.Codec) (clientv2keyring.Keyring, error) {
|
||||
kb, err := client.NewKeyringFromBackend(clientCtx, clientCtx.Keyring.Backend())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return keyring.NewAutoCLIKeyring(kb)
|
||||
}
|
22
cmd/laconic2d/main.go
Normal file
22
cmd/laconic2d/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
|
||||
"git.vdb.to/cerc-io/laconic2d/app"
|
||||
"git.vdb.to/cerc-io/laconic2d/app/params"
|
||||
"git.vdb.to/cerc-io/laconic2d/cmd/laconic2d/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
params.SetAddressPrefixes()
|
||||
|
||||
rootCmd := cmd.NewRootCmd()
|
||||
if err := svrcmd.Execute(rootCmd, "", app.DefaultNodeHome); err != nil {
|
||||
fmt.Fprintln(rootCmd.OutOrStderr(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
171
go.mod
Normal file
171
go.mod
Normal file
@ -0,0 +1,171 @@
|
||||
module git.vdb.to/cerc-io/laconic2d
|
||||
|
||||
go 1.21
|
||||
|
||||
toolchain go1.21.0
|
||||
|
||||
replace (
|
||||
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
|
||||
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
|
||||
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
|
||||
// Downgraded to avoid bugs in following commits which caused simulations to fail.
|
||||
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
|
||||
)
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.7.2
|
||||
cosmossdk.io/client/v2 v2.0.0-beta.1
|
||||
cosmossdk.io/core v0.11.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.4
|
||||
cosmossdk.io/errors v1.0.0
|
||||
cosmossdk.io/log v1.2.1
|
||||
cosmossdk.io/math v1.2.0
|
||||
cosmossdk.io/store v1.0.0
|
||||
cosmossdk.io/tools/confix v0.1.0
|
||||
github.com/cometbft/cometbft v0.38.0
|
||||
github.com/cosmos/cosmos-db v1.0.0
|
||||
github.com/cosmos/cosmos-sdk v0.50.1
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/viper v1.17.0
|
||||
)
|
||||
|
||||
require (
|
||||
cosmossdk.io/collections v0.4.0 // indirect
|
||||
cosmossdk.io/x/tx v0.12.0 // indirect
|
||||
filippo.io/edwards25519 v1.0.0 // indirect
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
github.com/99designs/keyring v1.2.1 // indirect
|
||||
github.com/DataDog/zstd v1.5.5 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
||||
github.com/cespare/xxhash v1.1.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
|
||||
github.com/cockroachdb/errors v1.11.1 // indirect
|
||||
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
|
||||
github.com/cockroachdb/pebble v0.0.0-20231101195458-481da04154d6 // indirect
|
||||
github.com/cockroachdb/redact v1.1.5 // indirect
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/cometbft/cometbft-db v0.8.0 // indirect
|
||||
github.com/cosmos/btcutil v1.0.5 // indirect
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
|
||||
github.com/cosmos/go-bip39 v1.0.0 // indirect
|
||||
github.com/cosmos/gogogateway v1.2.0 // indirect
|
||||
github.com/cosmos/gogoproto v1.4.11 // indirect
|
||||
github.com/cosmos/iavl v1.0.0 // indirect
|
||||
github.com/cosmos/ics23/go v0.10.0 // indirect
|
||||
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
|
||||
github.com/creachadair/atomicfile v0.3.1 // indirect
|
||||
github.com/creachadair/tomledit v0.0.24 // indirect
|
||||
github.com/danieljoos/wincred v1.1.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
|
||||
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
|
||||
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
|
||||
github.com/dgraph-io/ristretto v0.1.1 // indirect
|
||||
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/dvsekhvalnov/jose2go v1.5.0 // indirect
|
||||
github.com/emicklei/dot v1.6.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/felixge/httpsnoop v1.0.2 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/getsentry/sentry-go v0.25.0 // indirect
|
||||
github.com/go-kit/kit v0.12.0 // indirect
|
||||
github.com/go-kit/log v0.2.1 // indirect
|
||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
|
||||
github.com/gogo/googleapis v1.4.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/glog v1.1.2 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/btree v1.1.2 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/orderedcode v0.0.1 // indirect
|
||||
github.com/gorilla/handlers v1.5.1 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
||||
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
|
||||
github.com/hashicorp/go-hclog v1.5.0 // indirect
|
||||
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
|
||||
github.com/hashicorp/go-metrics v0.5.1 // indirect
|
||||
github.com/hashicorp/go-plugin v1.5.2 // indirect
|
||||
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/hashicorp/yamux v0.1.1 // indirect
|
||||
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
|
||||
github.com/huandu/skiplist v1.2.0 // indirect
|
||||
github.com/iancoleman/strcase v0.3.0 // indirect
|
||||
github.com/improbable-eng/grpc-web v0.15.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jmhodges/levigo v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.17.2 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/lib/pq v1.10.7 // indirect
|
||||
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
|
||||
github.com/linxGnu/grocksdb v1.8.4 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
|
||||
github.com/minio/highwayhash v1.0.2 // indirect
|
||||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/mtibben/percent v0.2.1 // indirect
|
||||
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
|
||||
github.com/oklog/run v1.1.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/client_golang v1.17.0 // indirect
|
||||
github.com/prometheus/client_model v0.5.0 // indirect
|
||||
github.com/prometheus/common v0.45.0 // indirect
|
||||
github.com/prometheus/procfs v0.12.0 // indirect
|
||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
|
||||
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
||||
github.com/rs/cors v1.8.3 // indirect
|
||||
github.com/rs/zerolog v1.31.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.3.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/sasha-s/go-deadlock v0.3.1 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.10.0 // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
|
||||
github.com/tendermint/go-amino v0.16.0 // indirect
|
||||
github.com/tidwall/btree v1.7.0 // indirect
|
||||
github.com/zondax/hid v0.9.2 // indirect
|
||||
github.com/zondax/ledger-go v0.14.3 // indirect
|
||||
go.etcd.io/bbolt v1.3.7 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/term v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gotest.tools/v3 v3.5.1 // indirect
|
||||
nhooyr.io/websocket v1.8.6 // indirect
|
||||
pgregory.net/rapid v1.1.0 // indirect
|
||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||
)
|
8
proto/buf.gen.gogo.yaml
Normal file
8
proto/buf.gen.gogo.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
version: v1
|
||||
plugins:
|
||||
- name: gocosmos
|
||||
out: ..
|
||||
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm
|
||||
- name: grpc-gateway
|
||||
out: ..
|
||||
opt: logtostderr=true,allow_colon_final_segments=true
|
20
proto/buf.gen.pulsar.yaml
Normal file
20
proto/buf.gen.pulsar.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
version: v1
|
||||
managed:
|
||||
enabled: true
|
||||
go_package_prefix:
|
||||
default: github.com/alice/checkers/api
|
||||
except:
|
||||
- buf.build/googleapis/googleapis
|
||||
- buf.build/cosmos/gogo-proto
|
||||
- buf.build/cosmos/cosmos-proto
|
||||
- buf.build/cosmos/cosmos-sdk
|
||||
plugins:
|
||||
- name: go-pulsar
|
||||
out: ..
|
||||
opt: paths=source_relative,Mcosmos/app/v1alpha1/module.proto=cosmossdk.io/api/cosmos/app/v1alpha1,Mcosmos/base/v1beta1/coin.proto=cosmossdk.io/api/cosmos/base/v1beta1,Mcosmos/base/query/v1beta1/pagination.proto=cosmossdk.io/api/cosmos/base/query/v1beta1
|
||||
- name: go-grpc
|
||||
out: ..
|
||||
opt: paths=source_relative,Mcosmos/app/v1alpha1/module.proto=cosmossdk.io/api/cosmos/app/v1alpha1
|
||||
- name: go-cosmos-orm
|
||||
out: ..
|
||||
opt: paths=source_relative,Mcosmos/app/v1alpha1/module.proto=cosmossdk.io/api/cosmos/app/v1alpha1
|
28
proto/buf.lock
Normal file
28
proto/buf.lock
Normal file
@ -0,0 +1,28 @@
|
||||
# Generated by buf. DO NOT EDIT.
|
||||
version: v1
|
||||
deps:
|
||||
- remote: buf.build
|
||||
owner: cosmos
|
||||
repository: cosmos-proto
|
||||
commit: 1935555c206d4afb9e94615dfd0fad31
|
||||
digest: shake256:c74d91a3ac7ae07d579e90eee33abf9b29664047ac8816500cf22c081fec0d72d62c89ce0bebafc1f6fec7aa5315be72606717740ca95007248425102c365377
|
||||
- remote: buf.build
|
||||
owner: cosmos
|
||||
repository: cosmos-sdk
|
||||
commit: cf13c7d232dd405180c2af616fa8a075
|
||||
digest: shake256:769a38e306a98339b549bc96991c97fae8bd3ceb1a7646c7bfe9a74e406ab068372970fbc5abda1891e2f3c36527cf2d3a25f631739d36900787226e564bb612
|
||||
- remote: buf.build
|
||||
owner: cosmos
|
||||
repository: gogo-proto
|
||||
commit: 5e5b9fdd01804356895f8f79a6f1ddc1
|
||||
digest: shake256:0b85da49e2e5f9ebc4806eae058e2f56096ff3b1c59d1fb7c190413dd15f45dd456f0b69ced9059341c80795d2b6c943de15b120a9e0308b499e43e4b5fc2952
|
||||
- remote: buf.build
|
||||
owner: googleapis
|
||||
repository: googleapis
|
||||
commit: 28151c0d0a1641bf938a7672c500e01d
|
||||
digest: shake256:49215edf8ef57f7863004539deff8834cfb2195113f0b890dd1f67815d9353e28e668019165b9d872395871eeafcbab3ccfdb2b5f11734d3cca95be9e8d139de
|
||||
- remote: buf.build
|
||||
owner: protocolbuffers
|
||||
repository: wellknowntypes
|
||||
commit: 657250e6a39648cbb169d079a60bd9ba
|
||||
digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb
|
17
proto/buf.yaml
Normal file
17
proto/buf.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
version: v1
|
||||
deps:
|
||||
- buf.build/cosmos/cosmos-sdk # pin the Cosmos SDK version
|
||||
- buf.build/cosmos/cosmos-proto
|
||||
- buf.build/cosmos/gogo-proto
|
||||
- buf.build/googleapis/googleapis
|
||||
lint:
|
||||
use:
|
||||
- DEFAULT
|
||||
- COMMENTS
|
||||
- FILE_LOWER_SNAKE_CASE
|
||||
except:
|
||||
- UNARY_RPC
|
||||
- COMMENT_FIELD
|
||||
- SERVICE_SUFFIX
|
||||
- PACKAGE_VERSION_SUFFIX
|
||||
- RPC_REQUEST_STANDARD_NAME
|
0
proto/cerc/bond/module/v1/module.proto
Normal file
0
proto/cerc/bond/module/v1/module.proto
Normal file
0
proto/cerc/bond/v1/bond.proto
Normal file
0
proto/cerc/bond/v1/bond.proto
Normal file
1
proto/cerc/bond/v1/event.proto
Normal file
1
proto/cerc/bond/v1/event.proto
Normal file
@ -0,0 +1 @@
|
||||
// Not present in laconicd
|
0
proto/cerc/bond/v1/genesis.proto
Normal file
0
proto/cerc/bond/v1/genesis.proto
Normal file
0
proto/cerc/bond/v1/query.proto
Normal file
0
proto/cerc/bond/v1/query.proto
Normal file
0
proto/cerc/bond/v1/tx.proto
Normal file
0
proto/cerc/bond/v1/tx.proto
Normal file
16
scripts/init.sh
Executable file
16
scripts/init.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm -r ~/.laconic2d || true
|
||||
LACONIC2D_BIN=$(which laconic2d)
|
||||
# configure laconic2d
|
||||
$LACONIC2D_BIN config set client chain-id demo
|
||||
$LACONIC2D_BIN config set client keyring-backend test
|
||||
$LACONIC2D_BIN keys add alice
|
||||
$LACONIC2D_BIN keys add bob
|
||||
$LACONIC2D_BIN init test --chain-id demo --default-denom photon
|
||||
# update genesis
|
||||
$LACONIC2D_BIN genesis add-genesis-account alice 10000000photon --keyring-backend test
|
||||
$LACONIC2D_BIN genesis add-genesis-account bob 1000photon --keyring-backend test
|
||||
# create default validator
|
||||
$LACONIC2D_BIN genesis gentx alice 1000000photon --chain-id demo
|
||||
$LACONIC2D_BIN genesis collect-gentxs
|
29
scripts/protocgen.sh
Executable file
29
scripts/protocgen.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# TODO: Update paths following laconicd
|
||||
|
||||
set -e
|
||||
|
||||
echo "Generating gogo proto code"
|
||||
cd proto
|
||||
proto_dirs=$(find . -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
|
||||
for dir in $proto_dirs; do
|
||||
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
|
||||
# this regex checks if a proto file has its go_package set to github.com/alice/checkers/api/...
|
||||
# gogo proto files SHOULD ONLY be generated if this is false
|
||||
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf
|
||||
if grep -q "option go_package" "$file" && grep -H -o -c 'option go_package.*github.com/alice/checkers/api' "$file" | grep -q ':0$'; then
|
||||
buf generate --template buf.gen.gogo.yaml $file
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "Generating pulsar proto code"
|
||||
buf generate --template buf.gen.pulsar.yaml
|
||||
|
||||
cd ..
|
||||
|
||||
cp -r github.com/alice/checkers/* ./
|
||||
rm -rf api && mkdir api
|
||||
mv alice/checkers/* ./api
|
||||
rm -rf github.com alice
|
3
x/README.md
Normal file
3
x/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# `/x/{modules}`
|
||||
|
||||
This directory contains the code for your chain custom modules.
|
1
x/bond/README.md
Normal file
1
x/bond/README.md
Normal file
@ -0,0 +1 @@
|
||||
# bond
|
10
x/bond/codec.go
Normal file
10
x/bond/codec.go
Normal file
@ -0,0 +1,10 @@
|
||||
package bond
|
||||
|
||||
import (
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
)
|
||||
|
||||
// RegisterInterfaces registers the interfaces types with the interface registry.
|
||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||
// TODO: Implement
|
||||
}
|
11
x/bond/errors.go
Normal file
11
x/bond/errors.go
Normal file
@ -0,0 +1,11 @@
|
||||
package bond
|
||||
|
||||
import "cosmossdk.io/errors"
|
||||
|
||||
var (
|
||||
ErrIndexTooLong = errors.Register(ModuleName, 2, "index too long")
|
||||
ErrDuplicateAddress = errors.Register(ModuleName, 3, "duplicate address")
|
||||
ErrInvalidBlack = errors.Register(ModuleName, 4, "black address is invalid: %s")
|
||||
ErrInvalidRed = errors.Register(ModuleName, 5, "red address is invalid: %s")
|
||||
ErrGameNotParseable = errors.Register(ModuleName, 6, "game cannot be parsed")
|
||||
)
|
23
x/bond/keeper/keeper.go
Normal file
23
x/bond/keeper/keeper.go
Normal file
@ -0,0 +1,23 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/address"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
)
|
||||
|
||||
// TODO: Add genesis.go?
|
||||
|
||||
type Keeper struct {
|
||||
cdc codec.BinaryCodec
|
||||
addressCodec address.Codec
|
||||
|
||||
// TODO: state management
|
||||
|
||||
// TODO: Later: add bond usage keepers
|
||||
}
|
||||
|
||||
// NewKeeper creates a new Keeper instance
|
||||
// TODO: Implement
|
||||
func NewKeeper(cdc codec.BinaryCodec, addressCodec address.Codec) Keeper {
|
||||
return Keeper{}
|
||||
}
|
15
x/bond/keeper/msg_server.go
Normal file
15
x/bond/keeper/msg_server.go
Normal file
@ -0,0 +1,15 @@
|
||||
package keeper
|
||||
|
||||
type msgServer struct {
|
||||
k Keeper
|
||||
}
|
||||
|
||||
// TODO: Generate types
|
||||
// var _ bond.MsgServer = msgServer{}
|
||||
|
||||
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
||||
// func NewMsgServerImpl(keeper Keeper) bond.MsgServer {
|
||||
// return &msgServer{k: keeper}
|
||||
// }
|
||||
|
||||
// TODO: Add write methods
|
15
x/bond/keeper/query_server.go
Normal file
15
x/bond/keeper/query_server.go
Normal file
@ -0,0 +1,15 @@
|
||||
package keeper
|
||||
|
||||
type queryServer struct {
|
||||
k Keeper
|
||||
}
|
||||
|
||||
// TODO: Generate types
|
||||
// var _ bond.QueryServer = queryServer{}
|
||||
|
||||
// NewQueryServerImpl returns an implementation of the module QueryServer.
|
||||
// func NewQueryServerImpl(k Keeper) checkers.QueryServer {
|
||||
// return queryServer{k}
|
||||
// }
|
||||
|
||||
// TODO: Add read methods
|
5
x/bond/keys.go
Normal file
5
x/bond/keys.go
Normal file
@ -0,0 +1,5 @@
|
||||
package bond
|
||||
|
||||
const ModuleName = "bond"
|
||||
|
||||
// TODO: Add required keys
|
1
x/bond/module/autocli.go
Normal file
1
x/bond/module/autocli.go
Normal file
@ -0,0 +1 @@
|
||||
package module
|
1
x/bond/module/depinject.go
Normal file
1
x/bond/module/depinject.go
Normal file
@ -0,0 +1 @@
|
||||
package module
|
4
x/bond/module/module.go
Normal file
4
x/bond/module/module.go
Normal file
@ -0,0 +1,4 @@
|
||||
package module
|
||||
|
||||
type Module struct {
|
||||
}
|
3
x/bond/params.go
Normal file
3
x/bond/params.go
Normal file
@ -0,0 +1,3 @@
|
||||
package bond
|
||||
|
||||
// TODO: Add required params types
|
Loading…
Reference in New Issue
Block a user