mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-12-25 08:05:17 +00:00
178 lines
5.6 KiB
Go
178 lines
5.6 KiB
Go
package main
|
||
|
||
import (
|
||
"encoding/hex"
|
||
"flag"
|
||
"fmt"
|
||
"io/fs"
|
||
"os"
|
||
"os/signal"
|
||
"path/filepath"
|
||
"syscall"
|
||
|
||
"github.com/libp2p/go-libp2p/core/crypto"
|
||
"github.com/libp2p/go-libp2p/core/peer"
|
||
"github.com/pkg/errors"
|
||
"source.quilibrium.com/quilibrium/monorepo/node/app"
|
||
"source.quilibrium.com/quilibrium/monorepo/node/config"
|
||
qcrypto "source.quilibrium.com/quilibrium/monorepo/node/crypto"
|
||
)
|
||
|
||
var (
|
||
configDirectory = flag.String(
|
||
"config",
|
||
"./.config/",
|
||
"the configuration directory",
|
||
)
|
||
importPrivKey = flag.String(
|
||
"import-priv-key",
|
||
"",
|
||
"creates a new config using a specific key from the phase one ceremony",
|
||
)
|
||
dbConsole = flag.Bool(
|
||
"db-console",
|
||
false,
|
||
"starts the node in database console mode",
|
||
)
|
||
)
|
||
|
||
func main() {
|
||
flag.Parse()
|
||
|
||
if *importPrivKey != "" {
|
||
config, err := config.LoadConfig(*configDirectory, *importPrivKey)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
printPeerID(config.P2P)
|
||
fmt.Println("Import completed, you are ready for the launch.")
|
||
return
|
||
}
|
||
done := make(chan os.Signal, 1)
|
||
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
|
||
|
||
printLogo()
|
||
printVersion()
|
||
fmt.Println(" ")
|
||
|
||
nodeConfig, err := config.LoadConfig(*configDirectory, "")
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
clearIfTestData(*configDirectory, nodeConfig)
|
||
|
||
if *dbConsole {
|
||
console, err := app.NewDBConsole(nodeConfig)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
console.Run()
|
||
return
|
||
}
|
||
|
||
fmt.Println("Loading ceremony state and starting node...")
|
||
qcrypto.Init()
|
||
|
||
node, err := app.NewNode(nodeConfig)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
node.Start()
|
||
|
||
<-done
|
||
node.Stop()
|
||
}
|
||
|
||
func clearIfTestData(configDir string, nodeConfig *config.Config) {
|
||
_, err := os.Stat(filepath.Join(configDir, "RELEASE_VERSION"))
|
||
if os.IsNotExist(err) {
|
||
fmt.Println("Clearing test data...")
|
||
err := os.RemoveAll(nodeConfig.DB.Path)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
versionFile, err := os.OpenFile(
|
||
filepath.Join(configDir, "RELEASE_VERSION"),
|
||
os.O_CREATE|os.O_RDWR,
|
||
fs.FileMode(0700),
|
||
)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
_, err = versionFile.Write([]byte{0x01, 0x00, 0x00})
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
|
||
err = versionFile.Close()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
}
|
||
}
|
||
|
||
func printPeerID(p2pConfig *config.P2PConfig) {
|
||
peerPrivKey, err := hex.DecodeString(p2pConfig.PeerPrivKey)
|
||
if err != nil {
|
||
panic(errors.Wrap(err, "error unmarshaling peerkey"))
|
||
}
|
||
|
||
privKey, err := crypto.UnmarshalEd448PrivateKey(peerPrivKey)
|
||
if err != nil {
|
||
panic(errors.Wrap(err, "error unmarshaling peerkey"))
|
||
}
|
||
|
||
pub := privKey.GetPublic()
|
||
id, err := peer.IDFromPublicKey(pub)
|
||
if err != nil {
|
||
panic(errors.Wrap(err, "error getting peer id"))
|
||
}
|
||
|
||
fmt.Println("Peer ID: " + id.String())
|
||
}
|
||
|
||
func printLogo() {
|
||
fmt.Println(" %#########")
|
||
fmt.Println(" #############################")
|
||
fmt.Println(" ########################################&")
|
||
fmt.Println(" ###############################################")
|
||
fmt.Println(" &#####################% %######################")
|
||
fmt.Println(" ################# #################")
|
||
fmt.Println(" ############### ###############")
|
||
fmt.Println(" ############# ##############")
|
||
fmt.Println(" ############# ############&")
|
||
fmt.Println(" ############ ############")
|
||
fmt.Println(" ########### ########## &###########")
|
||
fmt.Println(" ########### ############## ###########")
|
||
fmt.Println(" ########### ############## ##########&")
|
||
fmt.Println(" ########## ############## ##########")
|
||
fmt.Println("%########## ########## ##########")
|
||
fmt.Println("##########& ##########")
|
||
fmt.Println("########## &#########")
|
||
fmt.Println("##########& ####### ####### ##########")
|
||
fmt.Println(" ########## &######################### ##########")
|
||
fmt.Println(" ########## ##############% ############## &##########")
|
||
fmt.Println(" %########## &############## ############### ##########")
|
||
fmt.Println(" ########### ############### ##############% ###########")
|
||
fmt.Println(" ###########& ########## ############### ########")
|
||
fmt.Println(" ############ ##### ##############% ####")
|
||
fmt.Println(" ############ ###############")
|
||
fmt.Println(" ############## ##############%")
|
||
fmt.Println(" ############### ###############")
|
||
fmt.Println(" #################& ##############%")
|
||
fmt.Println(" #########################&&&############# ###############")
|
||
fmt.Println(" ########################################% ############")
|
||
fmt.Println(" ####################################### ########")
|
||
fmt.Println(" ############################# ##")
|
||
}
|
||
|
||
func printVersion() {
|
||
fmt.Println(" ")
|
||
fmt.Println(" Quilibrium Node - v1.0.0 – Dawn")
|
||
}
|