diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-06-30 22:39:50 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-06-30 22:39:50 +0300 |
commit | de53c55383ed07e0b65f69d33f5284a31d791664 (patch) | |
tree | f1e426c88a5d0a48ca463eccd21c1d12524d8f3a /lib/_ak_schain | |
parent | 9531bcdffff4e44e8aadb000f0b577d59a32ea3f (diff) | |
download | arching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.tar.gz arching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.tar.bz2 arching-kaos-tools-de53c55383ed07e0b65f69d33f5284a31d791664.zip |
Refactoring
Diffstat (limited to 'lib/_ak_schain')
-rwxr-xr-x | lib/_ak_schain | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/_ak_schain b/lib/_ak_schain new file mode 100755 index 0000000..2ff56eb --- /dev/null +++ b/lib/_ak_schain @@ -0,0 +1,93 @@ +#!/bin/bash +AK_SCHAINSDIR=$AK_WORKDIR/schains +GENESIS="00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + +_ak_schain_latest_cached(){ + if [ ! -f $AK_WORKDIR/schain.latest ] + then + ak-find-latest-mined-sblock > $AK_WORKDIR/schain.latest + fi + cat $AK_WORKDIR/schain.latest +} + +_ak_schain_tidy(){ + SLATEST=$(ak-find-latest-mined-sblock | jq -r '.latest_block') + if [ ! -d $AK_SCHAINSDIR ] + then + mkdir $AK_SCHAINSDIR + fi +} + +_ak_schain_block_latest_block_hash(){ + ak-find-latest-mined-sblock | jq -r '.latest_block' +} + +_ak_schain_crawl(){ + if [ ! -z $1 ] && [ -n "$1" ] + then + CUR_TARGET="$1" + else + _ak_log_warning "No next target found. So long for $1" + exit 1 + fi + + if [ $counter -eq 0 ] + then + echo '[' + counter=$(($counter + 1)) + else + _ak_log_info "Counter: $counter, LIMIT_ENABLED: $LIMIT_ENABLED, LIMIT: $LIMIT" + if [ "$LIMIT_ENABLED" == "yes" ] + then + if [ $counter -eq $LIMIT ] + then + echo ']' + exit 0 + fi + fi + echo ',' + counter=$(($counter + 1)) + fi + + if [ "$1" == "$GENESIS" ] + then + echo '{"genesis":"genesis"}' | jq + echo ']' + _ak_log_warning "Looks like genesis. Exiting with 0" + exit 0 + fi + + if [ ! -f "$AK_MINEDBLOCKSDIR/$CUR_TARGET" ] + then + _ak_log_warning "Could not find $CUR_TARGET" + else + ( echo -n '{"sblock":"'$1'",' && + ak-sblock-show $CUR_TARGET | sed -e 's/^{//g') | jq + NEXT_TARGET="$(ak-sblock-show $CUR_TARGET | jq -r '.previous')" + _ak_log_info "Found previous: $NEXT_TARGET" + _ak_schain_crawl "$NEXT_TARGET" + fi +} + +_ak_schain_crawl_interface(){ + LIMIT_ENABLED="no" + LIMIT=0 + counter=0 + if [ -z $1 ] || [ ! -n "$1" ] + then + _ak_schain_crawl `_ak_schain_block_latest_block_hash` + else + while [ "$#" ]; do + case "$1" in + -l) + LIMIT_ENABLED="yes" + LIMIT=$2 + shift 2 + ;; + *) + _ak_schain_crawl "$1" + ;; + esac + done + fi +} |