code.vegaprotocol.io/vega@v0.79.0/cmd/vega/commands/nodewallet/show.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package nodewallet
    17  
    18  import (
    19  	"code.vegaprotocol.io/vega/core/config"
    20  	"code.vegaprotocol.io/vega/core/nodewallets"
    21  	"code.vegaprotocol.io/vega/core/nodewallets/registry"
    22  	vgjson "code.vegaprotocol.io/vega/libs/json"
    23  	"code.vegaprotocol.io/vega/logging"
    24  	"code.vegaprotocol.io/vega/paths"
    25  
    26  	"github.com/jessevdk/go-flags"
    27  )
    28  
    29  type showCmd struct {
    30  	Config nodewallets.Config
    31  }
    32  
    33  func (opts *showCmd) Execute(_ []string) error {
    34  	log := logging.NewLoggerFromConfig(logging.NewDefaultConfig())
    35  	defer log.AtExit()
    36  
    37  	registryPass, err := rootCmd.PassphraseFile.Get("node wallet", false)
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	vegaPaths := paths.New(rootCmd.VegaHome)
    43  
    44  	_, conf, err := config.EnsureNodeConfig(vegaPaths)
    45  	if err != nil {
    46  		return err
    47  	}
    48  
    49  	opts.Config = conf.NodeWallet
    50  
    51  	if _, err := flags.NewParser(opts, flags.Default|flags.IgnoreUnknown).Parse(); err != nil {
    52  		return err
    53  	}
    54  
    55  	registryLoader, err := registry.NewLoader(vegaPaths, registryPass)
    56  	if err != nil {
    57  		return err
    58  	}
    59  
    60  	registry, err := registryLoader.Get(registryPass)
    61  	if err != nil {
    62  		return err
    63  	}
    64  
    65  	if err = vgjson.PrettyPrint(registry); err != nil {
    66  		return err
    67  	}
    68  	return nil
    69  }