code.vegaprotocol.io/vega@v0.79.0/cmd/vega/commands/nodewallet/reload.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 "context" 20 "fmt" 21 "time" 22 23 "code.vegaprotocol.io/vega/core/admin" 24 "code.vegaprotocol.io/vega/core/config" 25 vgjson "code.vegaprotocol.io/vega/libs/json" 26 "code.vegaprotocol.io/vega/paths" 27 28 "github.com/jessevdk/go-flags" 29 ) 30 31 type reloadCmd struct { 32 config.OutputFlag 33 34 Config admin.Config 35 36 Chain string `choice:"vega" choice:"ethereum" description:"The chain to be imported" long:"chain" required:"true" short:"c"` 37 } 38 39 func (opts *reloadCmd) Execute(_ []string) error { 40 output, err := opts.GetOutput() 41 if err != nil { 42 return err 43 } 44 45 vegaPaths := paths.New(rootCmd.VegaHome) 46 47 _, conf, err := config.EnsureNodeConfig(vegaPaths) 48 if err != nil { 49 return err 50 } 51 52 opts.Config = conf.Admin 53 54 if _, err := flags.NewParser(opts, flags.Default|flags.IgnoreUnknown).Parse(); err != nil { 55 return err 56 } 57 58 sc := admin.NewClient(opts.Config) 59 60 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) 61 defer cancel() 62 63 var resp *admin.NodeWalletReloadReply 64 switch opts.Chain { 65 case vegaChain, ethereumChain: 66 resp, err = sc.NodeWalletReload(ctx, opts.Chain) 67 if err != nil { 68 return fmt.Errorf("failed to reload node wallet: %w", err) 69 } 70 default: 71 return fmt.Errorf("chain %q is not supported", opts.Chain) 72 } 73 if output.IsHuman() { 74 fmt.Println(green("reload successful:")) 75 76 vgjson.PrettyPrint(resp) 77 } else if output.IsJSON() { 78 if err := vgjson.Print(resp); err != nil { 79 return err 80 } 81 } 82 83 return nil 84 }