github.com/k1rill-fedoseev/go-ethereum@v1.9.7/cmd/checkpoint-admin/main.go (about)

     1  // Copyright 2019 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // checkpoint-admin is a utility that can be used to query checkpoint information
    18  // and register stable checkpoints into an oracle contract.
    19  package main
    20  
    21  import (
    22  	"fmt"
    23  	"os"
    24  
    25  	"github.com/ethereum/go-ethereum/cmd/utils"
    26  	"github.com/ethereum/go-ethereum/common/fdlimit"
    27  	"github.com/ethereum/go-ethereum/log"
    28  	"gopkg.in/urfave/cli.v1"
    29  )
    30  
    31  const (
    32  	commandHelperTemplate = `{{.Name}}{{if .Subcommands}} command{{end}}{{if .Flags}} [command options]{{end}} [arguments...]
    33  {{if .Description}}{{.Description}}
    34  {{end}}{{if .Subcommands}}
    35  SUBCOMMANDS:
    36  	{{range .Subcommands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
    37  	{{end}}{{end}}{{if .Flags}}
    38  OPTIONS:
    39  {{range $.Flags}}{{"\t"}}{{.}}
    40  {{end}}
    41  {{end}}`
    42  )
    43  
    44  var (
    45  	// Git SHA1 commit hash of the release (set via linker flags)
    46  	gitCommit = ""
    47  	gitDate   = ""
    48  )
    49  
    50  var app *cli.App
    51  
    52  func init() {
    53  	app = utils.NewApp(gitCommit, gitDate, "ethereum checkpoint helper tool")
    54  	app.Commands = []cli.Command{
    55  		commandStatus,
    56  		commandDeploy,
    57  		commandSign,
    58  		commandPublish,
    59  	}
    60  	app.Flags = []cli.Flag{
    61  		oracleFlag,
    62  		nodeURLFlag,
    63  	}
    64  	cli.CommandHelpTemplate = commandHelperTemplate
    65  }
    66  
    67  // Commonly used command line flags.
    68  var (
    69  	indexFlag = cli.Int64Flag{
    70  		Name:  "index",
    71  		Usage: "Checkpoint index (query latest from remote node if not specified)",
    72  	}
    73  	hashFlag = cli.StringFlag{
    74  		Name:  "hash",
    75  		Usage: "Checkpoint hash (query latest from remote node if not specified)",
    76  	}
    77  	oracleFlag = cli.StringFlag{
    78  		Name:  "oracle",
    79  		Usage: "Checkpoint oracle address (query from remote node if not specified)",
    80  	}
    81  	thresholdFlag = cli.Int64Flag{
    82  		Name:  "threshold",
    83  		Usage: "Minimal number of signatures required to approve a checkpoint",
    84  	}
    85  	nodeURLFlag = cli.StringFlag{
    86  		Name:  "rpc",
    87  		Value: "http://localhost:8545",
    88  		Usage: "The rpc endpoint of a local or remote geth node",
    89  	}
    90  	clefURLFlag = cli.StringFlag{
    91  		Name:  "clef",
    92  		Value: "http://localhost:8550",
    93  		Usage: "The rpc endpoint of clef",
    94  	}
    95  	signerFlag = cli.StringFlag{
    96  		Name:  "signer",
    97  		Usage: "Signer address for clef signing",
    98  	}
    99  	signersFlag = cli.StringFlag{
   100  		Name:  "signers",
   101  		Usage: "Comma separated accounts of trusted checkpoint signers",
   102  	}
   103  	signaturesFlag = cli.StringFlag{
   104  		Name:  "signatures",
   105  		Usage: "Comma separated checkpoint signatures to submit",
   106  	}
   107  )
   108  
   109  func main() {
   110  	log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stderr, log.TerminalFormat(true))))
   111  	fdlimit.Raise(2048)
   112  
   113  	if err := app.Run(os.Args); err != nil {
   114  		fmt.Fprintln(os.Stderr, err)
   115  		os.Exit(1)
   116  	}
   117  }