@@ -5,16 +5,49 @@ import (
5
5
"errors"
6
6
"flag"
7
7
"fmt"
8
- "github.com/wavesplatform/gowaves/pkg/logging"
9
- "github.com/wavesplatform/gowaves/pkg/settings"
10
- "log"
11
8
"os"
12
9
10
+ "github.com/wavesplatform/gowaves/pkg/logging"
13
11
"github.com/wavesplatform/gowaves/pkg/proto"
12
+ "github.com/wavesplatform/gowaves/pkg/settings"
14
13
"go.uber.org/zap"
15
14
"go.uber.org/zap/zapcore"
16
15
)
17
16
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
+
18
51
func main () {
19
52
const (
20
53
defaultBlocksNumber = 1000
@@ -49,32 +82,7 @@ func main() {
49
82
if err != nil {
50
83
zap .S ().Fatalf ("failed to open snapshots file, %v" , err )
51
84
}
85
+ blocksSnapshots := parseSnapshots (* nBlocks , snapshotsBody , ss .AddressSchemeCharacter )
52
86
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 ])
80
88
}
0 commit comments