說明
以下api說明中{xxx}表示變量/參數(shù)
所有請求和返回均為json
請求格式
{
"jsonrpc": "2.0",
"method": "{method}",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"{function}",
"args":["{參數(shù)1}","{參數(shù)2}","{參數(shù)3}"...]
}
},
"id":{id}
}
{method} query/invoke
{chaincodeId} 測試前提供
{function} 實際操作,見具體API
{args} 調(diào)用參數(shù)娃承,見具體API
返回格式
{
"jsonrpc": "2.0",
"result": {
"status": "{status}",
"message": "{body}"
},
"id":{id}
}
- 所有invoke方法調(diào)用都是異步提交方式武花,返回結(jié)果只有事務(wù)TXID。
status ok不代表執(zhí)行成功,執(zhí)行結(jié)果無法直接查看温自,只能通過查看world state狀態(tài)查看調(diào)用結(jié)果
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
{id}:數(shù)字,序號,暫無意義,下同
-
目前fabric無法查詢到返回結(jié)果已维,demo階段將執(zhí)行結(jié)果放入world state供查詢。
request
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"result",
"args":["{TXID}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"OK\",\"result\":{json}/"{string}",\"status\":\"20000000\",\"success\":true}"
},
"id":{id}
}
{status}="20000000"或者{success}=true為成功
result為結(jié)果json
api
1.交易所
字段
- marketId 交易所id,demo階段只需要創(chuàng)建一個票交所阔墩,所有交易都在一個票交所交易
- address 地址
- name 名稱
- priKey 私鑰嘿架。簽名使用,demo不做數(shù)字簽名啸箫,只簡單比較私鑰耸彪。值為pri-{marketId}
- pubKey 公鑰。值為pub-{marketId}
1.1創(chuàng)建交易所
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"market.create",
"args":["{\"marketId\":\"{marketId}\",\"address\":\"{地址}\",\"name\":\"{name}\"}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表創(chuàng)建成功忘苛,見說明
1.2查詢交易所
request
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"market",
"args":["{marketId}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"OK\",\"result\":\"{\"address\":\"{address}\",\"marketId\":\"{market}\",\"name\":\"{name}\",\"priKey\":\"{priKey}\",\"pubKey\":\"{pubKey}\"}\",\"status\":\"20000000\",\"success\":true}"
},
"id": 0
}
- demo ok
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"OK\",\"result\":\"{\"address\":\"beijing\",\"marketId\":\"qianbao\",\"name\":\"qianbao\",\"priKey\":\"pri-qianbao\",\"pubKey\":\"pub-qianbao\"}\",\"status\":\"20000000\",\"success\":true}"
},
"id": 0
}
- demo-not found
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"market not found!\",\"status\":\"40400000\",\"success\":false}"
},
"id": 0
}
2.用戶
- userId 為公司或組織業(yè)務(wù)ID
- marketId 所屬票交所
- type 1:spv,可以做資產(chǎn)打包合約;2:普通票據(jù)持有者
- market-priKey 必須為票交所對應(yīng)priKey,用戶創(chuàng)建只能通過票交所上鏈蝉娜,通過該字段檢查來模擬票交所簽名
- address 地址
- businessLicense 營業(yè)執(zhí)照
- organizationCodeCertificate 稅務(wù)登記證
- taxRegistrationCertificate 組織機構(gòu)代碼證
- priKey 用戶私鑰唱较。demo不做數(shù)字簽名,只簡單比較私鑰召川。值為pri-{userId}
- pubKey 用戶公鑰南缓。值為pub-{userId}
2.1用戶上鏈
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"user.create",
"args":["{\"name\":\"{name}\",\"address\":\"{address}\",\"marketId\":\"{marketId}\",\"type\":{type},\"userId\":\"{userId}\",\"businessLicense\":\"{businessLicense}\",\"organizationCodeCertificate\":\"{organizationCodeCertificate}\",\"taxRegistrationCertificate\":\"{organizationCodeCertificate}\"}","{market-priKey"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表創(chuàng)建成功,見說明
2.2查詢用戶
request
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"user",
"args":["userId"]
}
},
"id":{id}
}
response demo
- ok
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"OK\",\"result\":\"{\"address\":\"beijing\",\"businessLicense\":\"xxxxx\",\"marketId\":\"qianbao\",\"name\":\"zhangzheng\",\"organizationCodeCertificate\":\"xxxxxx\",\"priKey\":\"pri-zz\",\"pubKey\":\"pub-zz\",\"taxRegistrationCertificate\":\"xxxxxx\",\"type\":1,\"userId\":\"zz\"}\",\"status\":\"20000000\",\"success\":true}"
},
"id": 0
}
- not found
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"user not found!\",\"status\":\"40400000\",\"success\":false}"
},
"id": 0
}
3.票據(jù)
- userId 用戶id
- marketId 所屬票交所
- billId 票據(jù)id
- type 1:紙銀;2:紙商
- status 10.持有荧呐,20.交易中汉形,30.資產(chǎn),40.已承兌坛增。允許狀態(tài)轉(zhuǎn)換:持有->交易中;交易中->資產(chǎn);持有->已承兌;交易中->持有;資產(chǎn)->已承兌
- amount 面值
- startDate yyyyMMdd
- endDate yyyyMMdd
- bank 銀行
- bankAddress 銀行地址
- billPackage 資產(chǎn)包获雕。資產(chǎn)打包后改字段有值
- transactions 歷史交易id。字符串數(shù)組
3.1 票據(jù)上鏈
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"bill.create",
"args":["{\"billId\":\"{billId}\",\"type\":{type},\"marketId\":\"{marketId}\",\"userId\":\"{userId}\",\"amount\":{amout},\"startDate\":\"{startDate}\",\"endDate\":\"{endDate}\",\"bank\":\"{bank}\",\"bankAddress\":\"{bankAddress}\"}","market-priKey","user-priKey"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表創(chuàng)建成功收捣,見說明
3.2 票據(jù)查詢
request
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"bill",
"args":["{billId}"]
}
},
"id":{id}
}
response demo
- ok
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"OK\",\"result\":\"{\"amount\":1000000,\"billId\":\"bill002\",\"endDate\":\"20180107\",\"startDate\":\"20180107\",\"bank\":\"ccbc\",\"bankAddress\":\"beijing\",\"marketId\":\"qianbao\",\"startDate\":\"20170107\",\"status\":10,\"transactions\":[\"5fe73654-dd53-433b-993f-62435ed3eeb4\",\"39a06dc2-f6a3-45d1-80c8-e42e5105afad\"],\"type\":1,\"userId\":\"gaoxiang\"}\",\"status\":\"20000000\",\"success\":true}"
},
"id": 0
}
- not found
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{\"message\":\"bill not found!\",\"status\":\"40400000\",\"success\":false}"
},
"id": 0
}
4.交易
- transactionId 交易ID,使用交易創(chuàng)建返回的區(qū)塊鏈TXID作為交易ID届案。
- billId 票據(jù)Id
- buyer 買方Id
- buyerMarket 買方票交所Id
- seller 賣方Id
- sellerMarket 賣方票交所Id
- buyerStatus 買方狀態(tài),只能買方修改罢艾。0,交易中;1,完成;2,取消
- sellerStatus 賣方狀態(tài)楣颠,只能賣方修改。0,交易中;1,完成;2,取消
- status 交易狀態(tài)咐蚯。0,交易中;1,完成(交易雙方狀態(tài)都是完成);2,取消(交易雙方狀態(tài)都是取消)
- createTime 交易創(chuàng)建時間
4.1交易創(chuàng)建
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"transaction.create",
"args":["{\"billId\":\"{billId}\",\"sellerMarket\":\"{sellerMarket}\",\"seller\":\"{seller}\",\"buyerMarket\":\"{buyerMarket}\",\"buyer\":\"{buyer}\",\"price\":{price},\"createTime\":{createTime}}","{sellerMarket-priKey}","{seller-priKey}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
返回消息中的TXID直接作為票據(jù)交易的transactionId,該返回并不代表交易創(chuàng)建成功童漩,見說明。
交易創(chuàng)建成功春锋,票據(jù)狀態(tài)變更為交易中(20)矫膨。
4.2買方確認
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"transaction.buyer.confirm",
"args":["transactionId","{buyerMarket-priKey}","{buyer-priKey}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表交易確認成功,見說明期奔。
買方確認成功時侧馅,買方狀態(tài)變更為完成(1)。若賣方狀態(tài)為完成(1)呐萌。則交易狀態(tài)變更為完成(1)馁痴,同時修改票據(jù)所有人,及票據(jù)狀態(tài)(10)肺孤。
4.3賣方確認
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"transaction.seller.confirm",
"args":["transactionId","{sellerMarket-priKey}","{seller-priKey}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表交易確認成功罗晕,見說明。
賣方確認成功時赠堵,賣方狀態(tài)變更為完成(1)小渊。若買方狀態(tài)為完成(1)。則交易狀態(tài)變更為完成(1)茫叭,同時修改票據(jù)所有人酬屉,及票據(jù)狀態(tài)(10)。
4.4買方取消
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"transaction.buyer.cancle",
"args":["transactionId","{buyerMarket-priKey}","{buyer-priKey}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表交易取消成功杂靶,見說明梆惯。
買方取消成功時,買方狀態(tài)變更為取消(2)吗垮。若賣方狀態(tài)為取消(2)垛吗。則交易狀態(tài)變更為取消(2),同時修改票據(jù)狀態(tài)(10)烁登。
4.5賣方取消
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"transaction.seller.cancle",
"args":["transactionId","{sellerMarket-priKey}","{seller-priKey}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表交易取消成功怯屉,見說明。
賣方取消成功時饵沧,賣方狀態(tài)變更為取消(2)锨络。若買狀態(tài)為取消(2)。則交易狀態(tài)變更為取消(2)狼牺,同時修改票據(jù)狀態(tài)(10)羡儿。
4.5交易查詢
request
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"transaction",
"args":["{transactionId}"]
}
},
"id":{id}
}
5.資產(chǎn)
- packageId 資產(chǎn)ID,使用資產(chǎn)上鏈返回的區(qū)塊鏈TXID作為資產(chǎn)ID。
- marketId 票交所
- userId 資產(chǎn)所有人是钥,只有SPV才能打包資產(chǎn)
- name 資產(chǎn)名稱
- endDate 資產(chǎn)到期日yyyyMMdd
- status 資產(chǎn)狀態(tài)掠归。10,資產(chǎn);20,兌付中;30,已兌付
- startDate yyyyMMdd
- price 資產(chǎn)價格,double
- billIds 票據(jù)id。字符串數(shù)組
5.1資產(chǎn)打包上鏈
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"package.create",
"args":["{\"userId\":\"{userId}\",\"marketId\":\"{marketId}\",\"name\":\"{name}\",\"endDate\":\"{endDate}\",\"price\":{price},\"billIds\":[\"{billId}",\"{billId}\"]}","{market-priKey}","{user-priKey}"]
}
},
"id":{id}
}
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
返回消息中的TXID直接作為資產(chǎn)的packageId,該返回并不代表資產(chǎn)創(chuàng)建成功悄泥,見說明虏冻。
資產(chǎn)打包會檢查票據(jù)持有人及priKey。
資產(chǎn)創(chuàng)建成功弹囚,票據(jù)狀態(tài)變更為資產(chǎn)(30)厨相。
5.2資產(chǎn)狀態(tài)更新
request
{
"jsonrpc": "2.0",
"method": "invoke",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"package.create",
"args":["{package}","{market-priKey}","{user-priKey}","{status}"]
}
},
"id":{id}
}
{status}只能為"20"或者"30"
response
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "{TXID}"
},
"id":{id}
}
該返回并不代表資產(chǎn)狀態(tài)更新成功,見說明鸥鹉。
資產(chǎn)狀態(tài)更新為已兌付(30)時蛮穿,票據(jù)狀態(tài)變更為已兌付(40)。
5.3資產(chǎn)查詢
request
{
"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID":{
"name":"{chaincodeId}"
},
"ctorMsg": {
"function":"package",
"args":["{package}"]
}
},
"id":{id}
}