分享
  1. 首页
  2. 文章

2018年11月15日

深不可测xy · · 1605 次点击 · · 开始浏览
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

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.

有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:深不可测xy

查看原文:2018年11月15日

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

关注微信
1605 次点击
上一篇:Go基础篇
下一篇:Go入门篇
暂无回复
添加一条新回复 (您需要 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传

用户登录

没有账号?注册
(追記) (追記ここまで)

今日阅读排行

    加载中
(追記) (追記ここまで)

一周阅读排行

    加载中

关注我

  • 扫码关注领全套学习资料 关注微信公众号
  • 加入 QQ 群:
    • 192706294(已满)
    • 731990104(已满)
    • 798786647(已满)
    • 729884609(已满)
    • 977810755(已满)
    • 815126783(已满)
    • 812540095(已满)
    • 1006366459(已满)
    • 692541889

  • 关注微信公众号
  • 加入微信群:liuxiaoyan-s,备注入群
  • 也欢迎加入知识星球 Go粉丝们(免费)

给该专栏投稿 写篇新文章

每篇文章有总共有 5 次投稿机会

收入到我管理的专栏 新建专栏