-
Notifications
You must be signed in to change notification settings - Fork 332
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(ioctl): project state and operator subcommands #4024
Open
saitofun
wants to merge
17
commits into
master
Choose a base branch
from
feat/project_state_and_operator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+322
−52
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7e840a6
feat(ioctl): optimize w3bstream project subcommand
saitofun 07f5178
feat(ioctl): project state and operator subcommands
saitofun de0705f
feat(ioctl): hardcode default ipfs endpoint and ipfs gateway with scheme
saitofun 1a050dd
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun fafaefd
feat(ioctl): optimize w3bstream project subcommand
saitofun 9997809
Merge branch 'feat/optimize_ws_project' of github.com:iotexproject/io…
saitofun d06e280
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun 2c6ba0a
chore: move _flags
saitofun e0b1603
WIP
saitofun c8093ec
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun 6450b39
fix comments
saitofun 5812647
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun 4f43ab1
fix: wait and check operator mgr result
saitofun 2b93551
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun d3980cc
chore: patch threshold
saitofun dece639
chore: modify .codecov.yaml
saitofun 87ad9e8
chore: revert .codecov.yaml
saitofun 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 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
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package ws | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl/cmd/action" | ||
"github.com/iotexproject/iotex-core/ioctl/config" | ||
"github.com/iotexproject/iotex-core/ioctl/output" | ||
"github.com/iotexproject/iotex-core/ioctl/util" | ||
) | ||
|
||
var ( | ||
wsProjectStart = &cobra.Command{ | ||
Use: "start", | ||
Short: config.TranslateInLang(wsProjectStartShorts, config.UILanguage), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
id, err := cmd.Flags().GetUint64("project-id") | ||
if err != nil { | ||
return output.PrintError(err) | ||
} | ||
out, err := controlProjectState(id, startProject) | ||
if err != nil { | ||
return output.PrintError(err) | ||
} | ||
output.PrintResult(out) | ||
return nil | ||
}, | ||
} | ||
|
||
wsProjectStop = &cobra.Command{ | ||
Use: "stop", | ||
Short: config.TranslateInLang(wsProjectStopShorts, config.UILanguage), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
id, err := cmd.Flags().GetUint64("project-id") | ||
if err != nil { | ||
return output.PrintError(err) | ||
} | ||
out, err := controlProjectState(id, stopProject) | ||
if err != nil { | ||
return output.PrintError(err) | ||
} | ||
output.PrintResult(out) | ||
return nil | ||
}, | ||
} | ||
|
||
wsProjectStartShorts = map[config.Language]string{ | ||
config.English: "start w3bstream project", | ||
config.Chinese: "开启项目", | ||
} | ||
|
||
wsProjectStopShorts = map[config.Language]string{ | ||
saitofun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
config.English: "stop w3bstream project", | ||
config.Chinese: "停止项目", | ||
} | ||
) | ||
|
||
const ( | ||
startProject = 0 | ||
stopProject = 1 | ||
) | ||
|
||
func init() { | ||
wsProjectStop.Flags().Uint64P("project-id", "i", 0, config.TranslateInLang(_flagProjectIDUsages, config.UILanguage)) | ||
wsProjectStart.Flags().Uint64P("project-id", "i", 0, config.TranslateInLang(_flagProjectIDUsages, config.UILanguage)) | ||
|
||
_ = wsProjectStop.MarkFlagRequired("project-id") | ||
_ = wsProjectStart.MarkFlagRequired("project-id") | ||
} | ||
|
||
func controlProjectState(projectID uint64, command int) (string, error) { | ||
var funcName string | ||
switch command { | ||
case startProject: | ||
funcName = startWsProjectFuncName | ||
case stopProject: | ||
funcName = stopWsProjectFuncName | ||
default: | ||
return "", errors.New("invalid control command") | ||
} | ||
saitofun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
contract, err := util.Address(wsProjectRegisterContractAddress) | ||
if err != nil { | ||
return "", output.NewError(output.AddressError, "failed to get project register contract address", err) | ||
} | ||
|
||
bytecode, err := wsProjectRegisterContractABI.Pack(funcName, projectID) | ||
if err != nil { | ||
return "", output.NewError(output.ConvertError, fmt.Sprintf("failed to pack abi"), err) | ||
} | ||
|
||
rsp, err := action.ExecuteAndResponse(contract, big.NewInt(0), bytecode) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to execute contract") | ||
} | ||
_, err = waitReceiptByActionHash(rsp.ActionHash) | ||
if err != nil { | ||
return "", errors.Wrap(err, "failed to wait event") | ||
} | ||
if command == startProject { | ||
return fmt.Sprintf("project %d started", projectID), nil | ||
} | ||
return fmt.Sprintf("project %d stopped", projectID), nil | ||
} |
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
Oops, something went wrong.
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.
move this to
ws.go