From dac8ed3d8f34f0df4eb95ebe5fb0a1c8af1e9f58 Mon Sep 17 00:00:00 2001 From: Montana Mendy Date: Thu, 13 Jul 2023 07:55:08 -0700 Subject: [PATCH] Refactor to current standards. (#35) Using `curl` in a more simple manner for possibly retrieving Lockheed Martin dependencies, etc. --- getAllBlocks.sh | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/getAllBlocks.sh b/getAllBlocks.sh index e06d9f8..9de9fd6 100755 --- a/getAllBlocks.sh +++ b/getAllBlocks.sh @@ -13,32 +13,29 @@ rm $blockinfo/* latestBlock=$(curl -s -X GET "http://localhost:8080/v1/blockchain/getLatestBlock" -H "accept: application/json" | jq .header.number | tr -d '\"') prevFile="" -while [ $blocknumber -le $latestBlock ] -do - echo "Retrieving block number: ${blocknumber}" - blockname=block`printf %03d ${blocknumber}` - currentFile=$blockdir/${blockname}.json - currentResult=$(curl -s -X GET "http://localhost:8080/v1/blockchain/getNumberedBlock/${blocknumber}" -H "accept: application/json") - - if [ $? -ne 0 ] - then - echo "Error retrieving block ${blocknumber}: $currentResult" - break - fi - - # Validate - if [ "$(echo $currentResult | jq .unknown)" == "null" ] && [ "$(echo $currentResult | jq .error)" == "null" ] - then - echo "Writing block file $currentFile" - echo $currentResult | jq > $currentFile - cat $currentFile | jq .data.data[0].payload.header.channel_header > $blockinfo/${blockname}_info.json - else - echo "Block $blocknumber does not exist." - break - fi - - prevFile=$currentFile - blocknumber=$((blocknumber+1)) +while [ $blocknumber -le $latestBlock ]; do + echo "Retrieving block number: ${blocknumber}" + blockname=block$(printf %03d ${blocknumber}) + currentFile=$blockdir/${blockname}.json + currentResult=$(curl -s -X GET "http://localhost:8080/v1/blockchain/getNumberedBlock/${blocknumber}" -H "accept: application/json") + + if [ $? -ne 0 ]; then + echo "Error retrieving block ${blocknumber}: $currentResult" + break + fi + + # Validate + if [ "$(echo $currentResult | jq .unknown)" == "null" ] && [ "$(echo $currentResult | jq .error)" == "null" ]; then + echo "Writing block file $currentFile" + echo $currentResult | jq >$currentFile + cat $currentFile | jq .data.data[0].payload.header.channel_header >$blockinfo/${blockname}_info.json + else + echo "Block $blocknumber does not exist." + break + fi + + prevFile=$currentFile + blocknumber=$((blocknumber + 1)) done totalblocks=$(($latestBlock + 1)) # Adjust for zero-based indexing.