erigon-pulse/cmd/snapshots/generator/commands/metainfo_hash.go
Alex Sharov 0be3044b7e
rename (#1978)
* rename

* rename "make grpc"

* rename "abi bindings templates"

* rename "abi bindings templates"
2021-05-20 19:25:53 +01:00

47 lines
1.0 KiB
Go

package commands
import (
"errors"
"fmt"
"time"
"github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/metainfo"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(snapshotMetainfoCmd)
}
func PrintMetaInfoHash(path string) error {
t := time.Now()
mi := metainfo.MetaInfo{}
info, err := snapshotsync.BuildInfoBytesForSnapshot(path, snapshotsync.MdbxFilename)
if err != nil {
return err
}
mi.InfoBytes, err = bencode.Marshal(info)
if err != nil {
return err
}
fmt.Println("infohash:", mi.HashInfoBytes().String())
fmt.Println("infobytes:", common.Bytes2Hex(mi.InfoBytes))
fmt.Println("It took", time.Since(t))
return nil
}
var snapshotMetainfoCmd = &cobra.Command{
Use: "snapshotMetainfo",
Short: "Calculate snapshot metainfo",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("empty path")
}
return PrintMetaInfoHash(args[0])
},
}