err user key cannot be empty
【问题分类】
- bug
- P2P网络相关(包含libp2p,liquid)
- 链账户身份与权限相关(证书问题、public、多签投票问题)
- 核心交易引擎相关(交易池、DAG)
- 共识相关
- 智能合约相关
- 存储相关
- SDK相关
- 长安链CMC工具
- 长安链管理台
- 长安链浏览器
- 长安链合约IDE
- 长安链web签名插件
- 跨链相关
- 轻节点相关
- 隐私计算相关
- 密码学相关
- 环境依赖
- 其他补充:
【问题描述】(请对问题进行描述,方便定位问题)
使用goSDK用参数创建chainclient时出现错误
err1 user key cannot be empty
panic: runtime error: invalid memory address or nil pointer dereference
文件路径正确,重新使用sdk.WithUserKeyBytes(userkeyBytes),还是报错
func createClient(orgId string) (client *sdk.ChainClient, err error) {
userkeyBytes, _ := ioutil.ReadFile("/root/release/org001-某省某高校2/config/org001/certs/user/学籍管理/学籍管理.tls.key")
usercrtBytes, _ := ioutil.ReadFile("/root/release/org001-某省某高校2/config/org001/certs/user/学籍管理/学籍管理.tls.crt")
fmt.Println(fmt.Sprintf("%s", userkeyBytes))
println(usercrtBytes)
if node1 == nil {
node1 = createNode()
}
fmt.Println("created node ")
chainClient, err := sdk.NewChainClient(
sdk.WithChainClientOrgId(orgId),
sdk.WithChainClientChainId("chain01"),
// 设置客户端用户私钥路径
sdk.WithUserKeyFilePath("/root/release/org001-某省某高校2/config/org001/certs/user/学籍管理/学籍管理.tls.key"),
sdk.WithUserKeyBytes(userkeyBytes),
// 设置客户端用户证书
sdk.WithUserCrtFilePath("/root/release/org001-某省某高校2/config/org001/certs/user/学籍管理/学籍管理.tls.crt"),
sdk.WithUserCrtBytes(usercrtBytes),
// 添加节点1
sdk.AddChainClientNodeConfig(node1),
)
if err != nil {
return nil, err
}
//启用证书压缩(开启证书压缩可以减小交易包大小,提升处理性能)
err = chainClient.EnableCertHash()
if err != nil {
return nil, err
}
return chainClient, nil
}
【相关日志文件】(如果有报错日志请贴图,或者上传附件)
创建客户端失败,gosdk panic.log system.log无报错
(base) [root@localhost gosdk]# go run findbysid/main.go
-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgbH0vGMW18jG2BoHC
q2torpTVYYWmKWeaRY6XZLP4zQagCgYIKoEcz1UBgi2hRANCAAQWSzrNhlvS3Kbr
dQY9W8dZXlH2Qr/7yYa7KQF9XDzOqBSej4N5JfjDNjaRg2JIM5quVNFY4m4gLjX6
cHiZKdB4
-----END PRIVATE KEY-----
[916/917]0xc0002f5c00
created node
err1 user key cannot be empty
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x133ea36]
goroutine 1 [running]:
chainmaker.org/chainmaker/sdk-go/v2.(*ChainClient).QueryContract(0x0, 0x177bbbf, 0x7, 0x1785327, 0xf, 0xc00046c260, 0x2, 0x2, 0xffffffffffffffff, 0xc000056720, ...)
/root/.g/versions/1.16.15/gopath/pkg/mod/chainmaker.org/chainmaker/sdk-go/v2@v2.3.2/sdk_user_contract.go:227 +0x136
main.main()
/root/gosdk/findbysid/main.go:47 +0x26b
exit status 2
【系统信息】(请填写系统信息,方便定位问题)
- chainmaker-go version * : [v2.3.1]
- OS & version * : Linux version 4.19.91-26.an8.x86_64 (mockbuild@anolis-build-01.openanolis.cn) (gcc version 8.5.0 20210514 (Anolis 8.5.0-10.0.1) (GCC)) #1 SMP Tue May 24 13:10:09 CST 2022
- **docker镜像 version:2.3.1
- 管理台 version: 2.3.1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information