2018-11-15

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.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,099评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,828评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,540评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,848评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,971评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,132评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,193评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,934评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,376评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,687评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,846评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,537评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,175评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,887评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,134评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,674评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,741评论 2 351

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,315评论 0 10
  • 版权归作者所有,任何形式转载请联系作者。 作者:花哈哈hhh 跟室友逛街看见一个长得跟我理想型特别像的男生,回来告...
    陈小花fa阅读 548评论 0 16
  • 休息在家看了董卿的朗读者,看到倪萍读她写的姥姥语录,文字总是有力量的,我,,想起了我的外婆! 小时候父母外出做...
    兔子夏天阅读 571评论 1 3
  • 小学的时候,我们每周的语文作业都是一篇作文,这让我很高兴。因为我们老师总是在星期一就把周记本发下来,如果我能在周六...
    绿植酱阅读 346评论 0 1