From 1476b9596385219f4c8f23570f87e8b7377a8d8c Mon Sep 17 00:00:00 2001 From: Benjamin Bollen <ben@monax.io> Date: Sat, 11 Feb 2017 20:49:41 +0100 Subject: [PATCH] genesis: re-introduce GenesisTime in GenesisDoc --- genesis/gen_test.go | 4 +++- genesis/make_genesis_file.go | 27 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/genesis/gen_test.go b/genesis/gen_test.go index 30d5f9c5..18ff69a7 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 c4324366..f67a86d8 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) -- GitLab