Skip to content

Commit 84b690d

Browse files
committed
Fixed linter issues
1 parent 478498e commit 84b690d

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

cmd/snapshotsreader/snapshots_reader.go

+38-30
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,49 @@ import (
55
"errors"
66
"flag"
77
"fmt"
8-
"github.com/wavesplatform/gowaves/pkg/logging"
9-
"github.com/wavesplatform/gowaves/pkg/settings"
10-
"log"
118
"os"
129

10+
"github.com/wavesplatform/gowaves/pkg/logging"
1311
"github.com/wavesplatform/gowaves/pkg/proto"
12+
"github.com/wavesplatform/gowaves/pkg/settings"
1413
"go.uber.org/zap"
1514
"go.uber.org/zap/zapcore"
1615
)
1716

17+
const (
18+
snapshotsByteSize = 4
19+
)
20+
21+
func parseSnapshots(nBlocks int, snapshotsBody *os.File, scheme proto.Scheme) []proto.BlockSnapshot {
22+
snapshotsSizeBytes := make([]byte, snapshotsByteSize)
23+
readPos := int64(0)
24+
var blocksSnapshots []proto.BlockSnapshot
25+
for height := uint64(1); height <= uint64(nBlocks); height++ {
26+
if _, readBerr := snapshotsBody.ReadAt(snapshotsSizeBytes, readPos); readBerr != nil {
27+
zap.S().Fatalf("failed to read the snapshots size in block %v", readBerr)
28+
}
29+
snapshotsSize := binary.BigEndian.Uint32(snapshotsSizeBytes)
30+
if snapshotsSize == 0 {
31+
readPos += snapshotsByteSize
32+
continue
33+
}
34+
if snapshotsSize != 0 {
35+
snapshotsInBlock := proto.BlockSnapshot{}
36+
snapshots := make([]byte, snapshotsSize+snapshotsByteSize) // []{snapshot, size} + 4 bytes = size of all snapshots
37+
if _, readRrr := snapshotsBody.ReadAt(snapshots, readPos); readRrr != nil {
38+
zap.S().Fatalf("failed to read the snapshots in block %v", readRrr)
39+
}
40+
unmrshlErr := snapshotsInBlock.UnmarshalBinaryImport(snapshots, scheme)
41+
if unmrshlErr != nil {
42+
zap.S().Fatalf("failed to unmarshal snapshots in block %v", unmrshlErr)
43+
}
44+
blocksSnapshots = append(blocksSnapshots, snapshotsInBlock)
45+
readPos += int64(snapshotsSize) + snapshotsByteSize
46+
}
47+
}
48+
return blocksSnapshots
49+
}
50+
1851
func main() {
1952
const (
2053
defaultBlocksNumber = 1000
@@ -49,32 +82,7 @@ func main() {
4982
if err != nil {
5083
zap.S().Fatalf("failed to open snapshots file, %v", err)
5184
}
85+
blocksSnapshots := parseSnapshots(*nBlocks, snapshotsBody, ss.AddressSchemeCharacter)
5286

53-
snapshotsSizeBytes := make([]byte, 4)
54-
readPos := int64(0)
55-
var blocksSnapshots []proto.BlockSnapshot
56-
for height := uint64(1); height <= uint64(*nBlocks); height++ {
57-
if _, err := snapshotsBody.ReadAt(snapshotsSizeBytes, readPos); err != nil {
58-
log.Fatal(err)
59-
}
60-
snapshotsSize := binary.BigEndian.Uint32(snapshotsSizeBytes)
61-
if snapshotsSize == 0 {
62-
readPos += 4
63-
continue
64-
}
65-
if snapshotsSize != 0 {
66-
fmt.Println()
67-
snapshotsInBlock := proto.BlockSnapshot{}
68-
snapshots := make([]byte, snapshotsSize+4) // []{snapshot, size} + 4 bytes = size of all snapshots
69-
if _, err := snapshotsBody.ReadAt(snapshots, readPos); err != nil {
70-
log.Fatal(err)
71-
}
72-
err := snapshotsInBlock.UnmarshalBinaryImport(snapshots, ss.AddressSchemeCharacter)
73-
if err != nil {
74-
return
75-
}
76-
blocksSnapshots = append(blocksSnapshots, snapshotsInBlock)
77-
readPos += int64(snapshotsSize) + 4
78-
}
79-
}
87+
zap.S().Info(blocksSnapshots[0])
8088
}

0 commit comments

Comments
 (0)