|
|
@ -26,19 +26,27 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// ReadDatabaseVersion retrieves the version number of the database.
|
|
|
|
// ReadDatabaseVersion retrieves the version number of the database.
|
|
|
|
func ReadDatabaseVersion(db DatabaseReader) int { |
|
|
|
func ReadDatabaseVersion(db DatabaseReader) *uint64 { |
|
|
|
var version int |
|
|
|
var version uint64 |
|
|
|
|
|
|
|
|
|
|
|
enc, _ := db.Get(databaseVerisionKey) |
|
|
|
enc, _ := db.Get(databaseVerisionKey) |
|
|
|
rlp.DecodeBytes(enc, &version) |
|
|
|
if len(enc) == 0 { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := rlp.DecodeBytes(enc, &version); err != nil { |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return version |
|
|
|
return &version |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WriteDatabaseVersion stores the version number of the database
|
|
|
|
// WriteDatabaseVersion stores the version number of the database
|
|
|
|
func WriteDatabaseVersion(db DatabaseWriter, version int) { |
|
|
|
func WriteDatabaseVersion(db DatabaseWriter, version uint64) { |
|
|
|
enc, _ := rlp.EncodeToBytes(version) |
|
|
|
enc, err := rlp.EncodeToBytes(version) |
|
|
|
if err := db.Put(databaseVerisionKey, enc); err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Crit("Failed to encode database version", "err", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err = db.Put(databaseVerisionKey, enc); err != nil { |
|
|
|
log.Crit("Failed to store the database version", "err", err) |
|
|
|
log.Crit("Failed to store the database version", "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|