5.4.3.17 Chaincode and block event notification API
This interface is implemented on the off-BSN system side. When the PCN gateway receives the notification of a triggered event, it uses this interface to notify the off-BSN system about the execution result.
After receiving the notification successfully, the off-BSN system returns a string containing “success”, otherwise, the gateway will send the notification again at 3, 12, 27, and 48 seconds respectively, for a total of five times.
1. Call method: POST
2. Signature algorithm: required and refer to Section 5.4.3.1
3. Call parameters
No. | Field name | Field | Type | Required | Remarks |
---|---|---|---|---|---|
1 | Header | header | Map | Y | |
2 | Body | body | Map | N | |
3 | Signature Value | mac | String | Y | |
header | |||||
1 | user unique ID | userCode | String | Y | |
2 | DApp unique ID | appCode | String | Y | |
body | |||||
1 | Chaincode ID | chainCode | String | N | Null when the block event notification |
2 | PCN ID | orgCode | String | Y | |
3 | Registered Event key | eventKey | String | N | |
4 | Registered Event ID | eventId | String | Y | |
5 | Registered Event parameters | attachArgs | String | N | Additional parameters entered during registration |
6 | Monitored event key | eventName | String | N | The event name in the chaincode, null when the block event notification |
7 | Current Chaincode transaction Id | txId | String | N | Null when the block event notification |
8 | Monitored event value | payload | String | N | |
9 | Current Block Height | blockNumber | Long | Y | |
10 | Response random string | nonceStr | String | Y | Off-BSN system uses this value to judge if the notification is already received. This string remains the same at the repeated notifications. |
11 | Previous hash | previousHash | String | N | Null when chaincode event notification |
Example:
Chaincode event nofitication
{"header":{"userCode":"lessing","appCode":"CL20191107112252"},"body":{"chainCode":"cc_bsn_test_00","orgCode":"ORG1571365934172","eventKey":"test:\\S{32}","eventId":"2964a0f60b3e460f834618b3664af2da","attachArgs":"abc=123211","eventName":"test:12345678123456781234567812345678","txId":"32fc105681820fa556b8a460efc1e43a47daa864b959ea1753abb4640f2dce49","payload":"","blockNumber":74,"nonceStr":"522c8061b5e84837bad72ca08c6a353f"},"mac":"MEQCIDU4tROyjLtvD1b8TTbWWAlCPuUbmdPAEUXwRRgVn7kIAiA58je5u/7xDuRPcgeUWL3nB9mouUGQ6dGKJMmD7Jm08g=="}
Block event notification
{"header":{"userCode":"USER0001202007101641243516163","appCode":"app0001202101191411238426266"},"body":{"orgCode":"ORG2020041114171692360","eventId":"8746bb9a1e854c9f8b3710f5a63f7c59","attachArgs":"a=1","previousHash":"022281f6089e3684501251775166b6b0afd18a176ec98a835cb5d09aff0d4950","blockNumber":12,"nonceStr":"79a7baa26c854caeb2e2e7abc0b7f07e"},"mac":"MEUCIQDiZrwf8fKG/3fuaVrsfTN3BKmLx+qnnEuuSaHfvIBbMQIgS+1qHKXeVR24WXwOGu3Nze/tLLziQ0LkjXaueYu0ctM="}
4. The payload parameter in the message is not passed in Fabric 1.4.3, please refer to https://github.com/hyperledger/fabric/blob/v1.4.3/core/peer/deliverevents.go#L251
For the specific code, if you need to use the payload parameter, you can get it as follows:
1) store the content to be passed through the event to the chain in the form of “key-value”.
2) pass the event name and the key splice in 1 as eventName, e.g.: eventkey_key.
3) register the event with a regular registration, e.g. : eventkey_[\s\S]*.
4) after receiving the event, parse the key according to the event name and call a query to get the value.
5) if the amount of payload data to be passed is not large, it can be directly spliced to enevtName, which has no length limitation.