diff --git a/genesis/gen_test.go b/genesis/gen_test.go index 30d5f9c511df7efbd372c6a44814b1c0d64070c8..18ff69a775adddfdacfe4226c103299619359f26 100644 --- a/genesis/gen_test.go +++ b/genesis/gen_test.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "testing" + "time" ) // set the chain ID @@ -149,7 +150,8 @@ func TestKnownCSV(t *testing.T) { } // create the genesis file - genesisFileWritten, err := GenerateKnown(chainID, accountsCSVpath, validatorsCSVpath) + // NOTE: [ben] set time to zero time, "genesis_time": "0001-01-01T00:00:00.000Z" + genesisFileWritten, err := generateKnownWithTime(chainID, accountsCSVpath, validatorsCSVpath, time.Time{}) if err != nil { t.Fatal(err) } diff --git a/genesis/make_genesis_file.go b/genesis/make_genesis_file.go index c4324366ccf4f1c6195684ce32c59592ddc37712..f67a86d87084dccc3cbfe288f60cf21e2dd70d0c 100644 --- a/genesis/make_genesis_file.go +++ b/genesis/make_genesis_file.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "strconv" + "time" ptypes "github.com/eris-ltd/eris-db/permission/types" "github.com/eris-ltd/eris-db/util" @@ -17,9 +18,25 @@ import ( ) //------------------------------------------------------------------------------------ -// core functions +// interface functions that are consumed by monax tooling +// TODO: [ben] these interfaces will be deprecated from v0.17 func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) (string, error) { + return generateKnownWithTime(chainID, accountsPathCSV, validatorsPathCSV, + // set the timestamp for the genesis + time.Now()) +} + +//------------------------------------------------------------------------------------ +// core functions that provide functionality for monax tooling in v0.16 + +// GenerateKnownWithTime takes chainId, an accounts and validators CSV filepath +// and a timestamp to generate the string of `genesis.json` +// NOTE: [ben] is introduced as technical debt to preserve the signature +// of GenerateKnown but in order to introduce the timestamp gradually +// This will be deprecated in v0.17 +func generateKnownWithTime(chainID, accountsPathCSV, validatorsPathCSV string, + genesisTime time.Time) (string, error) { var genDoc *GenesisDoc // TODO [eb] eliminate reading priv_val ... [zr] where? @@ -37,7 +54,7 @@ func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) (string, return "", err } - genDoc = newGenDoc(chainID, len(pubkeys), len(pubkeysA)) + genDoc = newGenDoc(chainID, genesisTime, len(pubkeys), len(pubkeysA)) for i, pk := range pubkeys { genDocAddValidator(genDoc, pk, amts[i], names[i], perms[i], setbits[i], i) } @@ -60,10 +77,10 @@ func GenerateKnown(chainID, accountsPathCSV, validatorsPathCSV string) (string, //----------------------------------------------------------------------------- // gendoc convenience functions -func newGenDoc(chainID string, nVal, nAcc int) *GenesisDoc { +func newGenDoc(chainID string, genesisTime time.Time, nVal, nAcc int) *GenesisDoc { genDoc := GenesisDoc{ - ChainID: chainID, - // GenesisTime: time.Now(), + ChainID: chainID, + GenesisTime: genesisTime, } genDoc.Accounts = make([]GenesisAccount, nAcc) genDoc.Validators = make([]GenesisValidator, nVal)