-
Notifications
You must be signed in to change notification settings - Fork 148
Refactor cql command #284
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
Merged
Merged
Refactor cql command #284
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
a784986
Remove one useless flag. Reorder some code.
laodouya b5a8bfe
Split cql command func into internal package
laodouya 4a08673
Move log and waitTxConfirmationMaxDuration to internal vars.
laodouya b5e0875
Fix UsqlRegister should not use outside variable.
laodouya 60a6806
Move cql console funcs to internal/command
laodouya 32718ec
Refactor interactive usql feature into console command.
laodouya c9735f1
Refactor version print into version command.
laodouya d186072
Refactor token balance check funcs into balance command.
laodouya 2f59c1d
Refactor createDB feature into create command.
laodouya dc4fa1a
Refactor dropDB feature into drop command.
laodouya 292137c
Fail while cql drop command could not wait tx confirm.
laodouya 8513210
Refactor updatePermission feature into permission command.
laodouya eb6f562
Refactor transferToken feature into transfer command.
laodouya 93b77dd
Move ConsoleLog init into package.
laodouya bbef278
Refactor explorer feature into cql web command.
laodouya b49fee4
Refactor adapter feature into cql adapter command.
laodouya 3a04bf7
Add new line after one console output.
laodouya f7af2a4
Change web and adapter start process into a func.
laodouya 29bd64b
Add web and adapter params for console command.
laodouya 70ec1fa
Make golint happy.
laodouya 2c5d31c
Fix cql test case.
laodouya d3b14b7
Fix old client compatibility test.
laodouya dcad0f4
Fix unit test: cql.test should set -test.coverprofile flag first befo…
laodouya 159e0ff
Fix compatibility test.
laodouya 359d218
Change cql create subcommand, only accept metainfo json string as par…
laodouya ad0bb8f
Update licence in code.
laodouya 577c112
Add help info while no command provide.
laodouya 4d6dd7e
Add help command to show sub command usage.
laodouya 7edd4a1
Merge branch 'develop' into feature/cql_refactor
90e35a8
Modify cql command help grammar.
laodouya 086d11c
Update cql README.
laodouya c2a8a90
Update cql README.
laodouya b468835
Update cql help description.
laodouya 1a9fa33
Make cql read password of master key from terminal as default.
laodouya b707682
Update test case with -no-password.
laodouya 8199f47
Remove -password in all usage line.
laodouya 99b5532
Remove [] in required params.
laodouya 75051ba
Exit with 0 if cql help has no errors.
laodouya 8ef09e1
Rename permission command to grant.
laodouya a02b689
Rename web command to explorer.
laodouya 4c5d3f8
Format cql help command tab
laodouya b5c005a
Fix cql explorer unit test.
laodouya 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,93 @@ | ||
| /* | ||
| * Copyright 2018-2019 The CovenantSQL Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package internal | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/CovenantSQL/CovenantSQL/sqlchain/adapter" | ||
| "github.com/CovenantSQL/CovenantSQL/utils" | ||
| ) | ||
|
|
||
| var ( | ||
| adapterAddr string // adapter listen addr | ||
|
|
||
| adapterHTTPServer *http.Server | ||
| ) | ||
|
|
||
| // CmdAdapter is cql adapter command entity. | ||
| var CmdAdapter = &Command{ | ||
laodouya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| UsageLine: "cql adapter [-config file] [-tmp-path path] [-bg-log-level level] address", | ||
| Short: "start a SQLChain adapter", | ||
| Long: ` | ||
| Adapter command serves a SQLChain adapter | ||
| e.g. | ||
| cql adapter 127.0.0.1:7784 | ||
| `, | ||
| } | ||
|
|
||
| func init() { | ||
| CmdAdapter.Run = runAdapter | ||
|
|
||
| addCommonFlags(CmdAdapter) | ||
| addBgServerFlag(CmdAdapter) | ||
| } | ||
|
|
||
| func startAdapterServer(adapterAddr string) func() { | ||
| adapterHTTPServer, err := adapter.NewHTTPAdapter(adapterAddr, configFile) | ||
| if err != nil { | ||
| ConsoleLog.WithError(err).Error("init adapter failed") | ||
| SetExitStatus(1) | ||
| return nil | ||
| } | ||
|
|
||
| if err = adapterHTTPServer.Serve(); err != nil { | ||
| ConsoleLog.WithError(err).Error("start adapter failed") | ||
| SetExitStatus(1) | ||
| return nil | ||
| } | ||
|
|
||
| ConsoleLog.Infof("adapter started on %s", adapterAddr) | ||
|
|
||
| return func() { | ||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
| defer cancel() | ||
| adapterHTTPServer.Shutdown(ctx) | ||
| ConsoleLog.Info("adapter stopped") | ||
| } | ||
| } | ||
|
|
||
| func runAdapter(cmd *Command, args []string) { | ||
| configInit() | ||
| bgServerInit() | ||
|
|
||
| if len(args) != 1 { | ||
| ConsoleLog.Error("Adapter command need listen address as param") | ||
| SetExitStatus(1) | ||
| return | ||
| } | ||
| adapterAddr = args[0] | ||
|
|
||
| cancelFunc := startAdapterServer(adapterAddr) | ||
| ExitIfErrors() | ||
| defer cancelFunc() | ||
|
|
||
| ConsoleLog.Printf("Ctrl + C to stop adapter server on %s\n", adapterAddr) | ||
| <-utils.WaitForExit() | ||
| } | ||
This file contains hidden or 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,90 @@ | ||
| /* | ||
| * Copyright 2018-2019 The CovenantSQL Authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package internal | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/CovenantSQL/CovenantSQL/client" | ||
| "github.com/CovenantSQL/CovenantSQL/types" | ||
| ) | ||
|
|
||
| var ( | ||
| tokenName string // get specific token's balance of current account | ||
| ) | ||
|
|
||
| // CmdBalance is cql balance command entity. | ||
| var CmdBalance = &Command{ | ||
laodouya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| UsageLine: "cql balance [-config file] [-token token_name]", | ||
| Short: "get the balance of current account", | ||
| Long: ` | ||
| Balance command can get CovenantSQL token balance of current account | ||
| e.g. | ||
| cql balance | ||
|
|
||
| cql balance -token Particle | ||
| `, | ||
| } | ||
|
|
||
| func init() { | ||
| CmdBalance.Run = runBalance | ||
|
|
||
| addCommonFlags(CmdBalance) | ||
| CmdBalance.Flag.StringVar(&tokenName, "token", "", "Get specific token's balance of current account, e.g. Particle, Wave, and etc.") | ||
| } | ||
|
|
||
| func runBalance(cmd *Command, args []string) { | ||
| configInit() | ||
|
|
||
| var err error | ||
| if tokenName == "" { | ||
| var stableCoinBalance, covenantCoinBalance uint64 | ||
|
|
||
| if stableCoinBalance, err = client.GetTokenBalance(types.Particle); err != nil { | ||
| ConsoleLog.WithError(err).Error("get Particle balance failed") | ||
| SetExitStatus(1) | ||
| return | ||
| } | ||
| if covenantCoinBalance, err = client.GetTokenBalance(types.Wave); err != nil { | ||
| ConsoleLog.WithError(err).Error("get Wave balance failed") | ||
| SetExitStatus(1) | ||
| return | ||
| } | ||
|
|
||
| ConsoleLog.Infof("Particle balance is: %d", stableCoinBalance) | ||
| ConsoleLog.Infof("Wave balance is: %d", covenantCoinBalance) | ||
| } else { | ||
| var tokenBalance uint64 | ||
| tokenType := types.FromString(tokenName) | ||
| if !tokenType.Listed() { | ||
| values := make([]string, len(types.TokenList)) | ||
| for i := types.Particle; i < types.SupportTokenNumber; i++ { | ||
| values[i] = types.TokenList[i] | ||
| } | ||
| ConsoleLog.Errorf("no such token supporting in CovenantSQL (what we support: %s)", | ||
| strings.Join(values, ", ")) | ||
| SetExitStatus(1) | ||
| return | ||
| } | ||
| if tokenBalance, err = client.GetTokenBalance(tokenType); err != nil { | ||
| ConsoleLog.WithError(err).Error("get token balance failed") | ||
| SetExitStatus(1) | ||
| return | ||
| } | ||
| ConsoleLog.Infof("%s balance is: %d", tokenType.String(), tokenBalance) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.