commit inicial do projeto
This commit is contained in:
24
internal/storage/snapshot.go
Normal file
24
internal/storage/snapshot.go
Normal file
@ -0,0 +1,24 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const snapshotFile = "state_snapshot.txt"
|
||||
|
||||
func (bs *BlockStore) SetSnapshotHeight(index uint64) error {
|
||||
file := filepath.Join(bs.Path, snapshotFile)
|
||||
return os.WriteFile(file, []byte(strconv.FormatUint(index, 10)), 0644)
|
||||
}
|
||||
|
||||
func (bs *BlockStore) GetSnapshotHeight() (uint64, error) {
|
||||
file := filepath.Join(bs.Path, snapshotFile)
|
||||
data, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return 0, errors.New("nenhum snapshot salvo")
|
||||
}
|
||||
return strconv.ParseUint(string(data), 10, 64)
|
||||
}
|
||||
Reference in New Issue
Block a user