Skip to content

Commit a242012

Browse files
committed
feat: add sha256 checksum generation
1 parent c12755b commit a242012

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

rollup/missing_header_fields/export-headers-toolkit/cmd/dedup.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"bufio"
5+
"crypto/sha256"
56
"encoding/binary"
67
"fmt"
78
"io"
@@ -41,9 +42,25 @@ The binary layout of the deduplicated file is as follows:
4142

4243
seenDifficulty, seenVanity, seenSealLen := runAnalysis(inputFile)
4344
runDedup(inputFile, outputFile, seenDifficulty, seenVanity, seenSealLen)
45+
runSHA256(outputFile)
4446
},
4547
}
4648

49+
func runSHA256(outputFile string) {
50+
f, err := os.Open(outputFile)
51+
defer f.Close()
52+
if err != nil {
53+
log.Fatalf("Error opening file: %v", err)
54+
}
55+
56+
h := sha256.New()
57+
if _, err = io.Copy(h, f); err != nil {
58+
log.Fatalf("Error hashing file: %v", err)
59+
}
60+
61+
fmt.Printf("Deduplicated headers written to %s with sha256 checksum: %x\n", outputFile, h.Sum(nil))
62+
}
63+
4764
func init() {
4865
rootCmd.AddCommand(dedupCmd)
4966

@@ -93,15 +110,13 @@ func runDedup(inputFile, outputFile string, seenDifficulty map[uint64]int, seenV
93110
defer reader.close()
94111

95112
writer := newMissingHeaderFileWriter(outputFile, seenVanity)
96-
writer.close()
113+
defer writer.close()
97114

98115
writer.missingHeaderWriter.writeVanities()
99116

100117
reader.read(func(header *types.Header) {
101118
writer.missingHeaderWriter.write(header)
102119
})
103-
104-
fmt.Printf("Deduplicated headers written to %s\n", outputFile)
105120
}
106121

107122
type headerReader struct {

rollup/missing_header_fields/export-headers-toolkit/cmd/fetch.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"sync"
1212
"time"
1313

14-
"github.com/scroll-tech/go-ethereum/ethclient"
1514
"github.com/spf13/cobra"
1615

16+
"github.com/scroll-tech/go-ethereum/ethclient"
17+
1718
"github.com/scroll-tech/go-ethereum/export-headers-toolkit/types"
1819
)
1920

0 commit comments

Comments
 (0)