Skip to content

Commit

Permalink
Fixed linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
esuwu committed Dec 27, 2023
1 parent 478498e commit 84b690d
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions cmd/snapshotsreader/snapshots_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,49 @@ import (
"errors"
"flag"
"fmt"
"github.com/wavesplatform/gowaves/pkg/logging"
"github.com/wavesplatform/gowaves/pkg/settings"
"log"
"os"

"github.com/wavesplatform/gowaves/pkg/logging"
"github.com/wavesplatform/gowaves/pkg/proto"
"github.com/wavesplatform/gowaves/pkg/settings"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

const (
snapshotsByteSize = 4
)

func parseSnapshots(nBlocks int, snapshotsBody *os.File, scheme proto.Scheme) []proto.BlockSnapshot {
snapshotsSizeBytes := make([]byte, snapshotsByteSize)
readPos := int64(0)
var blocksSnapshots []proto.BlockSnapshot
for height := uint64(1); height <= uint64(nBlocks); height++ {
if _, readBerr := snapshotsBody.ReadAt(snapshotsSizeBytes, readPos); readBerr != nil {
zap.S().Fatalf("failed to read the snapshots size in block %v", readBerr)
}
snapshotsSize := binary.BigEndian.Uint32(snapshotsSizeBytes)
if snapshotsSize == 0 {
readPos += snapshotsByteSize
continue
}
if snapshotsSize != 0 {
snapshotsInBlock := proto.BlockSnapshot{}
snapshots := make([]byte, snapshotsSize+snapshotsByteSize) // []{snapshot, size} + 4 bytes = size of all snapshots
if _, readRrr := snapshotsBody.ReadAt(snapshots, readPos); readRrr != nil {
zap.S().Fatalf("failed to read the snapshots in block %v", readRrr)
}
unmrshlErr := snapshotsInBlock.UnmarshalBinaryImport(snapshots, scheme)
if unmrshlErr != nil {
zap.S().Fatalf("failed to unmarshal snapshots in block %v", unmrshlErr)
}
blocksSnapshots = append(blocksSnapshots, snapshotsInBlock)
readPos += int64(snapshotsSize) + snapshotsByteSize
}
}
return blocksSnapshots
}

func main() {
const (
defaultBlocksNumber = 1000
Expand Down Expand Up @@ -49,32 +82,7 @@ func main() {
if err != nil {
zap.S().Fatalf("failed to open snapshots file, %v", err)
}
blocksSnapshots := parseSnapshots(*nBlocks, snapshotsBody, ss.AddressSchemeCharacter)

snapshotsSizeBytes := make([]byte, 4)
readPos := int64(0)
var blocksSnapshots []proto.BlockSnapshot
for height := uint64(1); height <= uint64(*nBlocks); height++ {
if _, err := snapshotsBody.ReadAt(snapshotsSizeBytes, readPos); err != nil {
log.Fatal(err)
}
snapshotsSize := binary.BigEndian.Uint32(snapshotsSizeBytes)
if snapshotsSize == 0 {
readPos += 4
continue
}
if snapshotsSize != 0 {
fmt.Println()
snapshotsInBlock := proto.BlockSnapshot{}
snapshots := make([]byte, snapshotsSize+4) // []{snapshot, size} + 4 bytes = size of all snapshots
if _, err := snapshotsBody.ReadAt(snapshots, readPos); err != nil {
log.Fatal(err)
}
err := snapshotsInBlock.UnmarshalBinaryImport(snapshots, ss.AddressSchemeCharacter)
if err != nil {
return
}
blocksSnapshots = append(blocksSnapshots, snapshotsInBlock)
readPos += int64(snapshotsSize) + 4
}
}
zap.S().Info(blocksSnapshots[0])
}

0 comments on commit 84b690d

Please sign in to comment.