genesis: support genesis creation under specific folder

This commit is contained in:
Alan Chen 2017-09-01 11:46:44 +08:00
parent 1139e3e983
commit b226460511
1 changed files with 9 additions and 5 deletions

View File

@ -64,11 +64,7 @@ func New(options ...Option) *core.Genesis {
return genesis
}
func NewFile(isQuorum bool, options ...Option) string {
dir, err := generateRandomDir()
if err != nil {
log.Fatalf("Failed to create random directory, err: %v", err)
}
func NewFileAt(dir string, isQuorum bool, options ...Option) string {
genesis := New(options...)
if err := Save(dir, genesis, isQuorum); err != nil {
log.Fatalf("Failed to save genesis to '%s', err: %v", dir, err)
@ -77,6 +73,14 @@ func NewFile(isQuorum bool, options ...Option) string {
return filepath.Join(dir, FileName)
}
func NewFile(isQuorum bool, options ...Option) string {
dir, err := generateRandomDir()
if err != nil {
log.Fatalf("Failed to create random directory, err: %v", err)
}
return NewFileAt(dir, isQuorum, options...)
}
func Save(dataDir string, genesis *core.Genesis, isQuorum bool) error {
filePath := filepath.Join(dataDir, FileName)