Skip to content

Commit

Permalink
fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gordon-sero committed May 12, 2019
1 parent ddfb482 commit f63f85b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
4 changes: 3 additions & 1 deletion zero/lstate/state1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func SetLastNum(putter serodb.Putter, num uint64) {
const delay_block_count = 6

func (self *State1) Parse(last_chose uint64) (chose uint64) {
self.MakesureEnv()

bc := light_ref.Ref_inst.Bc
tks := bc.GetTks()
next_num := GetLastNum(&self.db)
Expand Down Expand Up @@ -157,6 +159,6 @@ func (self *State1) Parse(last_chose uint64) (chose uint64) {
log.Info("STATE1 PARSE", "t", chose, "c", next_num-1)
}

return
return chose

}
27 changes: 23 additions & 4 deletions zero/lstate/state1/state1.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,31 @@ type State1 struct {

func NewState1(bc lstate.BlockChain) (ret State1) {
ret.bc = bc
if db, err := leveldb.OpenFile(zconfig.State1_db_dir(), nil); err != nil {
panic(err)
return
}

func (self *State1) MakesureEnv() {
var need_open_db bool
if !zconfig.IsDirExists(zconfig.State1_dir()) {
zconfig.Init_State1()
need_open_db = true
} else {
ret.db = SeroDB{db}
if !zconfig.IsDirExists(zconfig.State1_db_dir()) {
zconfig.Init_State1()
need_open_db = true
} else {
if self.db.db == nil {
need_open_db = true
}
}
}
if need_open_db {
if db, err := leveldb.OpenFile(zconfig.State1_db_dir(), nil); err != nil {
panic(err)
} else {
self.db.db = db
}
}
return
}

func (self *State1) valid() bool {
Expand Down
15 changes: 15 additions & 0 deletions zero/zconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package zconfig

import "io/ioutil"

var is_dev = false

func Init_Dev(dev bool) {
Expand All @@ -40,3 +42,16 @@ var VP0 = uint64(788888)
var MAX_O_INS_LENGTH = 2500

var MAX_TX_OUT_COUNT_LENGTH = 256

func IsDirExists(path string) bool {
files, err := ioutil.ReadDir(path)
if err != nil {
return false
} else {
if len(files) > 0 {
return true
} else {
return false
}
}
}
14 changes: 14 additions & 0 deletions zero/zconfig/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package zconfig

import (
"fmt"
"io/ioutil"
"testing"
)

func TestFile(t *testing.T) {

files, err := ioutil.ReadDir("/Users")
fmt.Print(files, err)

}

0 comments on commit f63f85b

Please sign in to comment.