Files
dejo-node/internal/storage/snapshot.go
2025-05-23 10:44:32 -03:00

24 lines
554 B
Go

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)
}