Skip to content
Aberic Yang edited this page Aug 8, 2018 · 6 revisions

API参考

Method REST API Description
POST /state/invoke 执行智能合约
POST /state/query 查询智能合约
POST /trace/hash 根据交易hash查询区块
POST /trace/number 根据交易区块高度查询区块
POST /trace/txid 根据交易ID查询区块
GET /trace/info/{id} 根据当前智能合约id查询当前链信息

如果有SaaS/BaaS服务的紧急需求,可以自行参考v0.1中的方案来解决。


链码接口用例

执行智能合约


该智能合约以chaincode_example02.go为例。
请求方式:POST
请求接口:http://ip:port/state/invoke
请求参数:

{
   "flag": "9305b6266c57d8cc",
   "key": "0XVnCLdh",
   "strArray": ["invoke", "a", "b", "1"]
}

请求结果:

{
	"code": 200,
	"txid": "49eb3c9556029951e9a58414b8a752cf3720663b0252f21d2b3c34f439a93d15"
}

查询智能合约


该智能合约以chaincode_example02.go为例。
请求方式:POST
请求接口:http://ip:port/state/query
请求参数:

{
   "flag": "9305b6266c57d8cc",
   "key": "0XVnCLdh",
   "strArray": ["query", "a"]
}

请求结果:

{
	"code": 200,
	"data": "-1",
	"txid": "88741ad952662e4b13361ea68196fb346dbd53dea8e27f4862f5eb8518975b09"
}

溯源接口用例

根据交易ID查询区块

请求方式:POST
请求接口:http://ip:port/state/trace/txid
请求参数:

{
	"trace": "66a58b02017952637ce556ed160fd2e21347a12e6043d799e4eaa1e43e681fcb",
   "flag": "9305b6266c57d8cc",
   "key": "0XVnCLdh"
}

请求结果:

{
	"dataHash": "2e04f43c307ba0627011331a761e0fa48af01f121d02f15155c640ce8bde3f82",
	"blockNumber": 29,
	"calculatedBlockHash": "150fae051b6754b7a977901588c78312a4a9bfc7b650d3abff744c994cab2f9a",
	"envelopeCount": 1,
	"envelopes": [],
	"previousHashID": "8a19b638a50a5f58a27e3999c6046158d8015902340011f05c84554b8ccebb69"
}

根据交易hash查询区块

请求方式:POST
请求接口:http://ip:port/state/trace/hash
请求参数:

{
	"trace": "150fae051b6754b7a977901588c78312a4a9bfc7b650d3abff744c994cab2f9a",
   "flag": "9305b6266c57d8cc",
   "key": "0XVnCLdh"
}

请求结果:

{
	"dataHash": "2e04f43c307ba0627011331a761e0fa48af01f121d02f15155c640ce8bde3f82",
	"blockNumber": 29,
	"calculatedBlockHash": "150fae051b6754b7a977901588c78312a4a9bfc7b650d3abff744c994cab2f9a",
	"envelopeCount": 1,
	"envelopes": [],
	"previousHashID": "8a19b638a50a5f58a27e3999c6046158d8015902340011f05c84554b8ccebb69"
}

根据交易区块高度查询区块

请求方式:POST
请求接口:http://ip:port/state/trace/number
请求参数:

{
	"trace": "29",
   "flag": "9305b6266c57d8cc",
   "key": "0XVnCLdh"
}

请求结果:

{
	"dataHash": "2e04f43c307ba0627011331a761e0fa48af01f121d02f15155c640ce8bde3f82",
	"blockNumber": 29,
	"calculatedBlockHash": "150fae051b6754b7a977901588c78312a4a9bfc7b650d3abff744c994cab2f9a",
	"envelopeCount": 1,
	"envelopes": [],
	"previousHashID": "8a19b638a50a5f58a27e3999c6046158d8015902340011f05c84554b8ccebb69"
}

根据当前链码id查询当前链信息

请求方式:GET
请求接口:http://ip:port/trace/info/1
请求结果:

{
	"code": 200,
	"data": {
		"previousBlockHash": "2669384cdfb19576603954e198daa0a964f2f6afbc3f8da42600c54e13ce0fd7",
		"currentBlockHash": "7f05d84db20afb58b1abc323bc1075c3ee057d0e3cb3bad30881e717323fad7b",
		"height": 36
	}
}



继续阅读进阶使用文档。