Skip to content
Snippets Groups Projects
Commit 34688ac3 authored by zramsay's avatar zramsay
Browse files

small tweaks to ease use as a library

parent dc3afdf6
No related branches found
No related tags found
No related merge requests found
package commands package commands
import ( import (
"fmt"
"github.com/eris-ltd/eris-db/genesis" "github.com/eris-ltd/eris-db/genesis"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -25,8 +27,11 @@ var GenesisGenCmd = &cobra.Command{ ...@@ -25,8 +27,11 @@ var GenesisGenCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
genesis.GenerateKnown(args[0], AccountsPathFlag, ValidatorsPathFlag) genesisFile, err := genesis.GenerateKnown(args[0], AccountsPathFlag, ValidatorsPathFlag)
if err != nil {
panic(err)
}
fmt.Println(genesisFile) // may want to save somewhere instead
}, },
} }
......
...@@ -20,23 +20,23 @@ import ( ...@@ -20,23 +20,23 @@ import (
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// core functions // core functions
func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) error { func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) (string, error) {
var genDoc *stypes.GenesisDoc var genDoc *stypes.GenesisDoc
// TODO [eb] eliminate reading priv_val ... [zr] where? // TODO [eb] eliminate reading priv_val ... [zr] where?
if accountsPathCSV == "" || validatorsPathCSV == "" { if accountsPathCSV == "" || validatorsPathCSV == "" {
return fmt.Errorf("both accounts.csv and validators.csv is required") return "", fmt.Errorf("both accounts.csv and validators.csv is required")
} }
pubkeys, amts, names, perms, setbits, err := parseCsv(validatorsPathCSV) pubkeys, amts, names, perms, setbits, err := parseCsv(validatorsPathCSV)
if err != nil { if err != nil {
return err return "", err
} }
pubkeysA, amtsA, namesA, permsA, setbitsA, err := parseCsv(accountsPathCSV) pubkeysA, amtsA, namesA, permsA, setbitsA, err := parseCsv(accountsPathCSV)
if err != nil { if err != nil {
return err return "", err
} }
genDoc = newGenDoc(chainID, len(pubkeys), len(pubkeysA)) genDoc = newGenDoc(chainID, len(pubkeys), len(pubkeysA))
...@@ -50,15 +50,13 @@ func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) error { ...@@ -50,15 +50,13 @@ func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) error {
buf, buf2, n := new(bytes.Buffer), new(bytes.Buffer), new(int) buf, buf2, n := new(bytes.Buffer), new(bytes.Buffer), new(int)
wire.WriteJSON(genDoc, buf, n, &err) wire.WriteJSON(genDoc, buf, n, &err)
if err != nil { if err != nil {
return err return "", err
} }
if err := json.Indent(buf2, buf.Bytes(), "", "\t"); err != nil { if err := json.Indent(buf2, buf.Bytes(), "", "\t"); err != nil {
return err return "", err
} }
genesisString := buf2.String()
fmt.Println(genesisString)
return nil return buf2.String(), nil
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment