入参方式设置sdk客户端,请求合约失败
在如下代码中
package main
import (
"fmt"
"vava/logger"
"chainmaker.org/chainmaker/pb-go/v2/common"
"github.com/tendermint/tendermint/libs/os"
sdk "chainmaker.org/chainmaker/sdk-go/v2"
)
func main() {
ca, _ := os.ReadFile("user/ca/ca.crt")
key, _ := os.ReadFile("user/xlhuang.sign.key")
crt, _ := os.ReadFile("user/xlhuang.sign.crt")
node := sdk.NewNodeConfig(
sdk.WithNodeCACerts([]string{string(ca)}),
sdk.WithNodeAddr("172.26.2.97:9091"),
sdk.WithNodeConnCnt(500),
sdk.WithNodeUseTLS(true),
sdk.WithNodeTLSHostName("chainmaker.org"),
)
rpcConfig := sdk.NewRPCClientConfig(sdk.WithRPCClientMaxReceiveMessageSize(16))
opts := []sdk.ChainClientOption{
//sdk.WithConfPath(confPath),
sdk.WithChainClientChainId("cqrd"),
sdk.WithChainClientOrgId("cqrd"),
sdk.WithUserCrtBytes(crt),
sdk.WithUserKeyBytes(key),
sdk.WithUserSignCrtBytes(crt),
sdk.WithUserSignKeyBytes(key),
sdk.AddChainClientNodeConfig(node),
sdk.WithRPCClientConfig(rpcConfig),
}
logger.Info(opts)
//方式1
client, err := sdk.NewChainClient(opts...)
//方式2
// client, err := sdk.NewChainClient(sdk.WithConfPath("../sdk_config_client.yml"))
if err != nil {
logger.Error(err)
return
}
kvs := []*common.KeyValuePair{
{
Key: "file_hash",
Value: []byte("1"),
},
}
resp, err := client.QueryContract("dqc3", "find_by_file_hash", kvs, -1)
if err != nil {
logger.Info(err)
}
fmt.Printf("QUERY claim contract resp: %+v\n", resp)
}
sdk_config_client.yml
chain_client:
# 链ID
chain_id: "cqrd"
# 组织ID
org_id: "cqrd"
# 客户端用户私钥路径
user_key_file_path: "user/xlhuang.sign.key"
# 客户端用户证书路径
user_crt_file_path: "user/xlhuang.sign.crt"
# 客户端用户交易签名私钥路径(若未设置,将使用user_key_file_path)
user_sign_key_file_path: "user/xlhuang.sign.key"
# 客户端用户交易签名证书路径(若未设置,将使用user_crt_file_path)
user_sign_crt_file_path: "user/xlhuang.sign.crt"
nodes:
- # 节点地址,格式为:IP:端口:连接数
node_addr: "172.26.2.97:9091"
# 节点连接数
conn_cnt: 500
# RPC连接是否启用双向TLS认证
enable_tls: true
# 信任证书池路径
trust_root_paths:
- "user/ca"
# TLS hostname
tls_host_name: "chainmaker.org"
# archive:
# # 数据归档链外存储相关配置
# type: "mysql"
# dest: "root:123456:localhost:3306"
# secret_key: xxx
rpc_client:
# grpc客户端最大接受容量(MB)
max_receive_message_size: 16
方式2,使用配置文件初始化客户端,合约访问正常
方式1,使用入参方式初始化客户端,请求合约时失败,错误信息如下
QUERY claim contract resp: code:INTERNAL_ERROR message:"tx verify failed, verify tx authentation failed, authentication error: authentication failed, [refine endorsements failed, all endorsers have failed verification], txId:174f0257d2b0a00dca214ac3a2a7ae1858d0b97961c84d379a79ebee5dd8f1ad, sender:2d2d2d2d2d424547494e205055424c4943204b45592d2d2d2d2d0a4d466b77457759484b6f5a497a6a3043415159494b6f45637a31554267693044516741454d656d4741477a49545152744e745044427036436f4c30666c464a2f0a3642514a36496f6f554749375630352b6674565248506a632b3764434c3879304b455046516248357867686a30354f6359444e5a66366b724b773d3d0a2d2d2d2d2d454e44205055424c4943204b45592d2d2d2d2d0a" tx_id:"174f0257d2b0a00dca214ac3a2a7ae1858d0b97961c84d379a79ebee5dd8f1ad"
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information