From 40bf742acaaa12afb0f401adedc784a0c6ebad10 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Mon, 8 Jul 2024 23:32:37 +0300 Subject: Refactoring and bugfixes --- bin/ak-find-latest-mined-sblock | 66 ++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/bin/ak-find-latest-mined-sblock b/bin/ak-find-latest-mined-sblock index c91197e..dda1196 100755 --- a/bin/ak-find-latest-mined-sblock +++ b/bin/ak-find-latest-mined-sblock @@ -51,33 +51,45 @@ lookfor(){ fi } -templistblock="$(_ak_make_temp_file)" -find . -type f | sed 's/^\.\/000/000/g' | grep '^000' | sort > $templistblock -while IFS="" read -r p || [ -n "$p" ] -do -# if [ ! "$p" = "" ] && [ ! "$p" = "tmplistblock" ] - if [ "$(echo $p | tr -d '\n' | wc -c)" = 128 ] +_ak_sblock_get_latest_from_haystack_of_sblocks(){ + templistblock="$(_ak_make_temp_file)" + find $AK_MINEDBLOCKSDIR -maxdepth 1 -type f | while read line + do + basename "${line}" >> $templistblock + done + if [ "$(cat $templistblock | wc -l)" -ne 0 ] then - filename="$(basename $p)" - _ak_log_info "Investigating $filename..." - export CHAIN_PARENT="$filename" - counters[$CHAIN_PARENT]=1 - lookfor "$filename" + while IFS="" read -r p || [ -n "$p" ] + do + # if [ ! "$p" = "" ] && [ ! "$p" = "tmplistblock" ] + if [ "$(echo $p | tr -d '\n' | wc -c)" = 128 ] + then + filename="$(basename $p)" + _ak_log_info "Investigating $filename..." + export CHAIN_PARENT="$filename" + counters[$CHAIN_PARENT]=1 + lookfor "$filename" + else + _ak_log_warning "Nothing to do with $filename" + fi + done < $templistblock + rm $templistblock + max=0 + max_holder=0 + for value in "${!counters[@]}" + do + # echo "${value} : ${counters[${value}]}" + if [ ${counters[${value}]} -gt $max ] + then + max="${counters[${value}]}" + max_holder="${value}" + _ak_log_info "New MAX $max on $max_holder" + fi + done else - _ak_log_warning "Nothing to do with $filename" + max_holder="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" fi -done < $templistblock -rm $templistblock -max=0 -max_holder=0 -for value in "${!counters[@]}" -do - # echo "${value} : ${counters[${value}]}" - if [ ${counters[${value}]} -gt $max ] - then - max="${counters[${value}]}" - max_holder="${value}" - _ak_log_info "New MAX $max on $max_holder" - fi -done -echo '{"latest_block":"'$max_holder'"}' + echo -n '{"latest_block":"'$max_holder'"}' | tee $AK_WORKDIR/schain.latest +} + +_ak_sblock_get_latest_from_haystack_of_sblocks $1 -- cgit v1.2.3