Skip to content

Commit

Permalink
fix python sdk document description (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Jun 19, 2020
1 parent ce73c0d commit 941a82c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 37 deletions.
93 changes: 65 additions & 28 deletions docs/sdk/python_sdk/configuration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 配置说明

`client_config.py`是Python SDK的配置文件,主要包括**通用配置****群组配置****通信配置****证书配置**
`client_config.py`是Python SDK的配置文件,主要包括**SDK算法类型配置****通用配置****账户配置****群组配置****通信配置****证书配置**

```eval_rst
.. note::
Expand All @@ -10,14 +10,28 @@
- 日志配置参见 ``client/clientlogger.py`` ,默认在 ``bin/logs`` 目录下生成日志,默认级别为DEBUG
```

## SDK算法类型配置

- **crypto_type**: SDK接口类型,目前支持国密接口(`GM`)和非国密接口(`ECDSA`)

## 通用配置

- **contract_info_file**: 保存已部署合约信息的文件,默认为`bin/contract.ini`
- **account_keyfile_path**: 存放keystore文件的目录,默认为`bin/accounts`
- **account_keyfile**: keystore文件路径,默认为`pyaccount.keystore`
- **account_password**:keystore文件存储口令,默认为`123456`
- **logdir**:默认日志输出目录,默认为`bin/logs`

## 账户配置

**非国密账户的配置如下:**

- **account_keyfile**: 存储非国密账号信息的keystore文件路径, 默认为`pyaccount.keystore`
- **account_password**: 非国密keystore文件的存储口令,默认为`123456`

**国密账户的配置如下:**
- **gm_account_keyfile**: 存储国密账号信息的加密文件路径, 默认为`gm_account.json`
- **gm_account_password**: 国密账户文件的存储口令,默认为`123456`


## 群组配置

群组配置主要包括链ID和群组ID:
Expand All @@ -42,40 +56,63 @@

Python SDK支持使用配置的solc和solcjs编译器自动编译合约,同时配置solc和solcjs时,选择性能较高的solc编译器,编译选项如下:

- **solc_path**:solc编译器路径
- **solcjs_path**:solcjs编译脚本路径,为`./solc.js`
- **solc_path**:非国密solc编译器路径

- **gm_solc_path**: 国密编译器路径

- **solcjs_path**:solcjs编译脚本路径,为`./solc.js`


## 配置项示例

**配置项示例如下**

```python
class client_config:
#类成员变量,便于用.调用和区分命名空间
PROTOCOL_RPC="rpc" #const,dont change this
PROTOCOL_CHANNEL="channel" #const,dont change this
#--------------------------------------
"""
类成员常量和变量,便于用.调用和区分命名空间
"""
# keyword used to represent the RPC Protocol
PROTOCOL_RPC = "rpc"
# keyword used to represent the Channel Protocol
PROTOCOL_CHANNEL = "channel"

# ---------crypto_type config--------------
# crypto_type : 大小写不敏感:"GM" for 国密, "ECDSA" 或其他是椭圆曲线默认实现。
crypto_type = "ECDSA"
crypto_type = crypto_type.upper()
set_crypto_type(crypto_type) # 使密码算法模式全局生效,切勿删除此行

# --------------------------------------
# configure below
contract_info_file="bin/contract.ini" #保存已部署合约信息的文件
account_keyfile_path="bin/accounts" #保存keystore文件的路径,在此路径下,keystore文件以 [name].keystore命名
account_keyfile ="pyaccount.keystore"
account_password ="123456" #实际使用时建议改为复杂密码
fiscoChainId=1 #链ID,和要通信的节点*必须*一致
groupid = 1 #群组ID,和要通信的节点*必须*一致,如和其他群组通信,修改这一项,或者设置bcosclient.py里对应的成员变量
logdir="bin/logs" #默认日志输出目录,该目录必须先建立
#---------client communication config--------------
# ---------client communication config--------------
client_protocol = "channel" # or PROTOCOL_CHANNEL to use channel prototol
#client_protocol = PROTOCOL_CHANNEL
remote_rpcurl = "http://127.0.0.1:8545" # 采用rpc通信时,节点的rpc端口,和要通信的节点*必须*一致,**如采用channel协议通信,这里可以留空**
channel_host="127.0.0.1" #采用channel通信时,节点的channel ip地址,**如采用rpc协议通信,这里可以留空**
channel_port=20200 ##节点的channel 端口,**如采用rpc协议通信,这里可以留空**
channel_ca="bin/ca.crt" #采用channel协议时,需要设置链证书,**如采用rpc协议通信,这里可以留空**
channel_node_cert="bin/sdk.crt" # 采用channel协议时,需要设置sdk证书,如采用rpc协议通信,这里可以留空
channel_node_key="bin/sdk.key" # 采用channel协议时,需要设置sdk私钥,如采用rpc协议通信,这里可以留空
# client_protocol = PROTOCOL_CHANNEL
remote_rpcurl = "http://127.0.0.1:8545" # 采用rpc通信时,节点的rpc端口,和要通信的节点*必须*一致,如采用channel协议通信,这里可以留空
channel_host = "127.0.0.1" # 采用channel通信时,节点的channel ip地址,如采用rpc协议通信,这里可以留空
channel_port = 20200 # 节点的channel 端口,如采用rpc协议通信,这里可以留空
channel_ca = "bin/ca.crt" # 采用channel协议时,需要设置链证书,如采用rpc协议通信,这里可以留空
channel_node_cert = "bin/sdk.crt" # 采用channel协议时,需要设置sdk证书,如采用rpc协议通信,这里可以留空
channel_node_key = "bin/sdk.key" # 采用channel协议时,需要设置sdk私钥,如采用rpc协议通信,这里可以留空
fiscoChainId = 1 # 链ID,和要通信的节点*必须*一致
groupid = 1 # 群组ID,和要通信的节点*必须*一致,如和其他群组通信,修改这一项,或者设置bcosclient.py里对应的成员变量

# ---------account &keyfile config--------------
# 注意账号部分,国密和ECDSA采用不同的配置
contract_info_file = "bin/contract.ini" # 保存已部署合约信息的文件
account_keyfile_path = "bin/accounts" # 保存keystore文件的路径,在此路径下,keystore文件以 [name].keystore命名
account_keyfile = "pyaccount.keystore"
account_password = "123456" # 实际使用时建议改为复杂密码
gm_account_keyfile = "gm_account.json" # 国密账号的存储文件,可以加密存储,如果留空则不加载gm_account_password = "123456"
gm_account_password = "123456"
# ---------console mode, support user input--------------
background = True
# ---------compiler related--------------
# path of solc compiler
solc_path = os.environ["HOME"] + "/.py-solc/solc-v0.4.25/bin/solc"

# ---------runtime related--------------
# 非国密编译器路径
solc_path = "./bin/solc/v0.4.25/solc"
# 国密编译器路径
gm_solc_path = "./bin/solc/v0.4.25/solc-gm"
solcjs_path = "./solcjs"

logdir = "bin/logs" # 默认日志输出目录,该目录必须先建立
```
11 changes: 2 additions & 9 deletions docs/sdk/python_sdk/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- **Ubuntu**: `sudo apt install -y zlib1g-dev libffi6 libffi-dev wget git`
- **CentOS**`sudo yum install -y zlib-devel libffi-devel wget git`
- **MacOs**: `brew install wget npm git`
- **MacOs**: `brew install wget git`

**Python环境要求**

Expand Down Expand Up @@ -112,17 +112,10 @@ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
```bash
# 该脚本执行操作如下:
# 1. 拷贝client_config.py.template->client_config.py
# 2. 安装solc编译器
# 2. 下载solc编译器
bash init_env.sh -i
```

**若MacOS环境solc安装较慢,可在python-sdk目录下执行如下命令安装solcjs**,python-sdk自动从该路径加载nodejs编译器:

```bash
# 安装编译器
npm install solc@v0.4.25
```

若没有执行以上初始化步骤,需要将`contracts/`目录下的`sol`代码手动编译成`bin``abi`文件并放置于`contracts`目录,才可以部署和调用相应合约。合约编译可以使用[remix](https://remix.ethereum.org)


Expand Down

0 comments on commit 941a82c

Please sign in to comment.