Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: configure bech32prefix in genesis #59

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export the following variables:
export EXECUTABLE="rollapp-wasm"
export ROLLAPP_CHAIN_ID="rollappwasm_1234-1"
export KEY_NAME_ROLLAPP="rol-user"
export BECH32="rol"
export BASE_DENOM="awsm"
export DENOM=$(echo "$BASE_DENOM" | sed 's/^.//')
export MONIKER="$ROLLAPP_CHAIN_ID-sequencer"
Expand Down
3 changes: 1 addition & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ import (
)

const (
AccountAddressPrefix = "rol"
Name = "rollapp-wasm"
Name = "rollapp-wasm"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/bcdevtools/wasm-block-explorer-rpc-cosmos v1.1.1
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cosmos/ibc-go/v6 v6.3.0
github.com/dymensionxyz/dymension-rdk v1.5.0-beta
github.com/dymensionxyz/dymension-rdk v1.5.0-beta.0.20240423161402-f6997e0d1a5c
github.com/dymensionxyz/dymint v1.0.1-alpha.0.20240414124654-eb08e30da2c5
github.com/ethereum/go-ethereum v1.12.0
github.com/gorilla/mux v1.8.1
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,10 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/cosmosclient v0.4.2-beta h1:sokBefcN1tIOlUKmB8Q2E9XMJ93LueqtFThiM/kA4DI=
github.com/dymensionxyz/cosmosclient v0.4.2-beta/go.mod h1:GQQu3ITEjWfi5ULR2B6X2i2YZNennY1yzcT5qdL4MGI=
github.com/dymensionxyz/dymension-rdk v1.5.0-beta h1:whKxcgcXB3l7rK7F0Vnq0EF0Ri9475CSZTseaUQN6o0=
github.com/dymensionxyz/dymension-rdk v1.5.0-beta/go.mod h1:kzNFKt3yfFzZ2u3+47Nlpobub3/UXsICOg1WmGud3DE=
github.com/dymensionxyz/dymension-rdk v1.5.0-beta.0.20240423161402-f6997e0d1a5c h1:ee4pw3mkuYLQzwhTbiwD5msPvwoDvuCHrEMSBrZMcPc=
github.com/dymensionxyz/dymension-rdk v1.5.0-beta.0.20240423161402-f6997e0d1a5c/go.mod h1:kzNFKt3yfFzZ2u3+47Nlpobub3/UXsICOg1WmGud3DE=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240411195658-f7cd96f53b56 h1:cmpJYdRviuUfmlJdHrcAND8Jd6JIY4rp63bWAQzPr54=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240411195658-f7cd96f53b56/go.mod h1:3Pfrr8j/BR9ztNKztGfC5PqDiO6CcrzMLCJtFtPEVW4=
github.com/dymensionxyz/dymint v1.0.1-alpha.0.20240411212116-3cd56c57c597 h1:tIvgP75oCriRaxkOb2KtL8cExX2/QGlZQvY9qxJbr98=
github.com/dymensionxyz/dymint v1.0.1-alpha.0.20240411212116-3cd56c57c597/go.mod h1:0h9bBg5vdTqkAdiWIaKv5UutD98+KUNODDy80dXMW9o=
github.com/dymensionxyz/dymint v1.0.1-alpha.0.20240414124654-eb08e30da2c5 h1:7UEyfIyW54zJXUL4hSAJdLol7CkJtD0eL865vLTf9Lg=
github.com/dymensionxyz/dymint v1.0.1-alpha.0.20240414124654-eb08e30da2c5/go.mod h1:0h9bBg5vdTqkAdiWIaKv5UutD98+KUNODDy80dXMW9o=
github.com/dymensionxyz/evmos/v12 v12.1.6-dymension-v0.3 h1:vmAdUGUc4rTIiO3Phezr7vGq+0uPDVKSA4WAe8+yl6w=
Expand Down
13 changes: 6 additions & 7 deletions rollappd/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
tmos "github.com/tendermint/tendermint/libs/os"
)

const (
Expand Down Expand Up @@ -128,7 +127,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
}

genFile := config.GenesisFile()
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
appState, genDoc, err := GenesisStateFromGenFile(genFile)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}
Expand Down Expand Up @@ -186,13 +185,13 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
}
appState[banktypes.ModuleName] = bankGenStateBz

appStateJSON, err := json.Marshal(appState)
genDoc["app_state"] = appState
genDocBytes, err := json.MarshalIndent(genDoc, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
return err
}

genDoc.AppState = appStateJSON
return genutil.ExportGenesisFile(genDoc, genFile)
return tmos.WriteFile(genFile, genDocBytes, 0o644)
},
}

Expand Down
100 changes: 93 additions & 7 deletions rollappd/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"encoding/json"
"errors"
"fmt"
"io"
"os"

Expand All @@ -28,6 +30,7 @@ import (
tmcfg "github.com/tendermint/tendermint/config"
tmcli "github.com/tendermint/tendermint/libs/cli"
tmlog "github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/CosmWasm/wasmd/x/wasm"
Expand All @@ -36,6 +39,7 @@ import (
berpcconfig "github.com/bcdevtools/block-explorer-rpc-cosmos/be_rpc/config"
rdkserver "github.com/dymensionxyz/dymension-rdk/server"
"github.com/dymensionxyz/dymension-rdk/utils"
rdk_genutilcli "github.com/dymensionxyz/dymension-rdk/x/genutil/client/cli"
dymintconf "github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/rollapp-wasm/app"
"github.com/dymensionxyz/rollapp-wasm/app/params"
Expand Down Expand Up @@ -106,6 +110,18 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
//create Block Explorer Json-RPC toml config file
berpcconfig.EnsureRoot(home, berpcconfig.DefaultBeJsonRpcConfig())

// Set config
sdkconfig := sdk.GetConfig()
cfg := serverCtx.Config
genFile := cfg.GenesisFile()
if tmos.FileExists(genFile) {
genDoc, _ := GenesisDocFromFile(genFile)
utils.SetPrefixes(sdkconfig, genDoc["bech32_prefix"].(string))
} else {
utils.SetPrefixes(sdkconfig, "rol")
}
sdkconfig.Seal()

return nil
},
}
Expand Down Expand Up @@ -144,17 +160,38 @@ func initRootCmd(
rootCmd *cobra.Command,
encodingConfig params.EncodingConfig,
) {
// Set config
sdkconfig := sdk.GetConfig()
utils.SetPrefixes(sdkconfig, app.AccountAddressPrefix)
sdkconfig.Seal()

ac := appCreator{
encCfg: encodingConfig,
}

initCmd := genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome)
initCmd.Flags().String(FlagBech32Prefix, "rol", "set bech32 prefix for rollapp, if left blank default value is 'rol'")

initCmd.PostRunE = func(cmd *cobra.Command, args []string) error {
prefix, _ := initCmd.Flags().GetString(FlagBech32Prefix)

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config
path := config.GenesisFile()

genDoc, err := GenesisDocFromFile(path)
if err != nil {
fmt.Println("Failed to read genesis doc from file", err)
}

genDoc["bech32_prefix"] = prefix

genDocBytes, err := json.MarshalIndent(genDoc, "", " ")
if err != nil {
return err
}
return tmos.WriteFile(path, genDocBytes, 0o644)

}

rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
initCmd,
rdk_genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),
genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome),

Expand Down Expand Up @@ -306,3 +343,52 @@ func (ac appCreator) appExport(

return rollapp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
}

// GenesisStateFromGenFile creates the core parameters for genesis initialization
// for the application.
//
// NOTE: The pubkey input is this machines pubkey.
func GenesisStateFromGenFile(genFile string) (genesisState map[string]json.RawMessage, genDoc map[string]interface{}, err error) {
if !tmos.FileExists(genFile) {
return genesisState, genDoc,
fmt.Errorf("%s does not exist, run `init` first", genFile)
}

genDoc, err = GenesisDocFromFile(genFile)
if err != nil {
return genesisState, genDoc, err
}

bz, err := json.Marshal(genDoc["app_state"])
if err != nil {
return genesisState, genDoc, err
}

err = json.Unmarshal(bz, &genesisState)
return genesisState, genDoc, err
}

// GenesisDocFromFile reads JSON data from a file and unmarshalls it into a GenesisDoc.
func GenesisDocFromFile(genDocFile string) (map[string]interface{}, error) {
jsonBlob, err := os.ReadFile(genDocFile)
if err != nil {
return nil, fmt.Errorf("couldn't read GenesisDoc file: %w", err)
}

genDoc, err := GenesisDocFromJSON(jsonBlob)
if err != nil {
return nil, fmt.Errorf("error reading GenesisDoc at %s: %w", genDocFile, err)
}
return genDoc, nil
}

// GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.
func GenesisDocFromJSON(jsonBlob []byte) (map[string]interface{}, error) {
genDoc := make(map[string]interface{})
err := json.Unmarshal(jsonBlob, &genDoc)
if err != nil {
return nil, err
}

return genDoc, err
}
1 change: 1 addition & 0 deletions rollappd/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
FlagUnsafeSkipUpgrades = "unsafe-skip-upgrades"
FlagTrace = "trace"
FlagInvCheckPeriod = "inv-check-period"
FlagBech32Prefix = "bech32-prefix"

FlagPruning = "pruning"
FlagPruningKeepRecent = "pruning-keep-recent"
Expand Down
Loading