Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Sign in
sdk-go
sdk-go
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1
    • Issues 1
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar

新注册的用户请输入邮箱并保存,随后登录邮箱激活账号。后续可直接使用邮箱登录!

  • chainmaker
  • sdk-gosdk-go
  • Issues
  • #16

Closed
Open
Opened Jun 04, 2024 by wOvOwl@wovowl

InvokeContract函数的withSyncResult参数设置为true时,交易请求发送失败的问题

golang 1.21.5
sdk-go v3.0.1
chainmaker v2.3.2
docker-vm 部署golang合约

提交交易的函数:

func SaveDataToChain(client *sdk.ChainClient, contractName, method, entityName, field, data, txId string, withSyncResult bool) string {

	kvs := []*common.KeyValuePair{
		{
			Key:   "entity_name",
			Value: []byte(entityName),
		},
		{
			Key:   "field",
			Value: []byte(field),
		},
		{
			Key:   "data",
			Value: []byte(data),
		},
	}
	fmt.Printf("invoke contract, contract name: %s, method: %s, params: %s", contractName, method, kvs)

	resp, err := client.InvokeContract(contractName, method, txId, kvs, -1, withSyncResult)
	if err != nil {
		panic(err)
	}

	if resp.Code != common.TxStatusCode_SUCCESS {
		msg := fmt.Errorf("invoke contract failed, [code:%d]/[msg:%s]\n", resp.Code, resp.Message)
		panic(msg)
	}

	return resp.Message
}

sdk配置如下:

chain_client:
  # 链ID
  chain_id: "chain1"
  # 组织ID
  org_id: "wx-org1.chainmaker.org"
  # 客户端用户私钥路径
  user_key_file_path: "../crypto-config/wx-org1.chainmaker.org/certs/user/client1/client1.tls.key"
  # 客户端用户证书路径
  user_crt_file_path: "../crypto-config/wx-org1.chainmaker.org/certs/user/client1/client1.tls.crt"
  # 客户端用户加密私钥路径(tls加密证书对应私钥,应用于国密GMTLS双证书体系;若未设置仅使用单证书)
  user_enc_key_file_path: "../crypto-config/wx-org1.chainmaker.org/certs/user/client1/client1.tls.enc.key"
  # 客户端用户加密证书路径(tls加密证书,应用于国密GMTLS双证书体系;若未设置仅使用单证书)
  user_enc_crt_file_path: "../crypto-config/wx-org1.chainmaker.org/certs/user/client1/client1.tls.enc.crt"
  # 客户端用户交易签名私钥路径(若未设置,将使用user_key_file_path)
  user_sign_key_file_path: "../crypto-config/wx-org1.chainmaker.org/certs/user/client1/client1.sign.key"
  # 客户端用户交易签名证书路径(若未设置,将使用user_crt_file_path)
  user_sign_crt_file_path: "../crypto-config/wx-org1.chainmaker.org/certs/user/client1/client1.sign.crt"
  # 当前签名证书的别名。当设置此配置项时,chain client 对象将自动检查链上是否已添加此别名,如果没有则自动上链此证书别名,
  # 并且后续所有交易都会使用别名,别名可降低交易体大小。若为空则不启用。
#  alias: mycert1

  nodes:
    - # 节点地址,格式为:IP:端口:连接数
      node_addr: "192.168.6.10:12301"
      # 节点连接数
      conn_cnt: 10
      # RPC连接是否启用双向TLS认证
      enable_tls: true
      # 信任证书池路径
      trust_root_paths:
        - "../crypto-config/wx-org1.chainmaker.org/certs/ca/wx-org1.chainmaker.org"
      # TLS hostname
      tls_host_name: "chainmaker.org"
    - # 节点地址,格式为:IP:端口:连接数
      node_addr: "192.168.6.10:12302"
      # 节点连接数
      conn_cnt: 10
      # RPC连接是否启用双向TLS认证
      enable_tls: true
      # 信任证书池路径
      trust_root_paths:
        - "../crypto-config/wx-org2.chainmaker.org/certs/ca/wx-org2.chainmaker.org"
      # TLS hostname
      tls_host_name: "chainmaker.org"
    - # 节点地址,格式为:IP:端口:连接数
      node_addr: "192.168.6.10:12303"
      # 节点连接数
      conn_cnt: 10
      # RPC连接是否启用双向TLS认证
      enable_tls: true
      # 信任证书池路径
      trust_root_paths:
        - "../crypto-config/wx-org3.chainmaker.org/certs/ca/wx-org3.chainmaker.org"
      # TLS hostname
      tls_host_name: "chainmaker.org"
    - # 节点地址,格式为:IP:端口:连接数
      node_addr: "192.168.6.10:12304"
      # 节点连接数
      conn_cnt: 10
      # RPC连接是否启用双向TLS认证
      enable_tls: true
      # 信任证书池路径
      trust_root_paths:
        - "../crypto-config/wx-org4.chainmaker.org/certs/ca/wx-org4.chainmaker.org"
      # TLS hostname
      tls_host_name: "chainmaker.org"
  archive:
    # 数据归档链外存储相关配置
    type: "mysql"
    dest: "root:123456:localhost:3306"
    secret_key: xxx
  rpc_client:
    max_receive_message_size: 16 # grpc客户端接收消息时,允许单条message大小的最大值(MB)
    max_send_message_size: 16 # grpc客户端发送消息时,允许单条message大小的最大值(MB)
    send_tx_timeout: 60 # grpc 客户端发送交易超时时间
    get_tx_timeout: 60 # rpc 客户端查询交易超时时间
  pkcs11:
    enabled: false # pkcs11 is not used by default
    library: /usr/local/lib64/pkcs11/libupkcs11.so # path to the .so file of pkcs11 interface
    label: HSM # label for the slot to be used
    password: 11111111 # password to logon the HSM(Hardware security module)
    session_cache_size: 10 # size of HSM session cache, default to 10
    hash: "SHA256" # hash algorithm used to compute SKI
  kms:
    enabled: false            # kms enable flag, set true if use kms
    is_public: true           # private cloud kms or public cloud kms, set true if use public kms
    secret_id: ""             # cloud kms SecretId
    secret_key: ""            # cloud kms SecretKey
    address: "kms.tencentcloudapi.com" # kms server address, ip or dns
    region: "ap-guangzhou"    # kms server region
    sdk_scheme: "https"       # kms sdk scheme, http or https
    ext_params: ""            # optional,this is a map string, like "{k1:v1, k2:v2}".

提交交易之后产生如下错误信息: image

通过查看智能合约的日志,发现智能合约并没有被调用。 在同样的sdk配置下,withSyncResult的值设置为false时,交易可以正常提交,合约被调用。

Edited Jun 04, 2024 by wOvOwl
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: chainmaker/sdk-go#16

Copyright © 2021 ChainMaker Org. All Rights Reserved. 长安链 版权所有。