From 36abd131cb15579f24e7794fb70edf6f719ba02a Mon Sep 17 00:00:00 2001 From: "Mohd. Shahnawaz Ali Choudhary" <57221398+m-s-a-c@users.noreply.github.com> Date: Wed, 1 Sep 2021 22:47:08 +0530 Subject: [PATCH 1/2] Delete dependabot.yml dependabot s not working on other repo due directory path issue. dependabot need go.mod & go.sum files in order to fetch the the current versions. gosdk dependent repos like 0proxy, 0dns etc. do not have go.mod & go.sum in their root directory. When we are passing the full path for this, it is not able to recognise it. Therefore reverted these changes back. --- .github/dependabot.yml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index eb4bfe6e..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,11 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: "gomod" # See documentation for possible values - directory: "/" # Location of package manifests - schedule: - interval: "daily" From dfba10df469771ec3e17d2b2a4f149903efd31c5 Mon Sep 17 00:00:00 2001 From: Piers Shepperson Date: Tue, 7 Sep 2021 16:52:34 +0100 Subject: [PATCH 2/2] New smart contract update-config and config command (#42) --- cmd/common.go | 47 ++++++++++++ cmd/fc-config.go | 34 +++++++++ cmd/fc-update-config.go | 62 +++++++++++++++ cmd/global-config.go | 34 +++++++++ cmd/ip-config.go | 34 +++++++++ cmd/ip-update-config.go | 62 +++++++++++++++ cmd/minersc.go | 156 +++++++++++++++++++++++++++----------- cmd/mn-config.go | 34 +++++++++ cmd/mn-update-config.go | 62 +++++++++++++++ cmd/sc-config.go | 34 +++++++++ cmd/sc-update-config.go | 62 +++++++++++++++ cmd/vesting.go | 28 ------- cmd/vp-config.go | 34 +++++++++ cmd/vp-update-settings.go | 62 ++++----------- go.mod | 4 +- go.sum | 13 ++-- 16 files changed, 634 insertions(+), 128 deletions(-) create mode 100644 cmd/fc-config.go create mode 100644 cmd/fc-update-config.go create mode 100644 cmd/global-config.go create mode 100644 cmd/ip-config.go create mode 100644 cmd/ip-update-config.go create mode 100644 cmd/mn-config.go create mode 100644 cmd/mn-update-config.go create mode 100644 cmd/sc-config.go create mode 100644 cmd/sc-update-config.go create mode 100644 cmd/vp-config.go diff --git a/cmd/common.go b/cmd/common.go index 9c2a9b20..587b8b82 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -2,9 +2,14 @@ package cmd import ( "fmt" + "log" "os" + "sort" + "strings" "sync" + "github.com/spf13/pflag" + "github.com/0chain/gosdk/zcncore" "gopkg.in/cheggaaa/pb.v1" ) @@ -123,3 +128,45 @@ func ExitWithError(v ...interface{}) { fmt.Fprintln(os.Stderr, v...) os.Exit(1) } + +func setupInputMap(flags *pflag.FlagSet) map[string]string { + var err error + var keys []string + if flags.Changed("keys") { + keys, err = flags.GetStringSlice("keys") + if err != nil { + log.Fatal(err) + } + } + + var values []string + if flags.Changed("values") { + values, err = flags.GetStringSlice("values") + if err != nil { + log.Fatal(err) + } + } + + input := make(map[string]string) + if len(keys) != len(values) { + log.Fatal("number keys must equal the number values") + } + for i := 0; i < len(keys); i++ { + v := strings.TrimSpace(values[i]) + k := strings.TrimSpace(keys[i]) + input[k] = v + } + return input +} + +func printMap(outMap map[string]string) { + keys := make([]string, 0, len(outMap)) + for k := range outMap { + keys = append(keys, k) + } + sort.Strings(keys) + + for _, k := range keys { + fmt.Println(k, "\t", outMap[k]) + } +} diff --git a/cmd/fc-config.go b/cmd/fc-config.go new file mode 100644 index 00000000..7d0d6c2e --- /dev/null +++ b/cmd/fc-config.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" + "log" +) + +var getFaucetConfigCmd = &cobra.Command{ + Use: "fc-config", + Short: "Show facuet configurations.", + Long: `Show facuet configurations.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + + var ( + fields = new(zcncore.InputMap) + cb = NewJSONInfoCB(fields) + err error + ) + if err = zcncore.GetFaucetSCConfig(cb); err != nil { + log.Fatal(err) + } + if err = cb.Waiting(); err != nil { + log.Fatal(err) + } + + printMap(fields.Fields) + }, +} + +func init() { + rootCmd.AddCommand(getFaucetConfigCmd) +} diff --git a/cmd/fc-update-config.go b/cmd/fc-update-config.go new file mode 100644 index 00000000..73814b81 --- /dev/null +++ b/cmd/fc-update-config.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + "log" + "sync" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" +) + +var updateFaucetCmd = &cobra.Command{ + Use: "fc-update-config", + Short: "Update the Faucet smart contract", + Long: `Update the Faucet smart contract.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var err error + + input := new(zcncore.InputMap) + input.Fields = setupInputMap(cmd.Flags()) + if err != nil { + log.Fatal(err) + } + + var wg sync.WaitGroup + statusBar := &ZCNStatus{wg: &wg} + txn, err := zcncore.NewTransaction(statusBar, 0) + if err != nil { + log.Fatal(err) + } + + wg.Add(1) + if err = txn.FaucetUpdateConfig(input); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + statusBar.success = false + wg.Add(1) + if err = txn.Verify(); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + fmt.Printf("faucet smart contract settings updated\nHash: %v\n", txn.GetTransactionHash()) + }, +} + +func init() { + rootCmd.AddCommand(updateFaucetCmd) + updateFaucetCmd.PersistentFlags().StringSlice("keys", nil, "list of keys") + updateFaucetCmd.PersistentFlags().StringSlice("values", nil, "list of new values") +} diff --git a/cmd/global-config.go b/cmd/global-config.go new file mode 100644 index 00000000..1c840a0c --- /dev/null +++ b/cmd/global-config.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "log" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" +) + +var mnGlobalsCmd = &cobra.Command{ + Use: "global-config", + Short: "Show global configurations.", + Long: `Show global configurations.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var ( + fields = new(zcncore.InputMap) + cb = NewJSONInfoCB(fields) + err error + ) + if err = zcncore.GetMinerSCGlobals(cb); err != nil { + log.Fatal(err) + } + if err = cb.Waiting(); err != nil { + log.Fatal(err) + } + + printMap(fields.Fields) + }, +} + +func init() { + rootCmd.AddCommand(mnGlobalsCmd) +} diff --git a/cmd/ip-config.go b/cmd/ip-config.go new file mode 100644 index 00000000..8ec78adf --- /dev/null +++ b/cmd/ip-config.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" + "log" +) + +var getInterestPoolConfigCmd = &cobra.Command{ + Use: "ip-config", + Short: "Show interest pool configurations.", + Long: `Show interest pool configurations.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + + var ( + fields = new(zcncore.InputMap) + cb = NewJSONInfoCB(fields) + err error + ) + if err = zcncore.GetInterestPoolSCConfig(cb); err != nil { + log.Fatal(err) + } + if err = cb.Waiting(); err != nil { + log.Fatal(err) + } + + printMap(fields.Fields) + }, +} + +func init() { + rootCmd.AddCommand(getInterestPoolConfigCmd) +} diff --git a/cmd/ip-update-config.go b/cmd/ip-update-config.go new file mode 100644 index 00000000..0532d131 --- /dev/null +++ b/cmd/ip-update-config.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + "log" + "sync" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" +) + +var updateInterestPoolConfigCmd = &cobra.Command{ + Use: "ip-update-config", + Short: "Update the interest pool configurations.", + Long: `Update the interest pool configurations.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var err error + + input := new(zcncore.InputMap) + input.Fields = setupInputMap(cmd.Flags()) + if err != nil { + log.Fatal(err) + } + + var wg sync.WaitGroup + statusBar := &ZCNStatus{wg: &wg} + txn, err := zcncore.NewTransaction(statusBar, 0) + if err != nil { + log.Fatal(err) + } + + wg.Add(1) + if err = txn.InterestPoolUpdateConfig(input); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + statusBar.success = false + wg.Add(1) + if err = txn.Verify(); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + fmt.Printf("interest pool smart contract settings updated\nHash: %v\n", txn.GetTransactionHash()) + }, +} + +func init() { + rootCmd.AddCommand(updateInterestPoolConfigCmd) + updateInterestPoolConfigCmd.PersistentFlags().StringSlice("keys", nil, "list of keys") + updateInterestPoolConfigCmd.PersistentFlags().StringSlice("values", nil, "list of new values") +} diff --git a/cmd/minersc.go b/cmd/minersc.go index 87ff09fb..92970e5e 100644 --- a/cmd/minersc.go +++ b/cmd/minersc.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "encoding/json" "fmt" "log" "strings" @@ -13,6 +14,109 @@ import ( "github.com/spf13/cobra" ) +var minerscUpdateSettings = &cobra.Command{ + Use: "mn-update-settings", + Short: "Change miner/sharder settings in Miner SC.", + Long: "Change miner/sharder settings in Miner SC by delegate wallet.", + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + + var ( + flags = cmd.Flags() + id string + err error + ) + + if !flags.Changed("id") { + log.Fatal("missing id flag") + } + + if id, err = flags.GetString("id"); err != nil { + log.Fatal(err) + } + + var ( + miner *zcncore.MinerSCMinerInfo + wg sync.WaitGroup + statusBar = &ZCNStatus{wg: &wg} + ) + wg.Add(1) + if err = zcncore.GetMinerSCNodeInfo(id, statusBar); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + miner = new(zcncore.MinerSCMinerInfo) + err = json.Unmarshal([]byte(statusBar.errMsg), miner) + if err != nil { + log.Fatal(err) + } + + // remove not settings fields + miner = &zcncore.MinerSCMinerInfo{SimpleMinerSCMinerInfo: &zcncore.SimpleMinerSCMinerInfo{ + NumberOfDelegates: miner.NumberOfDelegates, + MinStake: miner.MinStake, + MaxStake: miner.MaxStake, + ID: id, + }, + } + + if flags.Changed("num_delegates") { + miner.NumberOfDelegates, err = flags.GetInt("num_delegates") + if err != nil { + log.Fatal(err) + } + } + + if flags.Changed("min_stake") { + var min float64 + if min, err = flags.GetFloat64("min_stake"); err != nil { + log.Fatal(err) + } + miner.MinStake = common.Balance(zcncore.ConvertToValue(min)) + } + + if flags.Changed("max_stake") { + var max float64 + if max, err = flags.GetFloat64("max_stake"); err != nil { + log.Fatal(err) + } + miner.MaxStake = common.Balance(zcncore.ConvertToValue(max)) + } + + txn, err := zcncore.NewTransaction(statusBar, 0) + if err != nil { + log.Fatal(err) + } + wg.Add(1) + if err = txn.MinerSCMinerSettings(miner); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + statusBar.success = false + wg.Add(1) + if err = txn.Verify(); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + fmt.Println("settings updated") + }, +} + var minerscInfo = &cobra.Command{ Use: "mn-info", Short: "Get miner/sharder info from Miner SC.", @@ -417,57 +521,13 @@ var minerscUnlock = &cobra.Command{ }, } -var minerConfig = &cobra.Command{ - Use: "mn-config", - Short: "Get miner SC global info.", - Long: "Get miner SC global info.", - Args: cobra.MinimumNArgs(0), - Run: func(cmd *cobra.Command, args []string) { - - var ( - conf = new(zcncore.MinerSCConfig) - cb = NewJSONInfoCB(conf) - err error - ) - - if err = zcncore.GetMinerSCConfig(cb); err != nil { - log.Fatal(err) - } - if err = cb.Waiting(); err != nil { - log.Fatal(err) - } - - fmt.Println("view_change: ", conf.ViewChange) - fmt.Println("max_n: ", conf.MaxN) - fmt.Println("min_n: ", conf.MinN) - fmt.Println("max_s: ", conf.MaxS) - fmt.Println("min_s: ", conf.MinS) - fmt.Println("t_percent: ", conf.TPercent) - fmt.Println("k_percent: ", conf.KPercent) - fmt.Println("last_round: ", conf.LastRound) - fmt.Println("max_stake: ", conf.MaxStake) - fmt.Println("min_stake: ", conf.MinStake) - fmt.Println("interest_rate: ", conf.InterestRate) - fmt.Println("reward_rate: ", conf.RewardRate) - fmt.Println("share_ratio: ", conf.ShareRatio) - fmt.Println("block_reward: ", conf.BlockReward) - fmt.Println("max_charge: ", conf.MaxCharge) - fmt.Println("epoch: ", conf.Epoch) - fmt.Println("reward_decline_rate: ", conf.RewardDeclineRate) - fmt.Println("interest_decline_rate:", conf.InterestDeclineRate) - fmt.Println("max_mint: ", conf.MaxMint) - fmt.Println("minted: ", conf.Minted) - fmt.Println("max_delegates: ", conf.MaxDelegates) - }, -} - func init() { + rootCmd.AddCommand(minerscUpdateSettings) rootCmd.AddCommand(minerscInfo) rootCmd.AddCommand(minerscUserInfo) rootCmd.AddCommand(minerscPoolInfo) rootCmd.AddCommand(minerscLock) rootCmd.AddCommand(minerscUnlock) - rootCmd.AddCommand(minerConfig) rootCmd.AddCommand(minerscMiners) rootCmd.AddCommand(minerscSharders) @@ -475,6 +535,12 @@ func init() { minerscSharders.PersistentFlags().Bool("json", false, "as JSON") minerscSharders.PersistentFlags().Bool("all", false, "include all registered sharders") + minerscUpdateSettings.PersistentFlags().String("id", "", "miner/sharder ID to update") + minerscUpdateSettings.PersistentFlags().Int("num_delegates", 0, "max number of delegate pools") + minerscUpdateSettings.PersistentFlags().Float64("min_stake", 0.0, "min stake allowed") + minerscUpdateSettings.PersistentFlags().Float64("max_stake", 0.0, "max stake allowed") + minerscUpdateSettings.MarkFlagRequired("id") + minerscInfo.PersistentFlags().String("id", "", "miner/sharder ID to get info for") minerscInfo.MarkFlagRequired("id") diff --git a/cmd/mn-config.go b/cmd/mn-config.go new file mode 100644 index 00000000..6bb1a38d --- /dev/null +++ b/cmd/mn-config.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "log" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" +) + +var mnConfigCmd = &cobra.Command{ + Use: "mn-config", + Short: "Show miner SC configuration.", + Long: `Show miner SC configuration.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var ( + fields = new(zcncore.InputMap) + cb = NewJSONInfoCB(fields) + err error + ) + if err = zcncore.GetMinerSCConfig(cb); err != nil { + log.Fatal(err) + } + if err = cb.Waiting(); err != nil { + log.Fatal(err) + } + + printMap(fields.Fields) + }, +} + +func init() { + rootCmd.AddCommand(mnConfigCmd) +} diff --git a/cmd/mn-update-config.go b/cmd/mn-update-config.go new file mode 100644 index 00000000..251403f2 --- /dev/null +++ b/cmd/mn-update-config.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + "log" + "sync" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" +) + +var updateMinerScConfigCmd = &cobra.Command{ + Use: "mn-update-config", + Short: "Update the miner smart contract", + Long: `Update the miner smart contract.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var err error + + input := new(zcncore.InputMap) + input.Fields = setupInputMap(cmd.Flags()) + if err != nil { + log.Fatal(err) + } + + var wg sync.WaitGroup + statusBar := &ZCNStatus{wg: &wg} + txn, err := zcncore.NewTransaction(statusBar, 0) + if err != nil { + log.Fatal(err) + } + + wg.Add(1) + if err = txn.MinerScUpdateConfig(input); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + statusBar.success = false + wg.Add(1) + if err = txn.Verify(); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + fmt.Printf("storagesc smart contract settings updated\nHash: %v\n", txn.GetTransactionHash()) + }, +} + +func init() { + rootCmd.AddCommand(updateMinerScConfigCmd) + updateMinerScConfigCmd.PersistentFlags().StringSlice("keys", nil, "list of keys") + updateMinerScConfigCmd.PersistentFlags().StringSlice("values", nil, "list of new values") +} diff --git a/cmd/sc-config.go b/cmd/sc-config.go new file mode 100644 index 00000000..374c8c9e --- /dev/null +++ b/cmd/sc-config.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" + "log" +) + +// scConfig shows SC configurations +var scConfig = &cobra.Command{ + Use: "sc-config", + Short: "Show storage SC configuration.", + Long: `Show storage SC configuration.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var ( + fields = new(zcncore.InputMap) + cb = NewJSONInfoCB(fields) + err error + ) + if err = zcncore.GetStorageSCConfig(cb); err != nil { + log.Fatal(err) + } + if err = cb.Waiting(); err != nil { + log.Fatal(err) + } + + printMap(fields.Fields) + }, +} + +func init() { + rootCmd.AddCommand(scConfig) +} diff --git a/cmd/sc-update-config.go b/cmd/sc-update-config.go new file mode 100644 index 00000000..23bf8b1a --- /dev/null +++ b/cmd/sc-update-config.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + "log" + "sync" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" +) + +var updateStoragScConfigCmd = &cobra.Command{ + Use: "sc-update-config", + Short: "Update the storage smart contract", + Long: `Update the storage smart contract.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var err error + + input := new(zcncore.InputMap) + input.Fields = setupInputMap(cmd.Flags()) + if err != nil { + log.Fatal(err) + } + + var wg sync.WaitGroup + statusBar := &ZCNStatus{wg: &wg} + txn, err := zcncore.NewTransaction(statusBar, 0) + if err != nil { + log.Fatal(err) + } + + wg.Add(1) + if err = txn.StorageScUpdateConfig(input); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + statusBar.success = false + wg.Add(1) + if err = txn.Verify(); err != nil { + log.Fatal(err) + } + wg.Wait() + + if !statusBar.success { + log.Fatal("fatal:", statusBar.errMsg) + } + + fmt.Printf("storagesc smart contract settings updated\nHash: %v\n", txn.GetTransactionHash()) + }, +} + +func init() { + rootCmd.AddCommand(updateStoragScConfigCmd) + updateStoragScConfigCmd.PersistentFlags().StringSlice("keys", nil, "list of keys") + updateStoragScConfigCmd.PersistentFlags().StringSlice("values", nil, "list of new values") +} diff --git a/cmd/vesting.go b/cmd/vesting.go index 43180e42..6a32c0b9 100644 --- a/cmd/vesting.go +++ b/cmd/vesting.go @@ -13,33 +13,6 @@ import ( "github.com/spf13/cobra" ) -var getVestingPoolConfigCmd = &cobra.Command{ - Use: "vp-config", - Short: "Check out vesting pool configurations.", - Long: `Check out vesting pool configurations.`, - Args: cobra.MinimumNArgs(0), - Run: func(cmd *cobra.Command, args []string) { - - var ( - conf = new(zcncore.VestingSCConfig) - cb = NewJSONInfoCB(conf) - err error - ) - if err = zcncore.GetVestingSCConfig(cb); err != nil { - log.Fatal(err) - } - if err = cb.Waiting(); err != nil { - log.Fatal(err) - } - - fmt.Println("min_lock:", conf.MinLock) - fmt.Println("min_duration:", conf.MinDuration) - fmt.Println("max_duration:", conf.MaxDuration) - fmt.Println("max_destinations:", conf.MaxDestinations) - fmt.Println("max_description_length:", conf.MaxDescriptionLength) - }, -} - var getVestingPoolInfoCmd = &cobra.Command{ Use: "vp-info", Short: "Check out vesting pool information.", @@ -521,7 +494,6 @@ func init() { log.SetOutput(os.Stdout) log.SetFlags(0) - rootCmd.AddCommand(getVestingPoolConfigCmd) rootCmd.AddCommand(getVestingPoolInfoCmd) rootCmd.AddCommand(getVestingClientPoolsCmd) rootCmd.AddCommand(vestingPoolAddCmd) diff --git a/cmd/vp-config.go b/cmd/vp-config.go new file mode 100644 index 00000000..a20bc1ed --- /dev/null +++ b/cmd/vp-config.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "log" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" +) + +var getVestingPoolConfigCmd = &cobra.Command{ + Use: "vp-config", + Short: "Check out vesting pool configurations.", + Long: `Check out vesting pool configurations.`, + Args: cobra.MinimumNArgs(0), + Run: func(cmd *cobra.Command, args []string) { + var ( + fields = new(zcncore.InputMap) + cb = NewJSONInfoCB(fields) + err error + ) + if err = zcncore.GetVestingSCConfig(cb); err != nil { + log.Fatal(err) + } + if err = cb.Waiting(); err != nil { + log.Fatal(err) + } + + printMap(fields.Fields) + }, +} + +func init() { + rootCmd.AddCommand(getVestingPoolConfigCmd) +} diff --git a/cmd/vp-update-settings.go b/cmd/vp-update-settings.go index fbb4fab8..b916af5f 100644 --- a/cmd/vp-update-settings.go +++ b/cmd/vp-update-settings.go @@ -1,13 +1,12 @@ package cmd -/* import ( "fmt" - "github.com/0chain/gosdk/core/common" - "github.com/0chain/gosdk/zcncore" - "github.com/spf13/cobra" "log" "sync" + + "github.com/0chain/gosdk/zcncore" + "github.com/spf13/cobra" ) var updateVestingPoolConfigCmd = &cobra.Command{ @@ -16,50 +15,23 @@ var updateVestingPoolConfigCmd = &cobra.Command{ Long: `Update the vesting pool configurations.`, Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { + var err error - var ( - flags = cmd.Flags() - err error - conf = new(zcncore.InputMap) - wg sync.WaitGroup - statusBar = &ZCNStatus{wg: &wg} - ) - conf.Fields = make(map[string]interface{}) - if flags.Changed("min_lock") { - var minLock float64 - if minLock, err = flags.GetFloat64("min_lock"); err != nil { - log.Fatal(err) - } - conf.Fields["min_lock"] = common.Balance(zcncore.ConvertToValue(minLock)) - } - if flags.Changed("max_destinations") { - if conf.Fields["max_destinations"], err = flags.GetInt("max_destinations"); err != nil { - log.Fatal(err) - } - } - if flags.Changed("max_description_length") { - if conf.Fields["max_description_length"], err = flags.GetInt("max_description_length"); err != nil { - log.Fatal(err) - } - } - - if flags.Changed("min_duration") { - if conf.Fields["min_duration"], err = flags.GetDuration("min_duration"); err != nil { - log.Fatal(err) - } - } - if flags.Changed("max_duration") { - if conf.Fields["max_duration"], err = flags.GetDuration("max_duration"); err != nil { - log.Fatal(err) - } + input := new(zcncore.InputMap) + input.Fields = setupInputMap(cmd.Flags()) + if err != nil { + log.Fatal(err) } + var wg sync.WaitGroup + statusBar := &ZCNStatus{wg: &wg} txn, err := zcncore.NewTransaction(statusBar, 0) if err != nil { log.Fatal(err) } + wg.Add(1) - if err = txn.VestingUpdateConfig(conf); err != nil { + if err = txn.VestingUpdateConfig(input); err != nil { log.Fatal(err) } wg.Wait() @@ -79,16 +51,12 @@ var updateVestingPoolConfigCmd = &cobra.Command{ log.Fatal("fatal:", statusBar.errMsg) } - fmt.Println("vesting smart contract settings updated") + fmt.Printf("vesting smart contract settings updated\nHash: %v\n", txn.GetTransactionHash()) }, } func init() { rootCmd.AddCommand(updateVestingPoolConfigCmd) - updateVestingPoolConfigCmd.PersistentFlags().Int("max_description_length", 0, "max length for descriptions") - updateVestingPoolConfigCmd.PersistentFlags().Int("max_destinations", 0, "max destinations allowed") - updateVestingPoolConfigCmd.PersistentFlags().Float64("min_lock", 0.0, "minimum lock for vesting") - updateVestingPoolConfigCmd.PersistentFlags().Duration("min_duration", 0.0, "minimum duration for vesting") - updateVestingPoolConfigCmd.PersistentFlags().Duration("max_duration", 0.0, "max duration for vesting") + updateVestingPoolConfigCmd.PersistentFlags().StringSlice("keys", nil, "list of keys") + updateVestingPoolConfigCmd.PersistentFlags().StringSlice("values", nil, "list of new values") } -*/ diff --git a/go.mod b/go.mod index 1ee6b28d..2dbdde28 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/0chain/zwalletcli require ( - github.com/0chain/gosdk v1.2.82 - github.com/lithammer/shortuuid v3.0.0+incompatible // indirect + github.com/0chain/gosdk v1.2.85-0.20210907154742-fb906840f621 github.com/mattn/go-colorable v0.1.4 // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/cobra v1.1.1 + github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.7.0 gopkg.in/cheggaaa/pb.v1 v1.0.28 ) diff --git a/go.sum b/go.sum index 643116cc..0697850b 100644 --- a/go.sum +++ b/go.sum @@ -19,11 +19,12 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/0chain/errors v1.0.2 h1:IIUMeh/qFlqDcyHesjU92CpRMVz9dIQWAtZooqrYinA= github.com/0chain/errors v1.0.2/go.mod h1:5t76jLb56TKfg/K2VD+eUMmNZJ42QsIRI8KzWuztwU4= -github.com/0chain/gosdk v0.0.0 h1:T1/BfSDmsca3SwgQStHP1Ao064P+VX/Rq73TBs6wpNA= -github.com/0chain/gosdk v0.0.0/go.mod h1:hdcqCl4oksjF5pU0XqvaTlNotppFOiGWrzVHfEMgvXM= -github.com/0chain/gosdk v1.2.82 h1:qm0BkPAaiZqKbrgCPf9csaZqTaBkPTrqy9Ehu3Q2D4M= -github.com/0chain/gosdk v1.2.82/go.mod h1:Bl/wsHdlktgXybdzkHPfaf6ATe7mPmew/xF3ki2gskQ= +github.com/0chain/gosdk v1.2.85-0.20210907143648-c09d2e991a85 h1:J020zuYTRb+e/93Rn8groQln6RzWqLLO2u+7oeJUyR0= +github.com/0chain/gosdk v1.2.85-0.20210907143648-c09d2e991a85/go.mod h1:Bl/wsHdlktgXybdzkHPfaf6ATe7mPmew/xF3ki2gskQ= +github.com/0chain/gosdk v1.2.85-0.20210907154742-fb906840f621 h1:HmRubsiC8xDTULh5B/8LB8fxfdgnrfG4B1WDIa5AiWY= +github.com/0chain/gosdk v1.2.85-0.20210907154742-fb906840f621/go.mod h1:Bl/wsHdlktgXybdzkHPfaf6ATe7mPmew/xF3ki2gskQ= github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc= github.com/Azure/azure-storage-blob-go v0.7.0/go.mod h1:f9YQKtsG1nMisotuTPpO0tjNuEjKRYAcJU8/ydDI++4= @@ -281,8 +282,8 @@ github.com/google/protobuf v3.14.0+incompatible/go.mod h1:lUQ9D1ePzbH2PrIS7ob/bj github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.5 h1:kxhtnfFVi+rYdOALN0B3k9UT86zVJKfBimRaciULW4I= github.com/google/uuid v1.1.5/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -428,7 +429,7 @@ github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2 github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w= +github.com/lithammer/shortuuid/v3 v3.0.7 h1:trX0KTHy4Pbwo/6ia8fscyHoGA+mf1jWbPJVuvyJQQ8= github.com/lithammer/shortuuid/v3 v3.0.7/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=