github.com/core-coin/go-core/v2@v2.1.9/cmd/checkpoint-admin/status.go (about)

     1  // Copyright 2019 by the Authors
     2  // This file is part of go-core.
     3  //
     4  // go-core 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-core 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-core. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"gopkg.in/urfave/cli.v1"
    23  
    24  	"github.com/core-coin/go-core/v2/cmd/utils"
    25  	"github.com/core-coin/go-core/v2/common"
    26  )
    27  
    28  var commandStatus = cli.Command{
    29  	Name:  "status",
    30  	Usage: "Fetches the signers and checkpoint status of the oracle contract",
    31  	Flags: []cli.Flag{
    32  		nodeURLFlag,
    33  	},
    34  	Action: utils.MigrateFlags(status),
    35  }
    36  
    37  // status fetches the admin list of specified registrar contract.
    38  func status(ctx *cli.Context) error {
    39  	// Create a wrapper around the checkpoint oracle contract
    40  	addr, oracle := newContract(newRPCClient(ctx.GlobalString(nodeURLFlag.Name)))
    41  	fmt.Printf("Oracle => %s\n", addr.Hex())
    42  	fmt.Println()
    43  
    44  	// Retrieve the list of authorized signers (admins)
    45  	admins, err := oracle.Contract().GetAllAdmin(nil)
    46  	if err != nil {
    47  		return err
    48  	}
    49  	for i, admin := range admins {
    50  		fmt.Printf("Admin %d => %s\n", i+1, admin.Hex())
    51  	}
    52  	fmt.Println()
    53  
    54  	// Retrieve the latest checkpoint
    55  	index, checkpoint, height, err := oracle.Contract().GetLatestCheckpoint(nil)
    56  	if err != nil {
    57  		return err
    58  	}
    59  	fmt.Printf("Checkpoint (published at #%d) %d => %s\n", height, index, common.Hash(checkpoint).Hex())
    60  
    61  	return nil
    62  }