Skip to content

Commit

Permalink
move to v3 dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust committed Dec 25, 2023
1 parent e6e3eda commit 76ab114
Show file tree
Hide file tree
Showing 153 changed files with 1,280 additions and 2,145 deletions.
6 changes: 3 additions & 3 deletions .ci/ethPrecompiled/bn256.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .ci/ethPrecompiled/bn256_gm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .ci/generate_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

GOPATH_BIN=$(go env GOPATH)/bin

c_sdk_version="v3.4.0"
c_sdk_version="v3.5.0"

LOG_ERROR() {
content=${1}
Expand Down Expand Up @@ -32,6 +32,7 @@ get_csdk_lib()
}

calculate_coverage() {
cd ./v3
# start blockchain demo
# latest_version=$(curl -sS https://gitee.com/api/v5/repos/FISCO-BCOS/FISCO-BCOS/tags | grep -oe "\"name\":\"v[3-9]*\.[0-9]*\.[0-9]*\"" | cut -d \" -f 4 | sort -V | tail -n 1)
# latest_version=$(curl --insecure -s https://api.github.com/repos/FISCO-BCOS/FISCO-BCOS/releases | grep "tag_name" | grep "\"v3\.[0-9]*\.[0-9]*\"" | cut -d \" -f 4 | sort -V | tail -n 1)
Expand Down
6 changes: 3 additions & 3 deletions .ci/hello/HelloWorld.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions .ci/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ compile_and_ut()
{
export GO111MODULE="on"
# execute_cmd "go get github.com/sirupsen/[email protected]"
execute_cmd "go build cmd/console.go"
execute_cmd "go build ./cmd/console.go"
pwd
execute_cmd "go build -o abigen ./cmd/abigen/main.go"

execute_cmd "go test -v ./smcrypto"
}

Expand Down Expand Up @@ -331,7 +331,7 @@ precompiled_test(){
integration_std()
{
LOG_INFO "integration_std testing..."
execute_cmd "bash tools/download_solc.sh -v 0.8.11"
execute_cmd "bash ../tools/download_solc.sh -v 0.8.11"

head build_chain.sh
bash build_chain.sh -l 127.0.0.1:2 -o nodes -a 0x83309d045a19c44dc3722d15a6abd472f95866ac
Expand All @@ -342,11 +342,11 @@ integration_std()
cp nodes/127.0.0.1/sdk/* ./client/

# abigen std
execute_cmd "./solc-0.8.11 --bin --abi --optimize -o .ci/hello .ci/hello/HelloWorld.sol"
execute_cmd "./abigen --bin .ci/hello/HelloWorld.bin --abi .ci/hello/HelloWorld.abi --type Hello --pkg main --out=hello.go"
execute_cmd "./solc-0.8.11 --bin --abi --optimize -o ../.ci/hello ../.ci/hello/HelloWorld.sol"
execute_cmd "./abigen --bin ../.ci/hello/HelloWorld.bin --abi ../.ci/hello/HelloWorld.abi --type Hello --pkg main --out=hello.go"
generate_hello Hello hello.go
execute_cmd "go build ${ldflags} -o hello hello.go"
execute_cmd "go build ${ldflags} -o bn256 .ci/ethPrecompiled/bn256.go"
execute_cmd "go build ${ldflags} -o bn256 ../.ci/ethPrecompiled/bn256.go"
LOG_INFO "generate hello.go and build hello done."

precompiled_test
Expand All @@ -357,8 +357,8 @@ integration_std()
if [ ! -z "$(cat hello.out | grep failed)" ];then LOG_ERROR "call hello failed." && cat hello.out && exit 1;fi
# if [ ! -z "$(./bn256 | grep failed)" ];then ./bn256 && LOG_ERROR "call bn256 failed." && exit 1;fi

execute_cmd "./solc-0.8.11 --bin --abi --optimize -o .ci/counter .ci/counter/Counter.sol"
execute_cmd "./abigen --bin .ci/counter/Counter.bin --abi .ci/counter/Counter.abi --type Counter --pkg main --out=counter.go"
execute_cmd "./solc-0.8.11 --bin --abi --optimize -o ../.ci/counter ../.ci/counter/Counter.sol"
execute_cmd "./abigen --bin ../.ci/counter/Counter.bin --abi ../.ci/counter/Counter.abi --type Counter --pkg main --out=counter.go"
generate_counter Counter counter.go
execute_cmd "go build ${ldflags} -o counter counter.go"
if [ -z "$(./counter | grep address)" ];then LOG_ERROR "std deploy contract failed." && exit 1;fi
Expand All @@ -374,7 +374,7 @@ integration_std()
integration_gm()
{
LOG_INFO "integration_gm testing..."
execute_cmd "bash tools/download_solc.sh -v 0.8.11 -g"
execute_cmd "bash ../tools/download_solc.sh -v 0.8.11 -g"

bash build_chain.sh -l 127.0.0.1:2 -s -o nodes_gm -a 0x791a0073e6dfd9dc5e5061aebc43ab4f7aa4ae8b
cp -r nodes_gm/127.0.0.1/sdk/* ./conf/
Expand All @@ -385,11 +385,11 @@ integration_gm()
cp nodes/127.0.0.1/sdk/* ./client/

# abigen gm
execute_cmd "./solc-0.8.11-gm --bin --abi --overwrite -o .ci/hello .ci/hello/HelloWorld.sol"
execute_cmd "./abigen --bin .ci/hello/HelloWorld.bin --abi .ci/hello/HelloWorld.abi --type Hello --pkg main --out=hello_gm.go --smcrypto=true"
execute_cmd "./solc-0.8.11-gm --bin --abi --overwrite -o ../.ci/hello ../.ci/hello/HelloWorld.sol"
execute_cmd "./abigen --bin ../.ci/hello/HelloWorld.bin --abi ../.ci/hello/HelloWorld.abi --type Hello --pkg main --out=hello_gm.go --smcrypto=true"
generate_hello_gm Hello hello_gm.go
execute_cmd "go build ${ldflags} -o hello_gm hello_gm.go"
execute_cmd "go build ${ldflags} -o bn256_gm .ci/ethPrecompiled/bn256_gm.go"
execute_cmd "go build ${ldflags} -o bn256_gm ../.ci/ethPrecompiled/bn256_gm.go"
LOG_INFO "generate hello_gm.go and build hello_gm done."

if [ -z "$(./hello_gm | grep address)" ];then LOG_ERROR "gm deploy contract failed." && exit 1;fi
Expand Down Expand Up @@ -439,6 +439,7 @@ parse_params()

main()
{
cd ./v3
check_env
get_csdk_lib
get_build_chain
Expand Down
6 changes: 3 additions & 3 deletions .ci/store/Store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.so
*.dylib
log/*
clog.ini

# Test binary, built with `go test -c`
*.test
Expand All @@ -20,6 +21,7 @@ log/*

# Go workspace file
go.work
go.work.sum

# cmd
main
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FISCO BCOS Go语言版本的SDK,主要实现的功能有:

master分支的go-sdk对应FISCO-BCOS v3版本,如果使用的是FISCO-BCOS v2版本,请切换到[FISCO-BCOS v2分支](https://github.com/FISCO-BCOS/go-sdk/tree/master-FISCO-BCOS-v2)[对应文档](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/go_sdk/index.html)

- [Golang](https://golang.org/), 版本需不低于`1.17`,本项目采用`go module`进行包管理。具体可查阅[Using Go Modules](https://blog.golang.org/using-go-modules)
- [Golang](https://golang.org/), 版本需不低于`1.21`,本项目采用`go module`进行包管理。具体可查阅[Using Go Modules](https://blog.golang.org/using-go-modules)
- [FISCO BCOS 3.2.0+](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/index.html), 可参考[安装搭建](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/quick_start/air_installation.html)
- Solidity编译器,默认0.8.11版本

Expand Down Expand Up @@ -56,13 +56,13 @@ type Config struct {
- GroupID:账本的`GroupID`
- Host:节点IP
- Port:节点RPC端口
- DisableSsl:使用TLS加密时为`false`,不使用TLS加密时为`true`
- DisableSsl:使用TLS加密时为`false`,不使用TLS加密时为`true`,此配置项需与节点config.ini中的`rpc.disable_ssl`保持一致

## 控制台使用

1. 搭建FISCO BCOS 3.2以上版本节点,请[参考这里](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/quick_start/air_installation.html)
1. 请拷贝对应的SDK证书到conf文件夹,证书名为`ca.crt/sdk.key/sdk.crt`,国密时证书名为`sm_ca.crt/sm_sdk.key/sm_sdk.crt/sm_ensdk.key/sm_ensdk.crt`
1. go-sdk需要依赖csdk的动态库,[下载地址](https://github.com/FISCO-BCOS/bcos-c-sdk/releases/tag/v3.4.0),将动态库放在`/usr/local/lib`目录下。在其他机器使用时也需要通过`export LD_LIBRARY_PATH=${PWD}/lib`设置动态库的搜索路径,其中`${PWD}/lib`需替换为bcos-c-sdk的动态库所在文件夹。如果编译后在其他机器运行,也可以在编译时使用`-ldflags`指定动态库搜索路径,如`go build -ldflags="-r ${PWD}/lib"`
1. go-sdk需要依赖csdk的动态库,[下载地址](https://github.com/FISCO-BCOS/bcos-c-sdk/releases/tag/v3.5.0),将动态库放在`/usr/local/lib`目录下。在其他机器使用时也需要通过`export LD_LIBRARY_PATH=${PWD}/lib`设置动态库的搜索路径,其中`${PWD}/lib`需替换为bcos-c-sdk的动态库所在文件夹。如果编译后在其他机器运行,也可以在编译时使用`-ldflags`指定动态库搜索路径,如`go build -ldflags="-r ${PWD}/lib"`

```bash
# 下面的脚本帮助用户下载bcos-c-sdk的动态库到/usr/local/lib目录下
Expand All @@ -76,7 +76,8 @@ type Config struct {
git clone https://github.com/FISCO-BCOS/go-sdk.git
cd go-sdk
go mod tidy
go build -ldflags="-r /usr/local/lib" -o console cmd/console.go
cd v3
go build -ldflags="-r /usr/local/lib" -o console ./cmd/console.go
./console help
```

Expand All @@ -85,7 +86,7 @@ go build -ldflags="-r /usr/local/lib" -o console cmd/console.go
以下的示例是通过`import`的方式来使用`go-sdk`,如引入RPC控制台库:

```go
import "github.com/FISCO-BCOS/go-sdk/client"
import "github.com/FISCO-BCOS/go-sdk/v3/client"
```

### Solidity合约编译为Go文件
Expand Down Expand Up @@ -141,6 +142,7 @@ bash tools/download_solc.sh -v 0.8.11

```bash
# 下面指令在go-sdk目录下操作,编译生成abigen工具
cd v3
go build ./cmd/abigen
```

Expand Down Expand Up @@ -196,8 +198,8 @@ import (
"fmt"
"log"

"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/core/types"
"github.com/FISCO-BCOS/go-sdk/v3/client"
"github.com/FISCO-BCOS/go-sdk/v3/types"
"github.com/FISCO-BCOS/go-sdk/hello"
)

Expand Down
Loading

0 comments on commit 76ab114

Please sign in to comment.