Skip to content

Commit

Permalink
feat: add sha256 checksum generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Jul 16, 2024
1 parent c12755b commit a242012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 18 additions & 3 deletions rollup/missing_header_fields/export-headers-toolkit/cmd/dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bufio"
"crypto/sha256"
"encoding/binary"
"fmt"
"io"
Expand Down Expand Up @@ -41,9 +42,25 @@ The binary layout of the deduplicated file is as follows:

seenDifficulty, seenVanity, seenSealLen := runAnalysis(inputFile)
runDedup(inputFile, outputFile, seenDifficulty, seenVanity, seenSealLen)
runSHA256(outputFile)
},
}

func runSHA256(outputFile string) {
f, err := os.Open(outputFile)
defer f.Close()
if err != nil {
log.Fatalf("Error opening file: %v", err)
}

h := sha256.New()
if _, err = io.Copy(h, f); err != nil {
log.Fatalf("Error hashing file: %v", err)
}

fmt.Printf("Deduplicated headers written to %s with sha256 checksum: %x\n", outputFile, h.Sum(nil))
}

func init() {
rootCmd.AddCommand(dedupCmd)

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

writer := newMissingHeaderFileWriter(outputFile, seenVanity)
writer.close()
defer writer.close()

writer.missingHeaderWriter.writeVanities()

reader.read(func(header *types.Header) {
writer.missingHeaderWriter.write(header)
})

fmt.Printf("Deduplicated headers written to %s\n", outputFile)
}

type headerReader struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"sync"
"time"

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

"github.com/scroll-tech/go-ethereum/ethclient"

"github.com/scroll-tech/go-ethereum/export-headers-toolkit/types"
)

Expand Down

0 comments on commit a242012

Please sign in to comment.