diff --git a/ioctl/cmd/ws/ws.go b/ioctl/cmd/ws/ws.go index ffee2c5e0e..777647b294 100644 --- a/ioctl/cmd/ws/ws.go +++ b/ioctl/cmd/ws/ws.go @@ -28,6 +28,10 @@ var ( config.English: "set w3bsteram endpoint for once", config.Chinese: "一次设置w3bstream端点", } + _flagContractAddressUsages = map[config.Language]string{ + config.English: "set w3bsteram project register contract address for once", + config.Chinese: "一次设置w3bstream项目注册合约地址", + } ) func init() { @@ -43,4 +47,8 @@ func init() { &config.ReadConfig.WsEndpoint, "ws-endpoint", config.ReadConfig.WsEndpoint, config.TranslateInLang(_flagWsEndpointUsages, config.UILanguage), ) + WsCmd.PersistentFlags().StringVar( + &config.ReadConfig.WsRegisterContract, "contract-address", + config.ReadConfig.WsRegisterContract, config.TranslateInLang(_flagContractAddressUsages, config.UILanguage), + ) } diff --git a/ioctl/cmd/ws/wsproject.go b/ioctl/cmd/ws/wsproject.go index 16938343a4..e5ddc0de0e 100644 --- a/ioctl/cmd/ws/wsproject.go +++ b/ioctl/cmd/ws/wsproject.go @@ -39,11 +39,6 @@ var ( config.Chinese: "w3bstream项目管理", } - _flagProjectRegisterContractAddressUsages = map[config.Language]string{ - config.English: "project register contract address", - config.Chinese: "项目注册合约地址", - } - wsProjectRegisterContractAddress string wsProjectRegisterContractABI abi.ABI @@ -69,14 +64,7 @@ func init() { wsProject.AddCommand(wsProjectUpdate) wsProject.AddCommand(wsProjectQuery) - wsProject.PersistentFlags().StringVarP( - &wsProjectRegisterContractAddress, - "contract-address", - "c", - "", - config.TranslateInLang(_flagProjectRegisterContractAddressUsages, config.UILanguage), - ) - _ = wsProject.MarkFlagRequired("contract-address") + wsProjectRegisterContractAddress = config.ReadConfig.WsRegisterContract } func convertStringToAbiBytes32(hash string) (interface{}, error) { diff --git a/ioctl/config/config.go b/ioctl/config/config.go index 623da2b182..9956068452 100644 --- a/ioctl/config/config.go +++ b/ioctl/config/config.go @@ -69,6 +69,8 @@ type Config struct { AnalyserEndpoint string `json:"analyserEndpoint" yaml:"analyserEndpoint"` // WsEndpoint w3bstream endpoint WsEndpoint string `json:"wsEndpoint" yaml:"wsEndpoint"` + // WsRegisterContract w3bstream project register contract address + WsRegisterContract string `json:"wsProjectRegisterContract" yaml:"wsProjectRegisterContract"` } var ( @@ -120,6 +122,10 @@ func init() { ReadConfig.WsEndpoint = _defaultWsEndpoint completeness = false } + if ReadConfig.WsRegisterContract == "" { + ReadConfig.WsRegisterContract = _defaultProjectRegisterContract + completeness = false + } if !completeness { err := writeConfig() if err != nil { diff --git a/ioctl/config/configsetget.go b/ioctl/config/configsetget.go index 7a98dfe99e..b6df0f4ac0 100644 --- a/ioctl/config/configsetget.go +++ b/ioctl/config/configsetget.go @@ -28,12 +28,14 @@ const ( _endpointPattern = "(" + _ipPattern + "|(" + _domainPattern + ")" + "|(" + _localPattern + "))" + `(:\d{1,5})?` _defaultAnalyserEndpoint = "https://iotex-analyser-api-mainnet.chainanalytics.org" _defaultWsEndpoint = "sprout-staging.w3bstream.com:9000" + // _defaultProjectRegisterContract default project register contract address + _defaultProjectRegisterContract = "0x4F7e678B0203e0444E17512108dba4B08B39512e" ) var ( _supportedLanguage = []string{"English", "中文"} - _validArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height", "wsEndpoint"} - _validGetArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height", "analyserEndpoint", "wsEndpoint", "all"} + _validArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height", "wsEndpoint", "projectRegisterContract"} + _validGetArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height", "analyserEndpoint", "wsEndpoint", "projectRegisterContract", "all"} _validExpl = []string{"iotexscan", "iotxplorer"} _endpointCompile = regexp.MustCompile("^" + _endpointPattern + "$") ) @@ -151,6 +153,8 @@ func Get(arg string) error { fmt.Println(ReadConfig.AnalyserEndpoint) case "wsEndpoint": fmt.Println(ReadConfig.WsEndpoint) + case "projectRegisterContract": + fmt.Println(ReadConfig.WsRegisterContract) case "all": fmt.Println(ReadConfig.String()) } @@ -281,6 +285,8 @@ func set(args []string) error { ReadConfig.Nsv2height = height case "wsEndpoint": ReadConfig.WsEndpoint = args[1] + case "projectRegisterContract": + ReadConfig.WsRegisterContract = args[1] } err := writeConfig() if err != nil { @@ -300,6 +306,7 @@ func reset() error { ReadConfig.Language = "English" ReadConfig.AnalyserEndpoint = _defaultAnalyserEndpoint ReadConfig.WsEndpoint = _defaultWsEndpoint + ReadConfig.WsRegisterContract = _defaultProjectRegisterContract err := writeConfig() if err != nil { diff --git a/ioctl/newcmd/config/config.go b/ioctl/newcmd/config/config.go index 19e37efa12..a798825c1b 100644 --- a/ioctl/newcmd/config/config.go +++ b/ioctl/newcmd/config/config.go @@ -35,12 +35,14 @@ const ( _defaultAnalyserEndpoint = "https://iotex-analyser-api-mainnet.chainanalytics.org" _defaultWsEndpoint = "sprout-staging.w3bstream.com:9000" _defaultConfigFileName = "config.default" + // _defaultWsProjectRegisterContract default w3bstream project register contract address + _defaultWsProjectRegisterContract = "0x4F7e678B0203e0444E17512108dba4B08B39512e" ) var ( _supportedLanguage = []string{"English", "中文"} - _validArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height"} - _validGetArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height", "analyserEndpoint", "all"} + _validArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height", "wsEndpoint", "wsProjectRegisterContract"} + _validGetArgs = []string{"endpoint", "wallet", "explorer", "defaultacc", "language", "nsv2height", "analyserEndpoint", "wsEndpoint", "wsProjectRegisterContract", "all"} _validExpl = []string{"iotexscan", "iotxplorer"} _endpointCompile = regexp.MustCompile("^" + _endpointPattern + "$") _configDir = os.Getenv("HOME") + "/.config/ioctl/default" @@ -120,6 +122,9 @@ func InitConfig() (config.Config, string, error) { info.readConfig.WsEndpoint = _defaultWsEndpoint completeness = false } + if info.readConfig.WsRegisterContract == "" { + info.readConfig.WsRegisterContract = _defaultWsProjectRegisterContract + } if !completeness { if err = info.writeConfig(); err != nil { return info.readConfig, info.defaultConfigFile, err @@ -150,6 +155,7 @@ func (c *info) reset() error { c.readConfig.Language = _supportedLanguage[0] c.readConfig.AnalyserEndpoint = _defaultAnalyserEndpoint c.readConfig.WsEndpoint = _defaultWsEndpoint + c.readConfig.WsRegisterContract = _defaultWsProjectRegisterContract err := c.writeConfig() if err != nil { @@ -210,6 +216,8 @@ func (c *info) set(args []string, insecure bool, client ioctl.Client) (string, e c.readConfig.Nsv2height = height case "wsEndpoint": c.readConfig.WsEndpoint = args[1] + case "wsProjectRegisterContract": + c.readConfig.WsRegisterContract = args[1] default: return "", config.ErrConfigNotMatch } @@ -247,6 +255,8 @@ func (c *info) get(arg string) (string, error) { return c.readConfig.AnalyserEndpoint, nil case "wsEndpoint": return c.readConfig.WsEndpoint, nil + case "wsProjectRegisterContract": + return c.readConfig.WsRegisterContract, nil case "all": return jsonString(c.readConfig) default: diff --git a/ioctl/newcmd/config/config_test.go b/ioctl/newcmd/config/config_test.go index 13cabbd2d0..79e042a800 100644 --- a/ioctl/newcmd/config/config_test.go +++ b/ioctl/newcmd/config/config_test.go @@ -47,14 +47,15 @@ func TestConfigGet(t *testing.T) { require := require.New(t) testPath := t.TempDir() info := newInfo(config.Config{ - Wallet: testPath, - SecureConnect: true, - Aliases: make(map[string]string), - DefaultAccount: config.Context{AddressOrAlias: "test"}, - Explorer: "iotexscan", - Language: "English", - AnalyserEndpoint: "testAnalyser", - WsEndpoint: "testWsEndpoint", + Wallet: testPath, + SecureConnect: true, + Aliases: make(map[string]string), + DefaultAccount: config.Context{AddressOrAlias: "test"}, + Explorer: "iotexscan", + Language: "English", + AnalyserEndpoint: "testAnalyser", + WsEndpoint: "testWsEndpoint", + WsRegisterContract: "testWsProjectRegisterContract", }, testPath) tcs := []struct { @@ -93,9 +94,13 @@ func TestConfigGet(t *testing.T) { "wsEndpoint", "testWsEndpoint", }, + { + "wsProjectRegisterContract", + "testWsProjectRegisterContract", + }, { "all", - "\"endpoint\": \"\",\n \"secureConnect\": true,\n \"aliases\": {},\n \"defaultAccount\": {\n \"addressOrAlias\": \"test\"\n },\n \"explorer\": \"iotexscan\",\n \"language\": \"English\",\n \"nsv2height\": 0,\n \"analyserEndpoint\": \"testAnalyser\",\n \"wsEndpoint\": \"testWsEndpoint\"\n}", + "\"endpoint\": \"\",\n \"secureConnect\": true,\n \"aliases\": {},\n \"defaultAccount\": {\n \"addressOrAlias\": \"test\"\n },\n \"explorer\": \"iotexscan\",\n \"language\": \"English\",\n \"nsv2height\": 0,\n \"analyserEndpoint\": \"testAnalyser\",\n \"wsEndpoint\": \"testWsEndpoint\",\n \"wsProjectRegisterContract\": \"testWsProjectRegisterContract\"\n}", }, } @@ -115,14 +120,15 @@ func TestConfigReset(t *testing.T) { cfgFile := fmt.Sprintf("%s/%s", cfgDir, "config.test") info := newInfo(config.Config{ - Wallet: "wallet", - Endpoint: "testEndpoint", - SecureConnect: false, - DefaultAccount: config.Context{AddressOrAlias: ""}, - Explorer: "explorer", - Language: "Croatian", - AnalyserEndpoint: "testAnalyser", - WsEndpoint: "testWsEndpoint", + Wallet: "wallet", + Endpoint: "testEndpoint", + SecureConnect: false, + DefaultAccount: config.Context{AddressOrAlias: ""}, + Explorer: "explorer", + Language: "Croatian", + AnalyserEndpoint: "testAnalyser", + WsEndpoint: "testWsEndpoint", + WsRegisterContract: "testProjectRegisterContract", }, cfgFile) // write the config to the temp dir and then reset @@ -138,6 +144,7 @@ func TestConfigReset(t *testing.T) { require.Equal("explorer", cfg.Explorer) require.Equal(config.Context{AddressOrAlias: ""}, cfg.DefaultAccount) require.Equal("testWsEndpoint", cfg.WsEndpoint) + require.Equal("testProjectRegisterContract", cfg.WsRegisterContract) require.NoError(info.reset()) require.NoError(info.loadConfig()) @@ -150,6 +157,7 @@ func TestConfigReset(t *testing.T) { require.Equal("English", resetCfg.Language) require.Equal(_defaultAnalyserEndpoint, resetCfg.AnalyserEndpoint) require.Equal(_defaultWsEndpoint, resetCfg.WsEndpoint) + require.Equal(_defaultWsProjectRegisterContract, resetCfg.WsRegisterContract) require.Equal("iotexscan", resetCfg.Explorer) require.Equal(*new(config.Context), resetCfg.DefaultAccount) } @@ -221,6 +229,10 @@ func TestConfigSet(t *testing.T) { []string{"wsEndpoint", "testWsEndpoint"}, "testWsEndpoint", }, + { + []string{"wsProjectRegisterContract", "testWsProjectRegisterContract"}, + "testWsProjectRegisterContract", + }, } for _, tc := range tcs {