func CollectStdTxs(cdc *codec.Codec, name, genTxsDir string,
	genDoc tmtypes.GenesisDoc,
) (appGenTxs []authtypes.StdTx, persistentPeers string, err error) {
	var fos []os.FileInfo
	fos, err = ioutil.ReadDir(genTxsDir)
	if err != nil {
		return appGenTxs, persistentPeers, err
	}
	var appState map[string]json.RawMessage
	if err := cdc.UnmarshalJSON(genDoc.AppState, &appState); err != nil {
		return appGenTxs, persistentPeers, err
	}
	addrMap := make(map[string]auth.Account)
	IterateGenesisAccounts(cdc, appState,
		func(acc auth.Account) (stop bool) {
			addrMap[acc.Address.String()] = acc
			return false
		},
	)
	var addressesIPs []string
	for _, fo := range fos {
		filename := filepath.Join(genTxsDir, fo.Name())
		if !fo.IsDir() && (filepath.Ext(filename) != ".json") {
			continue
		}
		var jsonRawTx []byte
		if jsonRawTx, err = ioutil.ReadFile(filename); err != nil {
			return appGenTxs, persistentPeers, err
		}
		var genStdTx authtypes.StdTx
		if err = cdc.UnmarshalJSON(jsonRawTx, &genStdTx); err != nil {
			return appGenTxs, persistentPeers, err
		}
		appGenTxs = append(appGenTxs, genStdTx)
		nodeAddrIP := genStdTx.GetMemo()
		if len(nodeAddrIP) == 0 {
			return appGenTxs, persistentPeers, sdk.ErrUnknownRequest(
				fmt.Sprintf("couldn't find node's address and IP in %s", fo.Name()))
		}
		msgs := genStdTx.GetMsgs()
		if len(msgs) != 1 {
			return appGenTxs, persistentPeers, sdk.ErrUnknownRequest(
				"each genesis transaction must provide a single genesis message")
		}
		msg := msgs[0].(validator.MsgCreateValidator)
		account := msg.Signer.String()
		_, valOk := addrMap[account]
		if !valOk {
			return appGenTxs, persistentPeers, sdk.ErrUnknownRequest(
				fmt.Sprintf("Error account %v not in genesis.json: %+v", account, addrMap))
		}
		if msg.Description.Name != name {
			addressesIPs = append(addressesIPs, nodeAddrIP)
		}
	}
	sort.Strings(addressesIPs)
	persistentPeers = strings.Join(addressesIPs, ",")
	return appGenTxs, persistentPeers, nil
}
CollectStdTxs processes and validates application's genesis StdTxs and returns
the list of appGenTxs, and persistent peers required to generate genesis.json.
nolint:funlen
package genutil
import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"sort"
	"strings"
	"github.com/cosmos/cosmos-sdk/codec"
	sdk "github.com/cosmos/cosmos-sdk/types"
	authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
	cfg "github.com/tendermint/tendermint/config"
	tmtypes "github.com/tendermint/tendermint/types"
	"github.com/zigbee-alliance/distributed-compliance-ledger/x/auth"
	"github.com/zigbee-alliance/distributed-compliance-ledger/x/genutil/types"
	"github.com/zigbee-alliance/distributed-compliance-ledger/x/validator"
)
func GenAppStateFromConfig(cdc *codec.Codec, config *cfg.Config,
	initCfg InitConfig, genDoc tmtypes.GenesisDoc,
) (appState json.RawMessage, err error) {
	appGenTxs, persistentPeers, err := CollectStdTxs(
		cdc, config.Moniker, initCfg.GenTxsDir, genDoc)
	if err != nil {
		return appState, err
	}
	config.P2P.PersistentPeers = persistentPeers
	cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config)
	if len(appGenTxs) == 0 {
		return appState, sdk.ErrUnknownRequest("there must be at least one genesis tx")
	}
	appGenesisState, err := GenesisStateFromGenDoc(cdc, genDoc)
	if err != nil {
		return appState, err
	}
	appGenesisState, err = SetGenTxsInAppGenesisState(cdc, appGenesisState, appGenTxs)
	if err != nil {
		return appState, err
	}
	appState, err = codec.MarshalJSONIndent(cdc, appGenesisState)
	if err != nil {
		return appState, err
	}
	genDoc.AppState = appState
	err = ExportGenesisFile(&genDoc, config.GenesisFile())
	return appState, err
}