Skip to content
Merged
Show file tree
Hide file tree
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 Mar 7, 2019
b5a8bfe
Split cql command func into internal package
laodouya Mar 14, 2019
4a08673
Move log and waitTxConfirmationMaxDuration to internal vars.
laodouya Mar 14, 2019
b5e0875
Fix UsqlRegister should not use outside variable.
laodouya Mar 14, 2019
60a6806
Move cql console funcs to internal/command
laodouya Mar 14, 2019
32718ec
Refactor interactive usql feature into console command.
laodouya Mar 14, 2019
c9735f1
Refactor version print into version command.
laodouya Mar 15, 2019
d186072
Refactor token balance check funcs into balance command.
laodouya Mar 15, 2019
2f59c1d
Refactor createDB feature into create command.
laodouya Mar 15, 2019
dc4fa1a
Refactor dropDB feature into drop command.
laodouya Mar 15, 2019
292137c
Fail while cql drop command could not wait tx confirm.
laodouya Mar 15, 2019
8513210
Refactor updatePermission feature into permission command.
laodouya Mar 15, 2019
eb6f562
Refactor transferToken feature into transfer command.
laodouya Mar 15, 2019
93b77dd
Move ConsoleLog init into package.
laodouya Mar 15, 2019
bbef278
Refactor explorer feature into cql web command.
laodouya Mar 16, 2019
b49fee4
Refactor adapter feature into cql adapter command.
laodouya Mar 16, 2019
3a04bf7
Add new line after one console output.
laodouya Mar 17, 2019
f7af2a4
Change web and adapter start process into a func.
laodouya Mar 17, 2019
29bd64b
Add web and adapter params for console command.
laodouya Mar 17, 2019
70ec1fa
Make golint happy.
laodouya Mar 18, 2019
2c5d31c
Fix cql test case.
laodouya Mar 18, 2019
d3b14b7
Fix old client compatibility test.
laodouya Mar 18, 2019
dcad0f4
Fix unit test: cql.test should set -test.coverprofile flag first befo…
laodouya Mar 18, 2019
159e0ff
Fix compatibility test.
laodouya Mar 18, 2019
359d218
Change cql create subcommand, only accept metainfo json string as par…
laodouya Mar 18, 2019
ad0bb8f
Update licence in code.
laodouya Mar 18, 2019
577c112
Add help info while no command provide.
laodouya Mar 18, 2019
4d6dd7e
Add help command to show sub command usage.
laodouya Mar 18, 2019
7edd4a1
Merge branch 'develop' into feature/cql_refactor
Mar 18, 2019
90e35a8
Modify cql command help grammar.
laodouya Mar 19, 2019
086d11c
Update cql README.
laodouya Mar 19, 2019
c2a8a90
Update cql README.
laodouya Mar 19, 2019
b468835
Update cql help description.
laodouya Mar 19, 2019
1a9fa33
Make cql read password of master key from terminal as default.
laodouya Mar 20, 2019
b707682
Update test case with -no-password.
laodouya Mar 20, 2019
8199f47
Remove -password in all usage line.
laodouya Mar 20, 2019
99b5532
Remove [] in required params.
laodouya Mar 20, 2019
75051ba
Exit with 0 if cql help has no errors.
laodouya Mar 20, 2019
8ef09e1
Rename permission command to grant.
laodouya Mar 20, 2019
a02b689
Rename web command to explorer.
laodouya Mar 20, 2019
4c5d3f8
Format cql help command tab
laodouya Mar 20, 2019
b5c005a
Fix cql explorer unit test.
laodouya Mar 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/docker-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ blockproducer)
exec /app/cqld -config "${COVENANT_CONF}" -metric-web "${METRIC_WEB_ADDR}" "${@}"
;;
observer)
exec /app/cql -config "${COVENANT_CONF}" -web "${COVENANTSQL_OBSERVER_ADDR}" "${@}"
exec /app/cql web -config "${COVENANT_CONF}" -no-password "${COVENANTSQL_OBSERVER_ADDR}" "${@}"
;;
adapter)
exec /app/cql -config "${COVENANT_CONF}" -adapter "${COVENANTSQL_ADAPTER_ADDR}" "${@}"
exec /app/cql adapter -config "${COVENANT_CONF}" -no-password "${COVENANTSQL_ADAPTER_ADDR}" "${@}"
;;
mysql-adapter)
exec /app/cql-mysql-adapter -config "${COVENANT_CONF}" "${@}"
;;
cli)
exec /app/cql -config ${COVENANT_CONF} "${@}"
exec /app/cql console -config ${COVENANT_CONF} -no-password "${@}"
;;
faucet)
exec /app/cql-faucet -config ${COVENANT_CONF} "${@}"
Expand Down
11 changes: 6 additions & 5 deletions cmd/cql/README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ $ go get github.com/CovenantSQL/CovenantSQL/cmd/cql
## 检查钱包余额

使用 `cql` 命令来检查钱包余额:

```bash
$ cql -get-balance
$ cql balance
INFO[0000]
### Public Key ###
0388954cf083bb6bb2b9c7248849b57c76326296fcc0d69764fc61eedb5b8d820c
Expand All @@ -36,7 +37,7 @@ INFO[0000] covenant coin balance is: 0 caller="main.go:247 mai

```bash
# if a non-default password applied on master key, use `-password` to pass it
$ cql -create 1
$ cql create '{"node":1}'
INFO[0000]
### Public Key ###
039bc931161383c994ab9b81e95ddc1494b0efeb1cb735bb91e1043a1d6b98ebfd
Expand All @@ -45,17 +46,17 @@ INFO[0000]
INFO[0000] the newly created database is: covenantsql://0e9103318821b027f35b96c4fd5562683543276b72c488966d616bfe0fe4d213 caller="main.go:297 main.main"
```

这里 `-create 1` 表示创建一个单节点的 SQLChain。
这里 `create '{"node":1}'` 表示创建一个单节点的 SQLChain。

```bash
$ cql -dsn covenantsql://address
$ cql console -dsn covenantsql://address
```
`address` 就是你的数据库 ID。

`cql` 命令的详细使用帮助如下:

```bash
$ cql -help
$ cql help
```

## 使用 `cql`
Expand Down
13 changes: 7 additions & 6 deletions cmd/cql/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This doc introduce the usage of CovenantSQL commandline client `cql`. `cql` is a command line interface for batch scripting used for creating, querying, updating, and deleting the SQLChain and database adhere to the SQLChain.
This doc introduces the usage of CovenantSQL command line client `cql`. `cql` is a command line interface for batch scripting used for creating, querying, updating, and deleting the SQLChain and database adhere to the SQLChain.

## Install
Download [Latest Release](https://github.com/CovenantSQL/CovenantSQL/releases) or build from src:
Expand All @@ -18,8 +18,9 @@ See: [cql-utils doc](https://github.com/CovenantSQL/CovenantSQL/tree/develop/cmd
## Check balance

Use `cql` to check your wallet balance:

```bash
$ cql -get-balance
$ cql balance
INFO[0000]
### Public Key ###
0388954cf083bb6bb2b9c7248849b57c76326296fcc0d69764fc61eedb5b8d820c
Expand All @@ -37,7 +38,7 @@ You can get a database id when create a new SQL Chain:

```bash
# if a non-default password applied on master key, use `-password` to pass it
$ cql -create 1
$ cql create '{"node":1}'
INFO[0000]
### Public Key ###
039bc931161383c994ab9b81e95ddc1494b0efeb1cb735bb91e1043a1d6b98ebfd
Expand All @@ -46,17 +47,17 @@ INFO[0000]
INFO[0000] the newly created database is: covenantsql://0e9103318821b027f35b96c4fd5562683543276b72c488966d616bfe0fe4d213 caller="main.go:297 main.main"
```

Here, `-create 1` refers that there is only one node in SQL Chain.
Here, `create '{"node":1}'` refers that there is only one node in SQL Chain.

```bash
$ cql -dsn covenantsql://address
$ cql console -dsn covenantsql://address
```
`address` is database id.

Show the complete usage of `cql`:

```bash
$ cql -help
$ cql help
```

## Use the `cql`
Expand Down
93 changes: 93 additions & 0 deletions cmd/cql/internal/adapter.go
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{
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()
}
90 changes: 90 additions & 0 deletions cmd/cql/internal/balance.go
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{
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)
}
}
Loading