prysm-pulse/tools/interop/export-genesis/main.go
Raul Jordan 302b0f8c80
Use FastSSZ Everywhere Applicable (#6135)
* use fast ssz anywhere applicable
* use fastssz clearly
* Merge branch 'master' into use-fastssz
* Apply suggestions from code review
* imports
* Update beacon-chain/p2p/fork.go
* Merge branch 'master' into use-fastssz
* update go-ssz
* update go-ssz
* Merge refs/heads/master into use-fastssz
* Merge refs/heads/master into use-fastssz
2020-06-05 13:48:40 +00:00

49 lines
1.0 KiB
Go

package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
)
// A basic tool to extract genesis.ssz from existing beaconchain.db.
// ex:
// bazel run //tools/interop/export-genesis:export-genesis -- /tmp/data/beaconchaindata /tmp/genesis.ssz
func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: ./main /path/to/datadir /path/to/output/genesis.ssz")
os.Exit(1)
}
fmt.Printf("Reading db at %s and writing ssz output to %s.\n", os.Args[1], os.Args[2])
d, err := db.NewDB(os.Args[1], cache.NewStateSummaryCache())
if err != nil {
panic(err)
}
defer func() {
if err := d.Close(); err != nil {
panic(err)
}
}()
gs, err := d.GenesisState(context.Background())
if err != nil {
panic(err)
}
if gs == nil {
panic("nil genesis state")
}
b, err := gs.InnerStateUnsafe().MarshalSSZ()
if err != nil {
panic(err)
}
if err := ioutil.WriteFile(os.Args[2], b, 0644); err != nil {
panic(err)
}
fmt.Println("done")
}