<commit_before>package genesis

import (
	"bytes"
	"encoding/csv"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"os"
	"strconv"

	"github.com/eris-ltd/common/go/common"
	stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types"
	ptypes "github.com/eris-ltd/eris-db/permission/types"

	"github.com/tendermint/go-crypto"
	wire "github.com/tendermint/go-wire"
)

//------------------------------------------------------------------------------------
// core functions

func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) ([]byte, error) {
	var genDoc *stypes.GenesisDoc
	var err error

	// TODO [eb] eliminate reading priv_val ... [zr] where?
	if accountsPathCSV == "" || validatorsPathCSV == "" {
		return []byte{}, fmt.Errorf("both accounts.csv and validators.csv is required")

	}

	pubkeys, amts, names, perms, setbits, err := parseCsv(validatorsPathCSV)
	if err != nil {
		return nil, err
	}

	pubkeysA, amtsA, namesA, permsA, setbitsA, err := parseCsv(accountsPathCSV)
	if err != nil {
		return nil, err
	}

	genDoc = newGenDoc(chainID, len(pubkeys), len(pubkeysA))
	for i, pk := range pubkeys {
		genDocAddValidator(genDoc, pk, amts[i], names[i], perms[i], setbits[i], i)
	}
	for i, pk := range pubkeysA {
		genDocAddAccount(genDoc, pk, amtsA[i], namesA[i], permsA[i], setbitsA[i], i)
	}

	buf, buf2, n := new(bytes.Buffer), new(bytes.Buffer), new(int)
	wire.WriteJSON(genDoc, buf, n, &err)
	if err != nil {
		return nil, err
	}
	if err := json.Indent(buf2, buf.Bytes(), "", "\t"); err != nil {
		return nil, err
	}
	genesisBytes := buf2.Bytes()

	return genesisBytes, nil
}

//-----------------------------------------------------------------------------
// gendoc convenience functions

func newGenDoc(chainID string, nVal, nAcc int) *stypes.GenesisDoc {
	genDoc := stypes.GenesisDoc{
		ChainID: chainID,
		// GenesisTime: time.Now(),<commit_msg>working genesis generator; prints to stdout<commit_after>package genesis

import (
	"bytes"
	"encoding/csv"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"os"
	"strconv"

	"github.com/eris-ltd/common/go/common"
	stypes "github.com/eris-ltd/eris-db/manager/eris-mint/state/types"
	ptypes "github.com/eris-ltd/eris-db/permission/types"

	"github.com/tendermint/go-crypto"
	wire "github.com/tendermint/go-wire"
)

//------------------------------------------------------------------------------------
// core functions

func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) error {
	var genDoc *stypes.GenesisDoc

	// TODO [eb] eliminate reading priv_val ... [zr] where?
	if accountsPathCSV == "" || validatorsPathCSV == "" {
		return fmt.Errorf("both accounts.csv and validators.csv is required")

	}

	pubkeys, amts, names, perms, setbits, err := parseCsv(validatorsPathCSV)
	if err != nil {
		return err
	}

	pubkeysA, amtsA, namesA, permsA, setbitsA, err := parseCsv(accountsPathCSV)
	if err != nil {
		return err
	}

	genDoc = newGenDoc(chainID, len(pubkeys), len(pubkeysA))
	for i, pk := range pubkeys {
		genDocAddValidator(genDoc, pk, amts[i], names[i], perms[i], setbits[i], i)
	}
	for i, pk := range pubkeysA {
		genDocAddAccount(genDoc, pk, amtsA[i], namesA[i], permsA[i], setbitsA[i], i)
	}

	buf, buf2, n := new(bytes.Buffer), new(bytes.Buffer), new(int)
	wire.WriteJSON(genDoc, buf, n, &err)
	if err != nil {
		return err
	}
	if err := json.Indent(buf2, buf.Bytes(), "", "\t"); err != nil {
		return err
	}
	genesisString := buf2.String()
	fmt.Println(genesisString)

	return nil
}

//-----------------------------------------------------------------------------
// gendoc convenience functions

func newGenDoc(chainID string, nVal, nAcc int) *stypes.GenesisDoc {
	genDoc := stypes.GenesisDoc{
		ChainID: chainID,
		// GenesisTime: time.Now(),
{'fraction_non_alphanumeric': 0.22801390002673083, 'fraction_numerical': 0.0016038492381716118, 'mean_word_length': 2.834016393442623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5910200', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1361, 'n_words': 299}