-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wsctl): add project configuration cmd #4195
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2588b53
feat(wsctl): add project configuration cmd
hunshenshi dadcad7
feat(wsctl): update comment and del mock_envelope.go
hunshenshi 597d673
Merge branch 'master' into wsctl-prj
hunshenshi 4081bb8
feat(wsctl): fix ci
hunshenshi cf755e0
Merge branch 'wsctl-prj' of github.com:iotexproject/iotex-core into w…
hunshenshi 207d2f3
Merge branch 'master' into wsctl-prj
hunshenshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,10 @@ import ( | |
) | ||
|
||
var ( | ||
// wsCodeConvert represents the w3bstream code convert command | ||
wsCodeConvert = &cobra.Command{ | ||
Use: "convert", | ||
Short: config.TranslateInLang(wsCodeConvertShorts, config.UILanguage), | ||
// wsProjectConfig represents the generate w3bstream project configuration command | ||
wsProjectConfig = &cobra.Command{ | ||
Use: "config", | ||
Short: config.TranslateInLang(wsProjectConfigShorts, config.UILanguage), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
version, err := cmd.Flags().GetString("version") | ||
if err != nil { | ||
|
@@ -42,8 +42,12 @@ var ( | |
if err != nil { | ||
return errors.Wrap(err, "failed to get flag expand-param") | ||
} | ||
outputFile, err := cmd.Flags().GetString("output-file") | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get flag output-file") | ||
} | ||
|
||
out, err := generateProjectFile(version, vmType, codeFile, confFile, expParam) | ||
out, err := generateProjectFile(version, vmType, codeFile, confFile, expParam, outputFile) | ||
if err != nil { | ||
return output.PrintError(err) | ||
} | ||
|
@@ -52,10 +56,10 @@ var ( | |
}, | ||
} | ||
|
||
// wsCodeConvertShorts w3bstream code convert shorts multi-lang support | ||
wsCodeConvertShorts = map[config.Language]string{ | ||
config.English: "convert zkp code to hex string compressed with zlib", | ||
config.Chinese: "将zkp代码通过zlib进行压缩之后转成hex字符串", | ||
// wsProjectConfigShorts w3bstream project configuration shorts multi-lang support | ||
wsProjectConfigShorts = map[config.Language]string{ | ||
config.English: "generate w3bstream project configuration file", | ||
config.Chinese: "生成项目的配置文件", | ||
} | ||
|
||
_flagVersionUsages = map[config.Language]string{ | ||
|
@@ -78,21 +82,26 @@ var ( | |
config.English: "expand param, if you use risc0 vm, need it.", | ||
config.Chinese: "扩展参数,risc0虚拟机需要此参数", | ||
} | ||
_flagOutputFileUsages = map[config.Language]string{ | ||
config.English: "output file, default is stdout.", | ||
config.Chinese: "output的值所在文件,指定proof的输出", | ||
} | ||
) | ||
|
||
func init() { | ||
wsCodeConvert.Flags().StringP("version", "v", "", config.TranslateInLang(_flagVersionUsages, config.UILanguage)) | ||
wsCodeConvert.Flags().StringP("vm-type", "t", "", config.TranslateInLang(_flagVMTypeUsages, config.UILanguage)) | ||
wsCodeConvert.Flags().StringP("code-file", "i", "", config.TranslateInLang(_flagCodeFileUsages, config.UILanguage)) | ||
wsCodeConvert.Flags().StringP("conf-file", "c", "", config.TranslateInLang(_flagConfFileUsages, config.UILanguage)) | ||
wsCodeConvert.Flags().StringP("expand-param", "e", "", config.TranslateInLang(_flagExpandParamUsages, config.UILanguage)) | ||
|
||
_ = wsCodeConvert.MarkFlagRequired("version") | ||
_ = wsCodeConvert.MarkFlagRequired("vm-type") | ||
_ = wsCodeConvert.MarkFlagRequired("code-file") | ||
wsProjectConfig.Flags().StringP("version", "v", "", config.TranslateInLang(_flagVersionUsages, config.UILanguage)) | ||
wsProjectConfig.Flags().StringP("vm-type", "t", "", config.TranslateInLang(_flagVMTypeUsages, config.UILanguage)) | ||
wsProjectConfig.Flags().StringP("code-file", "i", "", config.TranslateInLang(_flagCodeFileUsages, config.UILanguage)) | ||
wsProjectConfig.Flags().StringP("conf-file", "c", "", config.TranslateInLang(_flagConfFileUsages, config.UILanguage)) | ||
wsProjectConfig.Flags().StringP("expand-param", "e", "", config.TranslateInLang(_flagExpandParamUsages, config.UILanguage)) | ||
wsProjectConfig.Flags().StringP("output-file", "u", "", config.TranslateInLang(_flagOutputFileUsages, config.UILanguage)) | ||
|
||
_ = wsProjectConfig.MarkFlagRequired("version") | ||
_ = wsProjectConfig.MarkFlagRequired("vm-type") | ||
_ = wsProjectConfig.MarkFlagRequired("code-file") | ||
} | ||
|
||
func generateProjectFile(version, vmType, codeFile, confFile, expParam string) (string, error) { | ||
func generateProjectFile(version, vmType, codeFile, confFile, expParam, outputFile string) (string, error) { | ||
tye, err := stringToVMType(vmType) | ||
if err != nil { | ||
return "", err | ||
|
@@ -103,16 +112,33 @@ func generateProjectFile(version, vmType, codeFile, confFile, expParam string) ( | |
return "", err | ||
} | ||
|
||
confMaps := make([]map[string]interface{}, 0) | ||
var ( | ||
confMaps = make([]map[string]interface{}, 0) | ||
confMap = make(map[string]interface{}) | ||
outputMap = make(map[string]interface{}) | ||
) | ||
|
||
confMap := make(map[string]interface{}) | ||
if expParam != "" { | ||
confMap["codeExpParam"] = expParam | ||
} | ||
confMap["vmType"] = string(tye) | ||
confMap["code"] = hexString | ||
confMap["version"] = version | ||
|
||
output := []byte(`{ | ||
"type": "stdout" | ||
}`) | ||
if outputFile != "" { | ||
output, err = os.ReadFile(outputFile) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to read output file") | ||
} | ||
} | ||
if err := json.Unmarshal(output, &outputMap); err != nil { | ||
return "", errors.Wrap(err, "failed to unmarshal output file") | ||
} | ||
confMap["output"] = outputMap | ||
|
||
confMaps = append(confMaps, confMap) | ||
jsonConf, err := json.MarshalIndent(confMaps, "", " ") | ||
if err != nil { | ||
|
@@ -147,3 +173,29 @@ func convertCodeToZlibHex(codeFile string) (string, error) { | |
|
||
return hexString, err | ||
} | ||
|
||
// zkp vm type | ||
type vmType string | ||
|
||
const ( | ||
risc0 vmType = "risc0" // risc0 vm | ||
halo2 vmType = "halo2" // halo2 vm | ||
zkWasm vmType = "zkwasm" // zkwasm vm | ||
wasm vmType = "wasm" // wasm vm | ||
) | ||
|
||
// TODO move this to sprout | ||
func stringToVMType(vmType string) (vmType, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be/has been done at API side There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add TODO |
||
switch vmType { | ||
case string(risc0): | ||
return risc0, nil | ||
case string(halo2): | ||
return halo2, nil | ||
case string(zkWasm): | ||
return zkWasm, nil | ||
case string(wasm): | ||
return wasm, nil | ||
default: | ||
return "", errors.New(fmt.Sprintf("not support %s type, just support %s, %s, %s, and %s", vmType, risc0, halo2, zkWasm, wasm)) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will err be returned without output flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep same with other param's error