资讯专栏INFORMATION COLUMN

Fabric学习笔记(五) - Fabric-sdk-node的使用

icattlecoder / 3309人阅读

摘要:本文参考原文档有些问题会跑不通做了适度的调整部署网络并启动下载启动网络修改安装的和安装并查看版本查看版本安装依赖请安装启动服务启动日志

本文参考balance-transfer,原文档有些问题会跑不通,做了适度的调整

部署fabric网络并启动fabric-client(nodejs) 下载fabric-samples
cd /opt/gopath/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-samples
启动网络
cd /opt/gopath/src/github.com/hyperledger/fabric-samples/balance-transfer
docker-compose -f artifacts/docker-compose.yaml up
修改package.json
{
  "name": "balance-transfer",
  "version": "1.0.0",
  "description": "A balance-transfer example node program to demonstrate using node.js SDK APIs",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "keywords": [
    "fabric-client sample app",
    "balance-transfer node sample",
    "v1.0 fabric nodesdk sample"
  ],
  "engines": {
    "node": "8.9.4",
    "npm": "5.6.0"
  },
  "license": "Apache-2.0",
  "dependencies": {
    "body-parser": "^1.17.1",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.3",
    "express": "^4.15.2",
    "express-bearer-token": "^2.1.0",
    "express-jwt": "^5.1.0",
    "express-session": "^1.15.2",
    "fabric-ca-client": "^1.0.2",
    "fabric-client": "^1.0.2",
    "fs-extra": "^2.0.0",
    "jsonwebtoken": "^7.3.0",
    "log4js": "^0.6.38"
  }
}
安装node 的fabric-ca-client和fabric-client node安装并查看版本
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum install -y nodejs
node -v
v8.9.4
查看npm版本
npm -v
5.6.0
安装依赖
npm install node-gyp
npm install node-pre-gyp
npm install grpc
npm install
请安装jq
 yum install jq
启动node服务
PORT=4000 node app

启动日志

[2018-01-31 16:30:13.600] [DEBUG] Helper - [crypto_ecdsa_aes]: constructor, keySize: 256
[2018-01-31 16:30:13.604] [DEBUG] Helper - [crypto_ecdsa_aes]: Hash algorithm: SHA2, hash output size: 256
[2018-01-31 16:30:13.711] [DEBUG] Helper - [utils.CryptoKeyStore]: CryptoKeyStore, constructor - start
[2018-01-31 16:30:13.712] [DEBUG] Helper - [utils.CryptoKeyStore]: constructor, no super class specified, using config: fabric-client/lib/impl/FileKeyValueStore.js
[2018-01-31 16:30:13.718] [DEBUG] Helper - [crypto_ecdsa_aes]: constructor, keySize: 256
[2018-01-31 16:30:13.718] [DEBUG] Helper - [crypto_ecdsa_aes]: Hash algorithm: SHA2, hash output size: 256
[2018-01-31 16:30:13.718] [DEBUG] Helper - [utils.CryptoKeyStore]: CryptoKeyStore, constructor - start
[2018-01-31 16:30:13.719] [DEBUG] Helper - [utils.CryptoKeyStore]: constructor, no super class specified, using config: fabric-client/lib/impl/FileKeyValueStore.js
[2018-01-31 16:30:13.735] [INFO] SampleWebApp - ****************** SERVER STARTED ************************
[2018-01-31 16:30:13.736] [INFO] SampleWebApp - **************  http://localhost:4000  ******************
以上步骤均在runApp.sh中
vim /opt/gopath/src/github.com/hyperledger/fabric-samples/balance-transfer/runApp.sh
使用node API实现操作
注意此时需要http访问了,需要关闭之前的各种proxy
注册和enroll新的user在org1
curl -s -X POST 
  http://localhost:4000/users 
  -H "content-type: application/x-www-form-urlencoded" 
  -d "username=Barry&orgName=org1"


{"success":true,"secret":"","message":"Barry enrolled Successfully","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw"}
注册和enroll新的user在org2
curl -s -X POST 
  http://localhost:4000/users 
  -H "content-type: application/x-www-form-urlencoded" 
  -d "username=Barry&orgName=org2"

{"success":true,"secret":"","message":"Barry enrolled Successfully","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2OTcsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMiIsImlhdCI6MTUxNzQ1MDY5N30.YhCQNk3vSeb4hA51cHIUJO9XKiDbiv3N9XnbYHreCz0"}
创建channel
curl -s -X POST 
  http://localhost:4000/channels 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json" 
  -d "{
    "channelName":"mychannel",
    "channelConfigPath":"../artifacts/channel/mychannel.tx"
}"


{"success":true,"message":"Channel "mychannel" created Successfully"}
注意:authorization Bearer后跟之前的enroll的token
org1加入channel
curl -s -X POST 
  http://localhost:4000/channels/mychannel/peers 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json" 
  -d "{
    "peers": ["peer1","peer2"]
}"

{"success":true,"message":"Successfully joined peers in organization org1 to the channel "mychannel""}
org2加入channel
curl -s -X POST 
  http://localhost:4000/channels/mychannel/peers 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2OTcsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMiIsImlhdCI6MTUxNzQ1MDY5N30.YhCQNk3vSeb4hA51cHIUJO9XKiDbiv3N9XnbYHreCz0" 
  -H "content-type: application/json" 
  -d "{
    "peers": ["peer1","peer2"]
}"

{"success":true,"message":"Successfully joined peers in organization org2 to the channel "mychannel""}
org1 安装channelcode
curl -s -X POST 
  http://localhost:4000/chaincodes 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json" 
  -d "{
    "peers": ["peer1", "peer2"],
    "chaincodeName":"mycc",
    "chaincodePath":"github.com/example_cc",
    "chaincodeVersion":"v0"
}"

Successfully Installed chaincode on organization org1
chaincodePath 也可以写成绝对路径
"chaincodePath":"$PWD/artifacts/src/github.com/example_cc/node",
org2 安装channelcode
curl -s -X POST 
  http://localhost:4000/chaincodes 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2OTcsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMiIsImlhdCI6MTUxNzQ1MDY5N30.YhCQNk3vSeb4hA51cHIUJO9XKiDbiv3N9XnbYHreCz0" 
  -H "content-type: application/json" 
  -d "{
    "peers": ["peer1","peer2"],
    "chaincodeName":"mycc",
    "chaincodePath":"github.com/example_cc",
    "chaincodeVersion":"v0"
}"

Successfully Installed chaincode on organization org2
org1 的peer1 实例化channelcode
curl -s -X POST 
  http://localhost:4000/channels/mychannel/chaincodes 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json" 
  -d "{
    "chaincodeName":"mycc",
    "chaincodeVersion":"v0",
    "args":["a","100","b","200"]
}"

Chaincode Instantiation is SUCCESS[
org1的peer1 invoke channelcode
curl -s -X POST 
  http://localhost:4000/channels/mychannel/chaincodes/mycc 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json" 
  -d "{
    "fcn":"move",
    "args":["a","b","10"]
}"


1f0d78257600c8d22496cf44bfc258d0636df4701b908b74bd5fd4c7fee5271f
查询chaincode
curl -s -X GET 
  "http://localhost:4000/channels/mychannel/chaincodes/mycc?peer=peer1&fcn=query&args=%5B%22a%22%5D" 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json"

a now has 90 after the move
根据区块号码查询
curl -s -X GET 
  "http://localhost:4000/channels/mychannel/blocks/1?peer=peer1" 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json"

输出

{"header":{"number":"1","previous_hash":"0664200ce99ba01be091fb55851c0b133c03c3f4504af24933d8317944865296","data_hash":"a4a60217882efdf2db7a1097d5455d14b3ab25eef38e7f12ac8cb013240abc19"},"data":{"data":[{"signature":{"type":"Buffer","data":[48,68,2,32,97,85,177,47,70,144,22,46,203,89,202,86,124,35,83,222,85,34,54,140,247,96,10,139,119,64,22,151,29,250,66,140,2,32,87,35,167,167,75,143,248,48,50,250,47,183,220,69,48,102,235,125,102,107,75,148,60,67,31,222,117,54,60,29,43,2]},"payload":{"header":{"channel_header":{"type":3,"version":1,"timestamp":"Thu Feb 01 2018 10:11:16 GMT+0800 (CST)","channel_id":"mychannel","tx_id":"246179ff7cceaabdc34811dafdb15b07a7b84270375f0e51bf34e8ded8f9b35d","epoch":"0","extension":{"type":"Buffer","data":[18,6,18,4,108,115,99,99]},"typeString":"ENDORSER_TRANSACTION"},"signature_header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----
MIICGTCCAb+gAwIBAgIQKKKdQSzsDoUYn/LPAuRWGTAKBggqhkjOPQQDAjBzMQsw
CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
b3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla
MFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
YW4gRnJhbmNpc2NvMR8wHQYDVQQDDBZBZG1pbkBvcmcxLmV4YW1wbGUuY29tMFkw
EwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAECmbzUDozIrLKjp3OAzItSG7m7Flw76rT
8VO8E6otlCwxKtBRkPpZL7norC3NsjyE339J5O4pXCqhIApQyRRsRqNNMEswDgYD
VR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE
yKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDSAAwRQIhALT02pc/
yfE/4wUJfUBQ32GifUEh8JktAXzL/73S0rjYAiACNSp6zAQBX9SBxTOGMk4cGGAy
CKqf8052NVUs2CvPzA==
-----END CERTIFICATE-----
"},"nonce":{"type":"Buffer","data":[253,239,177,254,29,27,96,216,175,70,231,198,247,91,170,113,52,220,37,224,111,172,59,126]}}},"data":{"actions":[{"header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----
MIICGTCCAb+gAwIBAgIQKKKdQSzsDoUYn/LPAuRWGTAKBggqhkjOPQQDAjBzMQsw
CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
b3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla
MFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
YW4gRnJhbmNpc2NvMR8wHQYDVQQDDBZBZG1pbkBvcmcxLmV4YW1wbGUuY29tMFkw
EwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAECmbzUDozIrLKjp3OAzItSG7m7Flw76rT
8VO8E6otlCwxKtBRkPpZL7norC3NsjyE339J5O4pXCqhIApQyRRsRqNNMEswDgYD
VR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE
yKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDSAAwRQIhALT02pc/
yfE/4wUJfUBQ32GifUEh8JktAXzL/73S0rjYAiACNSp6zAQBX9SBxTOGMk4cGGAy
CKqf8052NVUs2CvPzA==
-----END CERTIFICATE-----
"},"nonce":{"type":"Buffer","data":[253,239,177,254,29,27,96,216,175,70,231,198,247,91,170,113,52,220,37,224,111,172,59,126]}},"payload":{"chaincode_proposal_payload":{"input":{"type":"Buffer","data":[10,73,8,1,18,6,18,4,108,115,99,99,26,61,10,6,100,101,112,108,111,121,10,9,109,121,99,104,97,110,110,101,108,10,40,10,38,8,1,18,10,18,4,109,121,99,99,26,2,118,48,26,22,10,4,105,110,105,116,10,1,97,10,3,49,48,48,10,1,98,10,3,50,48,48]}},"action":{"proposal_response_payload":{"proposal_hash":"6f09f4dbadb24adcafe38425cfc5f103fb79330513e5267fda8f0b2a56882aad","extension":{"results":{"data_model":0,"ns_rwset":[{"namespace":"lscc","rwset":{"reads":[{"key":"mycc","version":null}],"range_queries_info":[],"writes":[{"key":"mycc","is_delete":false,"value":"
u0004myccu0012u0002v0u001au0004escc"u0004vscc*(u0012fu0012
u0001u0012u0002u0000u0012u0002u0001u001au000bu0012	
u0007Org1MSPu001au000bu0012	
u0007Org2MSP2D
 ����ϧ�i?v��OCjˢ��"��Hqu001e��Gbu0012 *PI�w�u000fjL5x6^�E=�)ˡF��	u0019u0015��C5u00115: ���ԣV��k����ر���u000b>z!F�P"�+΋I�B,u0012fu0012
u0001u0012u0002u0000u0012u0002u0001u001a
u0012u000b
u0007Org1MSPu0010u0001u001a
u0012u000b
u0007Org2MSPu0010u0001"}]}},{"namespace":"mycc","rwset":{"reads":[],"range_queries_info":[],"writes":[{"key":"a","is_delete":false,"value":"100"},{"key":"b","is_delete":false,"value":"200"}]}}]},"events":{"chaincode_id":"","tx_id":"","event_name":"","payload":{"type":"Buffer","data":[]}},"response":{"status":200,"message":"","payload":"
u0004myccu0012u0002v0u001au0004escc"u0004vscc*(u0012fu0012
u0001u0012u0002u0000u0012u0002u0001u001au000bu0012	
u0007Org1MSPu001au000bu0012	
u0007Org2MSP2D
 ����ϧ�i?v��OCjˢ��"��Hqu001e��Gbu0012 *PI�w�u000fjL5x6^�E=�)ˡF��	u0019u0015��C5u00115: ���ԣV��k����ر���u000b>z!F�P"�+΋I�B,u0012fu0012
u0001u0012u0002u0000u0012u0002u0001u001a
u0012u000b
u0007Org1MSPu0010u0001u001a
u0012u000b
u0007Org2MSPu0010u0001"},"chaincode_id":{"path":"","name":"lscc","version":"1.0.6-snapshot-78e18d1"}}},"endorsements":[{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----
MIICGDCCAb+gAwIBAgIQPcMFFEB/vq6mEL6vXV7aUTAKBggqhkjOPQQDAjBzMQsw
CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
b3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla
MFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
YW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw
EwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzS9k2gCKHcat8Wj4T2nB1uyC8R2zg3um
xdTL7nmgFWp0uyCCbQQxD/VS+8R/3DNvEFkvzhcjc9NU/nRqMirpLqNNMEswDgYD
VR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE
yKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDRwAwRAIgHBdxbHUG
rFUzKPX9UmmN3SwigWcRUREUy/GTb3hDIAsCIEF1BxTqv8ilQYE8ql0wJL4mTber
HE6DFYvvBCUnicUh
-----END -----
"},"signature":{"type":"Buffer","data":[48,69,2,33,0,221,89,84,65,198,9,182,185,236,115,245,0,126,215,99,202,175,124,30,19,85,188,93,198,107,180,1,120,31,49,151,223,2,32,13,83,183,254,68,247,90,114,116,100,211,167,147,77,7,114,143,119,1,189,118,59,212,226,6,154,183,85,0,17,205,98]}},{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----
MIICGjCCAcCgAwIBAgIRAI+BBtEBvpOqhfRZZH7eV/YwCgYIKoZIzj0EAwIwczEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh
Lm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNjIzMTIzMzE5WhcNMjcwNjIxMTIzMzE5
WjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
U2FuIEZyYW5jaXNjbzEfMB0GA1UEAxMWcGVlcjEub3JnMS5leGFtcGxlLmNvbTBZ
MBMGByqGSM49AgEGCCqGSM49AwEHA0IABCnT04ltvjsgiZVuCGLsRYzEiCTJZlZw
h3HT/273B3NkWA7wrlyK7FfAanIyexuR1UI9m4+YKNqFG6cgYnf8MsejTTBLMA4G
A1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIA5ykiTos/MX
hMipPFuO9vTByR2ebld8RcMxY2Cf5AARMAoGCCqGSM49BAMCA0gAMEUCIQCSRdWm
i4IgVUajvzWVxyE/wi7n617pVqS4+nJ7gbTRjQIgefzBwS+bkNhPc3/rktySFLRC
WMnq87KyqMLc6iRaJx0=
-----END -----
"},"signature":{"type":"Buffer","data":[48,69,2,33,0,199,231,180,29,203,81,149,143,127,66,155,2,123,159,37,68,254,129,236,250,170,122,254,193,94,166,237,95,180,197,25,111,2,32,36,33,111,115,225,188,10,156,46,238,37,118,76,149,185,157,167,63,115,123,150,114,58,226,65,26,118,66,97,211,208,43]}}]}}}]}}}]},"metadata":{"metadata":[{"value":"","signatures":[{"signature_header":{"creator":{"Mspid":"OrdererMSP","IdBytes":"-----BEGIN -----
MIICDTCCAbOgAwIBAgIRALFafJiTFN/47AvAGfvj1ZEwCgYIKoZIzj0EAwIwaTEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRcwFQYDVQQDEw5jYS5leGFt
cGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTlaMFgxCzAJBgNV
BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
c2NvMRwwGgYDVQQDExNvcmRlcmVyLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYI
KoZIzj0DAQcDQgAEYtguLKFBLLc0VSwyPHHHNe76HH71oOXK6wun8Y/5vtMawPZ/
WTm/vBVUWdfNlzc9eA28aXx6zBAB8iRm16EeU6NNMEswDgYDVR0PAQH/BAQDAgeA
MAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDUbM8OlDbBvDtuK/gM2yAsSUNgT5
XHLuD/g50+wwBxkwCgYIKoZIzj0EAwIDSAAwRQIhANJuEGHBftrtlWgie9zgc60J
/XVytPN/D0rPlkMV17n7AiBBbStggGBfFYcQ2LhDhcKut8nScJ2OFrt+dJSdJbod
7A==
-----END -----
"},"nonce":{"type":"Buffer","data":[23,194,242,143,221,90,72,166,151,0,135,49,136,64,157,226,109,131,36,120,189,18,37,195]}},"signature":{"type":"Buffer","data":[48,69,2,33,0,194,79,89,128,252,88,27,94,211,26,101,215,142,220,38,84,189,91,165,231,173,88,107,234,96,50,238,167,76,69,71,96,2,32,25,181,163,165,231,163,133,128,75,193,230,133,65,115,154,244,141,14,119,240,46,15,65,198,101,53,130,111,12,3,74,59]}}]},{"value":{"index":"0"},"signatures":[{"signature_header":{"creator":{"Mspid":"OrdererMSP","IdBytes":"-----BEGIN -----
MIICDTCCAbOgAwIBAgIRALFafJiTFN/47AvAGfvj1ZEwCgYIKoZIzj0EAwIwaTEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xFDASBgNVBAoTC2V4YW1wbGUuY29tMRcwFQYDVQQDEw5jYS5leGFt
cGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTlaMFgxCzAJBgNV
BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
c2NvMRwwGgYDVQQDExNvcmRlcmVyLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYI
KoZIzj0DAQcDQgAEYtguLKFBLLc0VSwyPHHHNe76HH71oOXK6wun8Y/5vtMawPZ/
WTm/vBVUWdfNlzc9eA28aXx6zBAB8iRm16EeU6NNMEswDgYDVR0PAQH/BAQDAgeA
MAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDUbM8OlDbBvDtuK/gM2yAsSUNgT5
XHLuD/g50+wwBxkwCgYIKoZIzj0EAwIDSAAwRQIhANJuEGHBftrtlWgie9zgc60J
/XVytPN/D0rPlkMV17n7AiBBbStggGBfFYcQ2LhDhcKut8nScJ2OFrt+dJSdJbod
7A==
-----END -----
"},"nonce":{"type":"Buffer","data":[69,152,26,2,158,39,123,106,137,249,50,166,48,82,137,238,62,45,137,151,93,94,54,208]}},"signature":{"type":"Buffer","data":[48,68,2,32,37,123,47,42,244,219,141,199,92,221,204,87,96,3,205,200,146,23,241,119,5,64,47,216,169,95,17,48,196,190,205,28,2,32,105,8,79,181,140,29,230,153,118,242,153,49,229,116,244,129,84,2,28,242,124,151,59,179,66,113,35,183,114,112,4,176]}}]},[0]]}}[root@block-hubin-104 balance-transfer]
根据transactionID查询交易

transactions/后的字符为invoke返回的transactionID

curl -s -X GET http://localhost:4000/channels/mychannel/transactions/1f0d78257600c8d22496cf44bfc258d0636df4701b908b74bd5fd4c7fee5271f?peer=peer1 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json"

输出

{"validationCode":0,"transactionEnvelope":{"signature":{"type":"Buffer","data":[48,69,2,33,0,185,163,80,179,245,219,65,184,204,163,115,254,248,52,65,176,193,29,69,88,248,66,171,180,44,148,52,220,12,16,95,186,2,32,66,37,236,145,58,181,14,60,224,129,23,254,51,113,208,91,159,215,73,48,249,128,243,142,241,123,243,183,38,134,165,28]},"payload":{"header":{"channel_header":{"type":3,"version":1,"timestamp":"Thu Feb 01 2018 10:13:49 GMT+0800 (CST)","channel_id":"mychannel","tx_id":"1f0d78257600c8d22496cf44bfc258d0636df4701b908b74bd5fd4c7fee5271f","epoch":"0","extension":{"type":"Buffer","data":[18,6,18,4,109,121,99,99]},"typeString":"ENDORSER_TRANSACTION"},"signature_header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----
MIIB8DCCAZegAwIBAgIUFJ+NHGFxRg73T+233rHsujLqMyEwCgYIKoZIzj0EAwIw
czELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT
E2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwMTMxMTExMDAwWhcNMTkwMTMxMTEx
MDAwWjAQMQ4wDAYDVQQDEwVhZG1pbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA
BPYeeBj5ssSFu6H4qvA4WzHyV1Utss0GJF2PGTP6lH5+tJN8d/7YZJmykUXIZoU1
AcYxAH4QbLPVwk1/En98rsmjbDBqMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8E
AjAAMB0GA1UdDgQWBBQobo0nZvSn6whePOc+1dryxiGPhjArBgNVHSMEJDAigCAO
cpIk6LPzF4TIqTxbjvb0wckdnm5XfEXDMWNgn+QAETAKBggqhkjOPQQDAgNHADBE
AiB4zornAF0Qt1nRYtzJq5AN8DDGN9sl6vwuMg9LmowMkAIgdcxa8TUIXy5aRNoU
UXR4U2CzKiNlQQX/HXsJIDgx9DI=
-----END CERTIFICATE-----
"},"nonce":{"type":"Buffer","data":[20,39,188,238,82,73,112,68,30,209,206,164,185,253,245,103,138,255,175,176,80,102,210,76]}}},"data":{"actions":[{"header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----
MIIB8DCCAZegAwIBAgIUFJ+NHGFxRg73T+233rHsujLqMyEwCgYIKoZIzj0EAwIw
czELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh
biBGcmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMT
E2NhLm9yZzEuZXhhbXBsZS5jb20wHhcNMTgwMTMxMTExMDAwWhcNMTkwMTMxMTEx
MDAwWjAQMQ4wDAYDVQQDEwVhZG1pbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA
BPYeeBj5ssSFu6H4qvA4WzHyV1Utss0GJF2PGTP6lH5+tJN8d/7YZJmykUXIZoU1
AcYxAH4QbLPVwk1/En98rsmjbDBqMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8E
AjAAMB0GA1UdDgQWBBQobo0nZvSn6whePOc+1dryxiGPhjArBgNVHSMEJDAigCAO
cpIk6LPzF4TIqTxbjvb0wckdnm5XfEXDMWNgn+QAETAKBggqhkjOPQQDAgNHADBE
AiB4zornAF0Qt1nRYtzJq5AN8DDGN9sl6vwuMg9LmowMkAIgdcxa8TUIXy5aRNoU
UXR4U2CzKiNlQQX/HXsJIDgx9DI=
-----END CERTIFICATE-----
"},"nonce":{"type":"Buffer","data":[20,39,188,238,82,73,112,68,30,209,206,164,185,253,245,103,138,255,175,176,80,102,210,76]}},"payload":{"chaincode_proposal_payload":{"input":{"type":"Buffer","data":[10,28,8,1,18,6,18,4,109,121,99,99,26,16,10,4,109,111,118,101,10,1,97,10,1,98,10,2,49,48]}},"action":{"proposal_response_payload":{"proposal_hash":"d2ea3d2fa713c24eaaa2513a47d85d004877004fa0acfa11cee1f0106611a6ea","extension":{"results":{"data_model":0,"ns_rwset":[{"namespace":"lscc","rwset":{"reads":[{"key":"mycc","version":{"block_num":"1","tx_num":"0"}}],"range_queries_info":[],"writes":[]}},{"namespace":"mycc","rwset":{"reads":[{"key":"a","version":{"block_num":"1","tx_num":"0"}},{"key":"b","version":{"block_num":"1","tx_num":"0"}}],"range_queries_info":[],"writes":[{"key":"a","is_delete":false,"value":"90"},{"key":"b","is_delete":false,"value":"210"}]}}]},"events":{"chaincode_id":"","tx_id":"","event_name":"","payload":{"type":"Buffer","data":[]}},"response":{"status":200,"message":"","payload":""},"chaincode_id":{"path":"","name":"mycc","version":"v0"}}},"endorsements":[{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----
MIICGDCCAb+gAwIBAgIQPcMFFEB/vq6mEL6vXV7aUTAKBggqhkjOPQQDAjBzMQsw
CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
b3JnMS5leGFtcGxlLmNvbTAeFw0xNzA2MjMxMjMzMTlaFw0yNzA2MjExMjMzMTla
MFsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
YW4gRnJhbmNpc2NvMR8wHQYDVQQDExZwZWVyMC5vcmcxLmV4YW1wbGUuY29tMFkw
EwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzS9k2gCKHcat8Wj4T2nB1uyC8R2zg3um
xdTL7nmgFWp0uyCCbQQxD/VS+8R/3DNvEFkvzhcjc9NU/nRqMirpLqNNMEswDgYD
VR0PAQH/BAQDAgeAMAwGA1UdEwEB/wQCMAAwKwYDVR0jBCQwIoAgDnKSJOiz8xeE
yKk8W4729MHJHZ5uV3xFwzFjYJ/kABEwCgYIKoZIzj0EAwIDRwAwRAIgHBdxbHUG
rFUzKPX9UmmN3SwigWcRUREUy/GTb3hDIAsCIEF1BxTqv8ilQYE8ql0wJL4mTber
HE6DFYvvBCUnicUh
-----END -----
"},"signature":{"type":"Buffer","data":[48,69,2,33,0,249,84,44,238,169,234,246,112,83,154,147,200,71,174,225,91,223,98,228,210,51,247,134,221,199,145,133,220,190,176,85,153,2,32,45,141,102,182,9,197,12,56,249,79,249,34,173,165,15,112,74,169,90,92,172,202,10,140,41,214,82,28,112,175,31,135]}},{"endorser":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN -----
MIICGjCCAcCgAwIBAgIRAI+BBtEBvpOqhfRZZH7eV/YwCgYIKoZIzj0EAwIwczEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xGTAXBgNVBAoTEG9yZzEuZXhhbXBsZS5jb20xHDAaBgNVBAMTE2Nh
Lm9yZzEuZXhhbXBsZS5jb20wHhcNMTcwNjIzMTIzMzE5WhcNMjcwNjIxMTIzMzE5
WjBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMN
U2FuIEZyYW5jaXNjbzEfMB0GA1UEAxMWcGVlcjEub3JnMS5leGFtcGxlLmNvbTBZ
MBMGByqGSM49AgEGCCqGSM49AwEHA0IABCnT04ltvjsgiZVuCGLsRYzEiCTJZlZw
h3HT/273B3NkWA7wrlyK7FfAanIyexuR1UI9m4+YKNqFG6cgYnf8MsejTTBLMA4G
A1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsGA1UdIwQkMCKAIA5ykiTos/MX
hMipPFuO9vTByR2ebld8RcMxY2Cf5AARMAoGCCqGSM49BAMCA0gAMEUCIQCSRdWm
i4IgVUajvzWVxyE/wi7n617pVqS4+nJ7gbTRjQIgefzBwS+bkNhPc3/rktySFLRC
WMnq87KyqMLc6iRaJx0=
-----END -----
"},"signature":{"type":"Buffer","data":[48,69,2,33,0,234,123,146,118,155,128,29,31,176,19,80,142,135,211,198,228,189,121,250,254,79,223,113,85,238,86,197,34,27,233,216,234,2,32,15,29,170,18,231,45,127,148,95,146,50,210,254,111,226,145,171,19,237,10,168,26,226,162,220,50,112,9,98,61,178,15]}}]}}}]}}}}
获取ChainInfo
curl -s -X GET 
  "http://localhost:4000/channels/mychannel?peer=peer1" 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json"

输出

{"height":{"low":3,"high":0,"unsigned":true},"currentBlockHash":{"buffer":{"type":"Buffer","data":[8,3,18,32,197,45,10,52,42,69,183,241,206,187,72,115,41,197,25,220,101,13,133,178,192,130,203,49,150,130,199,51,224,114,147,181,26,32,6,34,252,157,31,20,133,0,176,165,122,234,70,41,158,181,5,225,90,55,187,181,60,108,138,19,28,23,92,193,58,216]},"offset":4,"markedOffset":-1,"limit":36,"littleEndian":true,"noAssert":false},"previousBlockHash":{"buffer":{"type":"Buffer","data":[8,3,18,32,197,45,10,52,42,69,183,241,206,187,72,115,41,197,25,220,101,13,133,178,192,130,203,49,150,130,199,51,224,114,147,181,26,32,6,34,252,157,31,20,133,0,176,165,122,234,70,41,158,181,5,225,90,55,187,181,60,108,138,19,28,23,92,193,58,216]},"offset":38,"markedOffset":-1,"limit":70,"littleEndian":true,"noAssert":false}}
获取已安装的chaincode
curl -s -X GET 
  "http://localhost:4000/chaincodes?peer=peer1&type=installed" 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json"

["name: mycc, version: v0, path: github.com/example_cc"]
获取已实例化的chaincode
curl -s -X GET 
  "http://localhost:4000/chaincodes?peer=peer1&type=instantiated" 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json"

["name: mycc, version: v0, path: github.com/example_cc"]
获取channels
curl -s -X GET 
  "http://localhost:4000/channels?peer=peer1" 
  -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTc0ODY2ODAsInVzZXJuYW1lIjoiQmFycnkiLCJvcmdOYW1lIjoib3JnMSIsImlhdCI6MTUxNzQ1MDY4MH0.Ha6l8k5chOhBmwkiIpYVw--fW4ny-KUhH4cG14-kZLw" 
  -H "content-type: application/json"

{"channels":[{"channel_id":"mychannel"}]}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/23971.html

相关文章

  • Fabric学习笔记(四) - Fabric CA简单实用

    摘要:前言本文严重参考官方文档并去除复杂部分和相应解释基本只覆盖操作流程下载下载镜像启动进入镜像查询并启动已启动注册实体注册修改下的配置文件注册新成员 前言 本文严重参考官方文档,并去除复杂部分和相应解释,基本只覆盖操作流程 下载fabric-ca go get -u github.com/hyperledger/fabric-ca/cmd/... 下载fabric-ca镜像 docker ...

    ninefive 评论0 收藏0
  • Fabric学习笔记(三) - Fabric v1.0.5 使用CouchDB

    摘要:前言默认的为功能有限现在把它该归它提供了丰富的查询功能拉取使用启动利用上节教程使所有添加至改用安装请把环境变量都改为的实例化创建一些并交易 前言 默认的state DB为goleveldb,功能有限,现在把它该归CouchDB.它提供了丰富的查询功能 拉取coundb image docker pull hyperledger/fabric-couchdb:x86_64-1.0.5 d...

    liangzai_cool 评论0 收藏0
  • Fabric学习笔记(二) - Docker下手工启动Fabric v1.0.5网络

    摘要:前言安装笔记中的是一站式的运行例子具体做了什么我们这里一步一步分开来看参考资料网络拓扑生成组织关系和身份证书设置环境变量检查环境变量的生成确保自己在目录下生成密钥文件查看生成的密钥目录生成服务启动区块设 前言 Fabric v1.0.5安装笔记 中的network_setup.sh up是一站式的运行,e 2e cli例子.具体做了什么,我们这里一步一步分开来看 参考资料: end-...

    ad6623 评论0 收藏0
  • 基于ubuntu16.04部署IBM开源区块链项目-弹珠资产管理(Marbles)

    摘要:协议的细节由一个名为的处理。运行下面的脚本来让所有的事情都发生一两分钟后,命令提示符将返回运行结果如下图所示现在运行该命令查看当前正在运行的容器。 showImg(https://segmentfault.com/img/bVbazHF?w=709&h=159); 前言 本教程基本上是对Marbles项目的翻译过程. 如果英文比较好的话,建议根据官方操作说明,一步步进行环境部署。当然你...

    voidking 评论0 收藏0
  • Fabric学习笔记(七) - fabric-sdk-java End2endIT运行

    摘要:目的因最熟悉故最后还是拿做突破口学习本文只运行功能以后具体在分析运行环境网络远程本地远程下载运行网络核查网络是否启动成功这一步我遇到的问题是未启动成功原因在于中这 目的 因最熟悉java,故最后还是拿java做突破口学习sdk,本文只运行demo,sdk功能以后具体在分析. 运行环境 Fabric网络 远程Centos Fabric-sdk-java 本地MacOs Intellij...

    mzlogin 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<