diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a58a65178..6e2ac112c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: covenantsql/build variables: - REVIEWDOG_VERSION: 0.9.9 + REVIEWDOG_VERSION: 0.9.11 REVIEWDOG_GITLAB_API_TOKEN: $REVIEWDOG_TOKEN CODECOV_TOKEN: $CODECOV_TOKEN @@ -13,21 +13,24 @@ before_script: # - go get github.com/haya14busa/goverage # - go get github.com/golang/lint/golint # - go get github.com/haya14busa/reviewdog/cmd/reviewdog - - go get github.com/wadey/gocovmerge - - mkdir -p $GOPATH/src/github.com/ - - cp -r /builds/CovenantSQL $GOPATH/src/github.com/ +# - go get github.com/wadey/gocovmerge + - mkdir -p $GOPATH/src/github.com/CovenantSQL + - cp -r /builds/thunderdb/CovenantSQL $GOPATH/src/github.com/CovenantSQL/ - cd $GOPATH/src/github.com/CovenantSQL/CovenantSQL # - dep ensure - mkdir -p ~/bin/ && export PATH="~/bin/:$PATH" + - ulimit -n 8192 # - curl -fSL https://github.com/haya14busa/reviewdog/releases/download/$REVIEWDOG_VERSION/reviewdog_linux_amd64 -o ~/bin/reviewdog && chmod +x ~/bin/reviewdog test-my-project: stage: test script: - - bash build.sh - - go test -v -race $(go list ./... | grep -v "/vendor/") -coverprofile cover.out - - gocovmerge cover.out $(find cmd -name "*.cover.out") > coverage.txt && rm -f cover.out + - bash -x build.sh + - go test -v -race -failfast -parallel 16 -cpu 16 $(go list ./... | grep -v "/vendor/") -coverprofile cover.out + - cd rpc && go test -test.bench ^BenchmarkPersistentCaller_Call$ -test.run ^$ && cd - + - bash cleanupDB.sh || true + - cd cmd/cql-minerd && go test -bench=^BenchmarkMinerTwo$ -benchtime=5s -run ^$ && cd - + - gocovmerge cover.out $(find cmd -name "*.cover.out") | grep -F -v '_gen.go' > coverage.txt && rm -f cover.out - bash <(curl -s https://codecov.io/bash) - >- - golint ./... | grep -v 'vendor/' | grep -v 'server/' | grep -v 'utils/' | reviewdog -f=golint -reporter=github-mr-commit || true - + golint ./... | grep -v 'vendor/' | grep -v 'server/' | grep -v 'utils/' | reviewdog -f=golint -reporter=github-pr-review || true diff --git a/client/README-zh.md b/client/README-zh.md new file mode 100644 index 000000000..1a7dd7401 --- /dev/null +++ b/client/README-zh.md @@ -0,0 +1,103 @@ +本文档介绍 CovenantSQL 客户端的使用方式。客户端用来创建、查询、更新和删除 SQLChain 以及绑定的数据库。 + +## 开始之前 + +确保 `$GOPATH/bin` 目录在环境变量 `$PATH` 中,执行以下命令 + +```bash +$ go get github.com/CovenantSQL/CovenantSQL/client +$ go get github.com/CovenantSQL/CovenantSQL/cmd/cql-utils +``` + +然后在你的 go 代码中 import 第一个 `client` 包。 + + +## 初始化一个 CovenantSQL 客户端 + +首先需要一个 config 文件和 master key 来初始化。master key 用来加密解密本地密钥对。以下是如何用一个自定义 master key 来生成默认的 config 文件: + +### 生成默认的配置文件 + +运行以下 `cql-utils` 命令,输入 master key(类似密码)来生成本地密钥对。等待几十秒,会在 `conf` 文件夹中,生成一个私钥文件和一个名为 `config.yaml` 的配置文件。 + +```bash +$ cql-utils -tool confgen -root conf +Generating key pair... +Enter master key(press Enter for default: ""): +⏎ +Private key file: conf/private.key +Public key's hex: 025abec9b0072615170f4acf4a2fa1162a13864bb66bc3f140b29f6bf50ceafc75 +Generated key pair. +Generating nonce... +INFO[0005] cpu: 1 +INFO[0005] position: 0, shift: 0x0, i: 0 +nonce: {{1450338416 0 0 0} 26 0000002dd8bdb50ba0270642e4c4bc593c1630ef7784653f311b3c3d6374e514} +node id: 0000002dd8bdb50ba0270642e4c4bc593c1630ef7784653f311b3c3d6374e514 +Generated nonce. +Generating config file... +Generated nonce. +``` + +有了配置文件之后,可以通过以下 go 代码来初始化 CovenantSQL 客户端: + +```go +client.Init(configFile, masterKey) +``` + +## 客户端使用方式 + +### 创建一个 SQLChain 数据库 + +创建 SQLChain 数据库需要指明需要几个节点(nodeCount变量): + +```go +var ( + dsn string + meta client.ResourceMeta +) +meta.Node = uint16(nodeCount) +dsn, err = client.Create(meta) +// process err +``` +创建完毕会返回一个 dsn 字符串,用来访问这个数据库。 + +### 查询和执行 + +拿到 dsn 字符串后,可以通过以下代码在 SQLChain 中执行 SQL 语句: + +```go + + db, err := sql.Open("covenantsql", dsn) + // process err + + _, err = db.Exec("CREATE TABLE testSimple ( column int );") + // process err + + _, err = db.Exec("INSERT INTO testSimple VALUES(?);", 42) + // process err + + row := db.QueryRow("SELECT column FROM testSimple LIMIT 1;") + + var result int + err = row.Scan(&result) + // process err + fmt.Printf("SELECT column FROM testSimple LIMIT 1; result %d\n", result) + + err = db.Close() + // process err + +``` +用法和其他 go sql driver 一致。 + +### 删除数据库 + +使用 dsn 来删除数据库: + +```go + err = client.Drop(dsn) + // process err +``` + +### 完整示例 + +在以下目录中有一个简单示例和复杂示例可以参考 [示例](https://github.com/CovenantSQL/CovenantSQL/tree/develop/client/_example) \ No newline at end of file diff --git a/client/README.md b/client/README.md index f3e048bf8..ba53a074a 100644 --- a/client/README.md +++ b/client/README.md @@ -1,4 +1,4 @@ -This doc introduce the usage of covenantSQL client. Client is used for creating, querying, updating, and deleting the SQLChain and database adhere to the SQLChain. +This doc introduce the usage of CovenantSQL client. Client is used for creating, querying, updating, and deleting the SQLChain and database adhere to the SQLChain. ## Prerequisites @@ -100,4 +100,4 @@ Drop your database on SQL Chain is very easy with your dsn string: ### Full Example -simple and complex client examples can be found in [client/_example](_example/) \ No newline at end of file +simple and complex client examples can be found in [client/_example](_example/) diff --git a/cmd/cql-utils/README-zh.md b/cmd/cql-utils/README-zh.md new file mode 100644 index 000000000..cb36fd688 --- /dev/null +++ b/cmd/cql-utils/README-zh.md @@ -0,0 +1,34 @@ +cql-utils 是 CovenantSQL 的一个命令行工具,具体用法如下。 + +## 安装 +下载 [最新发布版本](https://github.com/CovenantSQL/CovenantSQL/releases) 或直接从源码编译: +```bash +$ go get github.com/CovenantSQL/CovenantSQL/cmd/cql-utils +``` +*保证 Golang 环境变量 `$GOPATH/bin` 已在 `$PATH` 中* + +## 使用 +### 生成公私钥对 + +``` +$ cql-utils -tool keygen +Enter master key(press Enter for default: ""): +⏎ +Private key file: private.key +Public key's hex: 03bc9e90e3301a2f5ae52bfa1f9e033cde81b6b6e7188b11831562bf5847bff4c0 +``` + +生成的 private.key 文件即是使用主密码加密过的私钥文件,而输出到屏幕上的字符串就是使用十六进制进行编码的公钥。 + +### 使用私钥文件或公钥生成钱包地址 + +``` +$ cql-utils -tool addrgen -private private.key +Enter master key(default: ""): +⏎ +wallet address: 4jXvNvPHKNPU8Sncz5u5F5WSGcgXmzC1g8RuAXTCJzLsbF9Dsf9 +$ cql-utils -tool addrgen -public 02f2707c1c6955a9019cd9d02ade37b931fbfa286a1163dfc1de965ec01a5c4ff8 +wallet address: 4jXvNvPHKNPU8Sncz5u5F5WSGcgXmzC1g8RuAXTCJzLsbF9Dsf9 +``` + +你可以通过指定私钥文件,或者把上述的公钥十六进制编码字符串作为命令行参数来直接生成钱包地址。 \ No newline at end of file diff --git a/cmd/cql/README-zh.md b/cmd/cql/README-zh.md new file mode 100644 index 000000000..b4ca69a3a --- /dev/null +++ b/cmd/cql/README-zh.md @@ -0,0 +1,67 @@ +本文档主要介绍 CovenantSQL 命令行客户端 `cql` 的使用。`cql` 是一个用于批量进行 SQLChain 上数据库的创建、查询、更新或删除操作的命令行工具。 + +## 安装 +下载 [最新发布版本](https://github.com/CovenantSQL/CovenantSQL/releases) 或直接从源码编译: + +```bash +$ go get github.com/CovenantSQL/CovenantSQL/client +$ go get github.com/CovenantSQL/CovenantSQL/cmd/cql +``` +*保证 Golang 环境变量 `$GOPATH/bin` 已在 `$PATH` 中* + +## 生成默认配置文件 + +首先需要一个 config 文件和由你输入的主密码(master key)来初始化,其中主密码用来加密解密本地密钥对。使用 `cql-utils` 工具进行配置文件生成后,你可以在生成的配置文件目录下找到密钥文件。 + +具体请参考: [cql-utils 使用文档](https://github.com/CovenantSQL/docs/blob/master/docs/development-cmd-cql-utils-zh.md#使用) 中配置文件及钱包地址生成相关章节。 + +## 检查钱包余额 + +使用 `cql` 命令来检查钱包余额: +```bash +$ cql -config conf/config.yaml -get-balance +INFO[0000] +### Public Key ### +0388954cf083bb6bb2b9c7248849b57c76326296fcc0d69764fc61eedb5b8d820c +### Public Key ### + caller="privatekeystore.go:116 crypto/kms.InitLocalKeyPair" +INFO[0000] stable coin balance is: 100 caller="main.go:246 main.main" +INFO[0000] covenant coin balance is: 0 caller="main.go:247 main.main" +``` +这里我们得到结果 **"stable coin balance is: 100"**。 + +## 初始化一个 CovenantSQL 数据库 + +准备好配置文件和主密码后就可以使用 `cql` 命令来创建数据库了,你的数据库 ID 将会输出到屏幕上: + +```bash +# if a non-default password applied on master key, use `-password` to pass it +$ cql -config conf/config.yaml -create 1 +INFO[0000] +### Public Key ### +039bc931161383c994ab9b81e95ddc1494b0efeb1cb735bb91e1043a1d6b98ebfd +### Public Key ### + caller="privatekeystore.go:116 crypto/kms.InitLocalKeyPair" +INFO[0000] the newly created database is: covenantsql://0e9103318821b027f35b96c4fd5562683543276b72c488966d616bfe0fe4d213 caller="main.go:297 main.main" +``` + +这里 `-create 1` 表示创建一个单节点的 SQLChain。 + +```bash +$ cql -config conf/config.yaml -dsn covenantsql://address +``` +`address` 就是你的数据库 ID。 + +`cql` 命令的详细使用帮助如下: + +```bash +$ cql -help +``` + +## 使用 `cql` + +现在可以使用 `cql` 进行数据库操作了: + +```bash +co:address=> show tables; +```