Skip to content

GitLab

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

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

  • chainmaker
  • issueissue
  • Issues
  • #1029

Closed
Open
Opened Mar 29, 2024 by 石漱夏目@sumai

利用go-sdk调用合约的查询方法时,怎么获得查询到的数据?

利用go-sdk调用创建资源方法,可以在区块链浏览器查询到交易和创建数据信息,但是在管理台查询该数据时只显示查询成功不显示数据,并且go-sdk的QueryContract字返回交易id等信息,我该如何获得原始数据? 这是gosdk中查询资源的函数: func GetResourceByID(ctx *gin.Context) { id = ctx.Query("id")

fmt.Println("====================== create client ======================")
client, err := examples.CreateChainClientWithSDKConf(sdkConfigOrg1Client1Path)
panicErr(err)


kvs := []*common.KeyValuePair{
	{
		Key:   "method",
		Value: []byte("getResourceByID"),
	},
	{
		Key:   "id",
		Value: []byte(id),
	},
}
fmt.Println("====================== 执行合约查询接口 ======================")
testUserContractClaimQuery(client, "invoke_contract", kvs)

ctx.JSON(200, gin.H{
	"code": 200,
	"msg":  "查询成功",
})

} 这是合约中的查询方法: func (f *ResourceContract) getResourceByID() protogo.Response { id := string(sdk.Instance.GetArgs()["id"])

resourceBytes, err := sdk.Instance.GetStateByte("resource_bytes", id)
if err != nil {
	return sdk.Error("failed to call get_state")
}

return sdk.Success(resourceBytes)

}

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/issue#1029

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