commit inicial do projeto

This commit is contained in:
Júnior
2025-05-23 10:44:32 -03:00
commit 8f04473c0b
106 changed files with 5673 additions and 0 deletions

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