From 6dc5ce503bdd54d8c48ffead610d19d2993ab3db Mon Sep 17 00:00:00 2001 From: sebastianpaulp Date: Wed, 24 Oct 2018 21:23:24 +0530 Subject: [PATCH] [FAB-12587] Fix for Query Block by block hash API Block Query by hash Fixed in balance transfer app. Change-Id: Iad5c0af657e7359ee787e1f939a6695d470da1cd Signed-off-by: sebastianpaulp --- balance-transfer/app/query.js | 2 +- balance-transfer/testAPIs.sh | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/balance-transfer/app/query.js b/balance-transfer/app/query.js index 3ff950229d..11a5b7a261 100644 --- a/balance-transfer/app/query.js +++ b/balance-transfer/app/query.js @@ -115,7 +115,7 @@ var getBlockByHash = async function(peer, channelName, hash, username, org_name) throw new Error(message); } - let response_payload = await channel.queryBlockByHash(Buffer.from(hash), peer); + let response_payload = await channel.queryBlockByHash(Buffer.from(hash,'hex'), peer); if (response_payload) { logger.debug(response_payload); return response_payload; diff --git a/balance-transfer/testAPIs.sh b/balance-transfer/testAPIs.sh index e48ec039d3..a8ec82bc9d 100755 --- a/balance-transfer/testAPIs.sh +++ b/balance-transfer/testAPIs.sh @@ -209,11 +209,13 @@ echo echo "GET query Block by blockNumber" echo -curl -s -X GET \ +BLOCK_INFO=$(curl -s -X GET \ "http://localhost:4000/channels/mychannel/blocks/1?peer=peer0.org1.example.com" \ -H "authorization: Bearer $ORG1_TOKEN" \ - -H "content-type: application/json" -echo + -H "content-type: application/json") +echo $BLOCK_INFO +# Assign previvious block hash to HASH +HASH=$(echo $BLOCK_INFO | jq -r ".header.previous_hash") echo echo "GET query Transaction by TransactionID" @@ -224,20 +226,17 @@ curl -s -X GET http://localhost:4000/channels/mychannel/transactions/$TRX_ID?pee echo echo -############################################################################ -### TODO: What to pass to fetch the Block information -############################################################################ -#echo "GET query Block by Hash" -#echo -#hash=???? -#curl -s -X GET \ -# "http://localhost:4000/channels/mychannel/blocks?hash=$hash&peer=peer1" \ -# -H "authorization: Bearer $ORG1_TOKEN" \ -# -H "cache-control: no-cache" \ -# -H "content-type: application/json" \ -# -H "x-access-token: $ORG1_TOKEN" -#echo -#echo + +echo "GET query Block by Hash - Hash is $HASH" +echo +curl -s -X GET \ + "http://localhost:4000/channels/mychannel/blocks?hash=$HASH&peer=peer0.org1.example.com" \ + -H "authorization: Bearer $ORG1_TOKEN" \ + -H "cache-control: no-cache" \ + -H "content-type: application/json" \ + -H "x-access-token: $ORG1_TOKEN" +echo +echo echo "GET query ChainInfo" echo