basecoin init --chain-id

This commit is contained in:
Ethan Buchman 2017-06-21 02:47:42 -04:00
parent 05e23eda06
commit 824050a0b4
4 changed files with 21 additions and 13 deletions

View File

@ -29,6 +29,7 @@ BREAKING CHANGES:
- removed `example-plugin`, put `counter` inside `docs/guide`
ENHANCEMENTS:
- `basecoin init` support `--chain-id`
- intergrates tendermint 0.10.0 (not the rc-2, but the real thing)
- commands return error code (1) on failure for easier script testing
- add `reset_all` to basecli, and never delete keys on `init`

View File

@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"github.com/spf13/cobra"
)
@ -17,6 +18,18 @@ var (
}
)
//flags
var (
chainIDFlag string
)
func init() {
flags := []Flag2Register{
{&chainIDFlag, "chain-id", "test_chain_id", "Chain ID"},
}
RegisterFlags(InitCmd, flags)
}
// returns 1 iff it set a file, otherwise 0 (so we can add them)
func setupFile(path, data string, perm os.FileMode) (int, error) {
_, err := os.Stat(path)
@ -47,7 +60,7 @@ func initCmd(cmd *cobra.Command, args []string) error {
privValFile := cfg.PrivValidatorFile()
keyFile := path.Join(cfg.RootDir, "key.json")
mod1, err := setupFile(genesisFile, GetGenesisJSON(userAddr), 0644)
mod1, err := setupFile(genesisFile, GetGenesisJSON(chainIDFlag, userAddr), 0644)
if err != nil {
return err
}
@ -55,7 +68,7 @@ func initCmd(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
mod3, err := setupFile(key1File, KeyJSON, 0400)
mod3, err := setupFile(keyFile, KeyJSON, 0400)
if err != nil {
return err
}
@ -89,10 +102,10 @@ var PrivValJSON = `{
// GetGenesisJSON returns a new tendermint genesis with Basecoin app_options
// that grant a large amount of "mycoin" to a single address
// TODO: A better UX for generating genesis files
func GetGenesisJSON(addr string) string {
func GetGenesisJSON(chainID, addr string) string {
return fmt.Sprintf(`{
"app_hash": "",
"chain_id": "test_chain_id",
"chain_id": "%s",
"genesis_time": "0001-01-01T00:00:00.000Z",
"validators": [
{
@ -115,7 +128,7 @@ func GetGenesisJSON(addr string) string {
]
}]
}
}`, addr)
}`, chainID, addr)
}
// TODO: remove this once not needed for relay

View File

@ -7,7 +7,7 @@ import (
"github.com/tendermint/tmlibs/cli"
"github.com/tendermint/basecoin/cmd/commands"
"github.com/tendermint/basecoin/cmd/basecoin/commands"
"github.com/tendermint/basecoin/docs/guide/counter/plugins/counter"
"github.com/tendermint/basecoin/types"
)

View File

@ -24,13 +24,7 @@ initServer() {
assertNotNull "no chain" $2
CHAIN=$2
SERVER_LOG=$1/${SERVER_EXE}.log
${SERVER_EXE} init --home=$SERVE_DIR >>$SERVER_LOG
#change the genesis to the first account
GENKEY=$(${CLIENT_EXE} keys get ${RICH} -o json | jq .pubkey.data)
GENJSON=$(cat $SERVE_DIR/genesis.json)
echo $GENJSON | jq '.app_options.accounts[0].pub_key.data='$GENKEY \
| jq ".chain_id=\"$2\"" > $SERVE_DIR/genesis.json
${SERVER_EXE} init --chain-id $CHAIN $(${CLIENT_EXE} keys get ${RICH} | awk '{print $2}') --home=$SERVE_DIR >>$SERVER_LOG
# optionally set the port
if [ -n "$3" ]; then