2019-05-16 08:25:32 -07:00
package cli
import (
"encoding/json"
"path/filepath"
2019-08-30 06:59:41 -07:00
"github.com/pkg/errors"
2019-05-16 08:25:32 -07:00
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/tendermint/libs/cli"
tmtypes "github.com/tendermint/tendermint/types"
2019-12-23 08:05:47 -08:00
"github.com/cosmos/cosmos-sdk/client/flags"
2019-05-16 08:25:32 -07:00
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
2019-07-24 14:37:03 -07:00
"github.com/cosmos/cosmos-sdk/x/genutil/types"
2019-05-16 08:25:32 -07:00
)
const flagGenTxDir = "gentx-dir"
// CollectGenTxsCmd - return the cobra command to collect genesis transactions
2020-06-12 09:23:08 -07:00
func CollectGenTxsCmd ( ctx * server . Context , cdc codec . JSONMarshaler , genBalIterator types . GenesisBalancesIterator , defaultNodeHome string ) * cobra . Command {
2019-05-16 08:25:32 -07:00
cmd := & cobra . Command {
Use : "collect-gentxs" ,
Short : "Collect genesis txs and output a genesis.json file" ,
RunE : func ( _ * cobra . Command , _ [ ] string ) error {
config := ctx . Config
config . SetRoot ( viper . GetString ( cli . HomeFlag ) )
2020-07-05 09:56:17 -07:00
2019-12-23 08:05:47 -08:00
name := viper . GetString ( flags . FlagName )
2019-05-16 08:25:32 -07:00
nodeID , valPubKey , err := genutil . InitializeNodeValidatorFiles ( config )
if err != nil {
2019-08-30 06:59:41 -07:00
return errors . Wrap ( err , "failed to initialize node validator files" )
2019-05-16 08:25:32 -07:00
}
genDoc , err := tmtypes . GenesisDocFromFile ( config . GenesisFile ( ) )
if err != nil {
2019-08-30 06:59:41 -07:00
return errors . Wrap ( err , "failed to read genesis doc from file" )
2019-05-16 08:25:32 -07:00
}
genTxsDir := viper . GetString ( flagGenTxDir )
if genTxsDir == "" {
genTxsDir = filepath . Join ( config . RootDir , "config" , "gentx" )
}
toPrint := newPrintInfo ( config . Moniker , genDoc . ChainID , nodeID , genTxsDir , json . RawMessage ( "" ) )
2020-06-13 00:41:45 -07:00
initCfg := types . NewInitConfig ( genDoc . ChainID , genTxsDir , name , nodeID , valPubKey )
2019-05-16 08:25:32 -07:00
2020-01-30 13:31:16 -08:00
appMessage , err := genutil . GenAppStateFromConfig ( cdc , config , initCfg , * genDoc , genBalIterator )
2019-05-16 08:25:32 -07:00
if err != nil {
2019-08-30 06:59:41 -07:00
return errors . Wrap ( err , "failed to get genesis app state from config" )
2019-05-16 08:25:32 -07:00
}
toPrint . AppMessage = appMessage
// print out some key information
return displayInfo ( cdc , toPrint )
} ,
}
2019-05-16 18:34:54 -07:00
cmd . Flags ( ) . String ( cli . HomeFlag , defaultNodeHome , "node's home directory" )
2020-07-05 09:56:17 -07:00
cmd . Flags ( ) . String ( flagGenTxDir , "" , "override default \"gentx\" directory from which collect and execute genesis transactions; default [--home]/config/gentx/" )
2020-05-02 12:26:59 -07:00
2019-05-16 08:25:32 -07:00
return cmd
}
// DONTCOVER