Fabric Node App For jinglan trace
App is design to meet the requirement of ****onchain**** & ****trace**** of kingland
Prerequisites and setup:
Docker - 17.06.2-ce or greater is required
Docker Compose - 1.14.0 or greater
Git client - needed for clone commands
Node.js v8.12.0 ( Node v7+ is not supported )
Golang v1.10.1 or higher
Setup Environment ()
git clone [http://116.236.220.212:30071/kingland/trace_kingland](http://116.236.220.212:30071/kingland/trace_kingland)
git checkout release-1.0
cd trace_kingland
./artifacts/channel/bootstrap.sh
Once you have completed the above setup, you will have provisioned a local network with the following docker container configuration:
4 CAs
A Kafka Orderer cluster
4 peers (1 peer per Org)
Artifacts
Crypto material has been generated using the cryptogen tool from Hyperledger Fabric and mounted to all peers, the orderering node and CA containers. More details regarding the cryptogen tool are available here.
An Orderer genesis block (genesis.block) and channel configuration transaction (mychannel.tx) has been pre generated using the configtxgen tool from Hyperledger Fabric and placed within the artifacts folder. More details regarding the configtxgen tool are available here.
Set up network environment
Start zookeeper
- 47.99.177.52
cd trace_jinglan/artifacts/channel
sh network_setup.sh startZookeeper0
- 47.99.171.97
cd trace_jinglan/artifacts/channel
sh network_setup.sh startZookeeper1
- 47.98.114.127
cd trace_jinglan/artifacts/channel
sh network_setup.sh startZookeeper2
Start kafka
- 47.99.177.52
cd trace_jinglan/artifacts/channel
sh network_setup.sh startKafka0
- 47.99.171.97
cd trace_jinglan/artifacts/channel
sh network_setup.sh startKafka1
- 47.98.114.127
cd trace_jinglan/artifacts/channel
sh network_setup.sh startKafka2
- 47.99.192.31
cd trace_jinglan/artifacts/channel
sh network_setup.sh startKafka3
Start Peer/Orderer
- 47.99.177.52
cd trace_jinglan/artifacts/channel
sh network_setup.sh startServer1
- 47.99.171.97
cd trace_jinglan/artifacts/channel
sh network_setup.sh startServer2
- 47.98.114.127
cd trace_jinglan/artifacts/channel
sh network_setup.sh startServer3
- 47.99.192.31
cd trace_jinglan/artifacts/channel
sh network_setup.sh startServer4
- This launches the required network on your machine
Run Node App
cd trace_jinglan
./runApp
Installs the fabric-client and fabric-ca-client node modules
And, starts the node app on PORT 4000
Run Base Apis
cd trace_jinglan
./testAPIs.sh
This create a channel named mychannel
Helps peers to join mychannel
Installs chaincode on peers
Instantiate the chaincode
REST APIs
Request for User Token
curl -s -X POST \
[http://127.0.0.1:4000/api/v1/token](http://127.0.0.1:4000/api/v1/token) \
-H "content-type: application/json" \
-d '{
"username":"Jim",
}'
- username : user's name
Response:
{
"code": 200,
"message": "Jim enrolled Successfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzY4MzY5NTgsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1MzY4MDA5NTh9.xPSP20obwgaKrrDxbwNeZtmOn6ngByWXcdN_TlEhK_E"
}
code : 200 means success, other representatives fail
message : more detailed message for response
token : json web token
Invoke chainCode
curl -s -X POST \
[http://localhost:4000/api/v1/save](http://localhost:4000/api/v1/save)\
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzgyNzQ5MDgsInVzZXJuYW1lIjoiUmFuZHkiLCJvcmdOYW1lIjoiT3JnMSIsImlhdCI6MTUzODI3NDg3OH0.jN8xZb69HzuFBxtmQFsNOVUU8ystgwi4pcy9KCze5xU" \
-H "content-type: application/json" \
-d '{
"data":[
{
"objectType":"iot",
"id":"1",
"timestamp":"1538275141",
"hash":"b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
}
]
}'
objectType : limitation of upload data type, optional value (iot/business)
id : --
timestamp : --
hash : hash of data during this time
Response:
{
"code": 200,
"message": "操作成功",
"data": [
"0ff44fcb0c4dee9bd03a5592b855440a16887ba9afae3f852c6d56a9b96ee17c"
]
}
code : 200 means success, other representatives fail
message : more detailed message for response
data : transactionIDs
Query chainCode
curl -s -X POST \
"[http://localhost:4000/api/v1/query](http://localhost:4000/api/v1/query)" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzgyNzQ5MDgsInVzZXJuYW1lIjoiUmFuZHkiLCJvcmdOYW1lIjoiT3JnMSIsImlhdCI6MTUzODI3NDg3OH0.jN8xZb69HzuFBxtmQFsNOVUU8ystgwi4pcy9KCze5xU" \
-H "content-type: application/json" \
-d '
{
"objectType":"iot",
"start":"1538275141",
"end":"1538276545"
}
'
objectType : limitation of upload data type, optional value (iot/business)
start : start time for timestamp
end : end time for timestamp
Response:
{
"code": 200,
"message": "查询成功",
"data": [
{
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3",
"id": "1",
"objectType": "iot",
"timestamp": "1538275141"
}
]
}
code : 200 means success, other representatives fail
message : more detailed message for response
data : --
HashVerify
curl -s -X POST \
"[http://localhost:4000/api/v1/hashVerify](http://localhost:4000/api/v1/hashVerify)" \
-H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MzgyNzQ5MDgsInVzZXJuYW1lIjoiUmFuZHkiLCJvcmdOYW1lIjoiT3JnMSIsImlhdCI6MTUzODI3NDg3OH0.jN8xZb69HzuFBxtmQFsNOVUU8ystgwi4pcy9KCze5xU" \
-H "content-type: application/json" \
-d '
{
"objectType":"iot",
"start":"1538275141",
"end":"1538276545",
"hash":"5885ad7bdb33da94583387b197bbef4a055f53ac34c85b5e00794945d6180074"
}'
objectType : limitation of upload data type, optional value (iot/business)
start : start time for timestamp
end : end time for timestamp
hash : hash of data during this time
Response:
{
"code": 200,
"message": "HASH校验成功",
"data": [
{
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3",
"id": "1",
"objectType": "iot",
"timestamp": "1538275141",
"transactionId": "903d8758f7177b4a389893fbc48e3eae7fbd9f52b7ca31ddc00fa25da3b3236f"
}
]
}
code : 200 means success, other representatives fail
message : more detailed message for response
data : --
Network configuration considerations
You have the ability to change configuration parameters by editing the network-config.yaml file.
Discover IP Address
To retrieve the IP Address for one of your network entities, issue the following command:
# this will return the IP Address for peer0
docker inspect peer0 | grep IPAddress
Troubleshooting
Please visit the TROUBLESHOOT.mdTROUBLESHOOT.md to view the Troubleshooting TechNotes.
<br />This work is licensed under a Creative Commons Attribution 4.0 International License.有疑问加站长微信联系(非本文作者)