mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-01 00:31:21 +00:00
0be3044b7e
* rename * rename "make grpc" * rename "abi bindings templates" * rename "abi bindings templates"
47 lines
1.0 KiB
Go
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])
|
|
},
|
|
}
|