From de53c55383ed07e0b65f69d33f5284a31d791664 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Sun, 30 Jun 2024 22:39:50 +0300 Subject: Refactoring --- README | 4 +- TUTORIAL | 10 +-- api/make_cache.sh | 2 +- api/routes/getZChain/index.js | 2 +- api/tests/node_local_chain.sh | 2 +- api/validators/ZblockValidator/index.js | 2 +- api/validators/ZchainValidator/index.js | 2 +- bin/ak-config | 2 +- bin/ak-follow | 102 +++++++++++++++++++++++++----- bin/ak-following | 13 ---- bin/ak-mempool | 15 ++++- bin/ak-miner-script | 2 +- bin/ak-profile | 58 ++++++++--------- bin/ak-schain | 28 +++++++++ bin/ak-schain-latest-cached | 9 --- bin/ak-unfollow | 30 --------- bin/ak-zchain | 10 ++- lib/_ak_network | 5 -- lib/_ak_schain | 93 +++++++++++++++++++++++++++ lib/_ak_zblock | 2 +- lib/_ak_zchain | 107 +++++++++++++++++++++++++++++--- modules/mixtapes/lib.sh | 4 +- modules/news/lib.sh | 8 +-- 23 files changed, 379 insertions(+), 133 deletions(-) delete mode 100755 bin/ak-following create mode 100755 bin/ak-schain delete mode 100755 bin/ak-schain-latest-cached delete mode 100755 bin/ak-unfollow create mode 100755 lib/_ak_schain diff --git a/README b/README index 7ac9332..6b4771a 100644 --- a/README +++ b/README @@ -37,7 +37,7 @@ Arching Kaos and using it. Generic tools: - `ak` - The tools wrapper -- `ak enter` - Can be used to crawl zchains. +- `ak zchain --crawl` - Can be used to crawl zchains. - `ak zchain --rebase` - Can be used to rebase your zchain to a previous zblock. - `ak zchain --reset` - Can be used to reset your zchain to zgenesis. @@ -343,6 +343,6 @@ tools you want. Example: ``` console -AK_DEBUG="yes"; ak enter -l 1 +AK_DEBUG="yes"; ak zchain --crawl -l 1 ``` diff --git a/TUTORIAL b/TUTORIAL index c22ba73..a720ef6 100644 --- a/TUTORIAL +++ b/TUTORIAL @@ -28,17 +28,17 @@ After setting up your nickname, you can see that addition by crawling your chain like this: ```console -$ ak enter +$ ak zchain --crawl ``` Most of the commands come with a `-h` and/or `--help` flags that will provide you with details on how to use each command. For example, the help message that -would appear for `ak enter -h` would look like this: +would appear for `ak zchain --crawl -h` would look like this: ``` -ak-enter - Crawl an arching kaos chain +ak zchain --crawl - Crawl an arching kaos chain ====================================== -ak-enter [-N | --no-verify] [-l | --limit ] [zblock] -ak-enter [-N | --no-verify] [-l | --limit ] -n +ak zchain --crawl [-N | --no-verify] [-l | --limit ] [zblock] +ak zchain --crawl [-N | --no-verify] [-l | --limit ] -n Usage: --help, -h Print this help and exit --chain , -n Crawl specified chain diff --git a/api/make_cache.sh b/api/make_cache.sh index 9745c88..71e80ca 100755 --- a/api/make_cache.sh +++ b/api/make_cache.sh @@ -1,5 +1,5 @@ #!/bin/bash ak-find-latest-mined-sblock > $AK_CACHEDIR/ak-find-latest-mined-sblock.json -ak-enter > $AK_CACHEDIR/ak-get-chain-minified.json +ak zchain --crawl > $AK_CACHEDIR/ak-get-chain-minified.json ak-get-zlatest > $AK_CACHEDIR/ak-get-zlatest.json diff --git a/api/routes/getZChain/index.js b/api/routes/getZChain/index.js index d30bb0a..6df2d7f 100644 --- a/api/routes/getZChain/index.js +++ b/api/routes/getZChain/index.js @@ -8,7 +8,7 @@ const { spawn } = require('child_process'); * */ module.exports = (req, res) => { - const command = spawn("ak-enter"); + const command = spawn("ak", ["zchain", "--crawl"]); response_string = ""; command.stdout.on("data", data => { response_string = response_string + data; diff --git a/api/tests/node_local_chain.sh b/api/tests/node_local_chain.sh index 4ad4c33..d1b87b4 100755 --- a/api/tests/node_local_chain.sh +++ b/api/tests/node_local_chain.sh @@ -4,7 +4,7 @@ printf '[%s]\n' "$PROGRAM" printf "TEST /zchain\n" printf "\t01:\tComparing API with CLI response..." API_RESPONSE="$(curl http://127.0.0.1:8610/v0/zchain 2>/dev/null | jq -c -M | sha512sum - | awk '{print $1 }')" -CMD_RESPONSE="$(ak-enter | jq -c -M | sha512sum - | awk '{ print $1 }')" +CMD_RESPONSE="$(ak zchain --crawl | jq -c -M | sha512sum - | awk '{ print $1 }')" if [ "$API_RESPONSE" == "$CMD_RESPONSE" ] then printf "\t\t\033[0;32mPASSED\033[0;0m" diff --git a/api/validators/ZblockValidator/index.js b/api/validators/ZblockValidator/index.js index 873a971..e3656d6 100644 --- a/api/validators/ZblockValidator/index.js +++ b/api/validators/ZblockValidator/index.js @@ -65,7 +65,7 @@ function continuethings(exitcode,sh,res){ * */ module.exports = (ch, res) => { - const command = spawn("ak-enter",[ch]); + const command = spawn("ak",["zchain", "--crawl", ch]); response_string = ""; command.stdout.on("data", data => { response_string = response_string + data; diff --git a/api/validators/ZchainValidator/index.js b/api/validators/ZchainValidator/index.js index f4080d0..80939d0 100644 --- a/api/validators/ZchainValidator/index.js +++ b/api/validators/ZchainValidator/index.js @@ -65,7 +65,7 @@ function continuethings(exitcode,sh,res){ * */ module.exports = (ch, res) => { - const command = spawn("ak-enter",["-n",ch]); + const command = spawn("ak",["zchain", "--crawl", "-n", ch]); response_string = ""; command.stdout.on("data", data => { response_string = response_string + data; diff --git a/bin/ak-config b/bin/ak-config index 24db38f..6be3f8c 100755 --- a/bin/ak-config +++ b/bin/ak-config @@ -31,7 +31,7 @@ _ak_config_show(){ _ak_gpg_key_self_export $KEY GPG_PUB_KEY=$(_ak_ipfs_add $KEY) rm $KEY - profile="$(ak-profile --index)" + profile="$(ak-profile -l)" echo ' { diff --git a/bin/ak-follow b/bin/ak-follow index c289b0f..d8461b8 100755 --- a/bin/ak-follow +++ b/bin/ak-follow @@ -1,26 +1,96 @@ #!/bin/bash -FOLLOWING="$HOME/.arching-kaos/following" -PROGRAM="$(basename $0)" +## +## You can maintain a list of friendly zchains or ids +## +## Usage: +## +## -h, --help Prints this help message +## +## -f, --follow Adds a ... to your follow list +## +## -l, --list Shows a list of your followings +## +## -u, --unfollow Unfollows a ... +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Following stuff" + source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs -if [ ! -z $1 ] -then - grep $1 $FOLLOWING - if [ $? == 0 ] +FOLLOWING="$HOME/.arching-kaos/following" + +_ak_follow_follow(){ + if [ ! -z $1 ] then - _ak_log_error "Already exists" - exit 1 + grep $1 $FOLLOWING + if [ $? == 0 ] + then + _ak_log_error "Already exists" + exit 1 + fi + echo $1 >> $FOLLOWING + IPFS=$(_ak_ipfs_add $FOLLOWING) + if [ $? -ne 0 ] + then + _ak_log_error "Addition failed" + exit 1 + fi + ak-profile set following $IPFS + exit 0 fi - echo $1 >> $FOLLOWING - IPFS=$(_ak_ipfs_add $FOLLOWING) - if [ $? != 0 ] + printf "Usage:\n\t%s \n" $PROGRAM + exit 1 +} + +_ak_follow_list(){ + if [ -f $FOLLOWING ] + then + cat $FOLLOWING + else + _ak_log_info "No following file, creating" + touch $FOLLOWING + echo "None found" + fi +} + +_ak_follow_unfollow(){ + FOLLOWING="$HOME/.arching-kaos/following" + fentries="$(cat $FOLLOWING)" + if [ ! -z $1 ] then - _ak_log_error "Addition failed" + search="$1" + sed -i -e 's,'"$search"',,g' $FOLLOWING + if [ $? -ne 0 ] + then + _ak_log_error "sed didn't found $search" + exit 1 + fi + IPFS="$(_ak_ipfs_add $FOLLOWING)" + if [ $? -ne 0 ] + then + _ak_log_error "IPFS problem" + exit 1 + fi + ak-profile set repositories "$IPFS" + exit 0 + else + echo "Who to unfollow?" + echo "Type following to see them" exit 1 fi - ak-profile set following $IPFS - exit 0 +} + +if [ ! -z $1 ] +then + case $1 in + -h | --help) _ak_usage; exit;; + -f | --follow) _ak_follow_follow $2; exit;; + -l | --list) _ak_follow_list $2; exit;; + -u | --unfollow) _ak_follow_unfollow $2; exit;; + * ) _ak_usage;; + esac +else _ak_usage fi -printf "Usage:\n\t%s \n" $PROGRAM -exit 1 diff --git a/bin/ak-following b/bin/ak-following deleted file mode 100755 index 734f6ed..0000000 --- a/bin/ak-following +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_log - -FOLLOWING="$HOME/.arching-kaos/following" -if [ -f $FOLLOWING ] -then - cat $FOLLOWING -else - _ak_log_info "No following file, creating" - touch $FOLLOWING - echo "None found" -fi diff --git a/bin/ak-mempool b/bin/ak-mempool index bcf56ad..4e796fb 100755 --- a/bin/ak-mempool +++ b/bin/ak-mempool @@ -1,11 +1,24 @@ #!/bin/bash +## +## Brief description +## +## Usage: +## +## -h, --help Prints this help message +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Quick description" + +# At least these +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script # Assumptions: # I suppose each ak node is connected to some IP. # They also run IPFS. # They also are a part of our swarm. # So should we ask for our peers? -source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_ipfs _ak_ipfs_swarm_peers > tmp_peers diff --git a/bin/ak-miner-script b/bin/ak-miner-script index 9119b0c..ae9f7a8 100755 --- a/bin/ak-miner-script +++ b/bin/ak-miner-script @@ -43,7 +43,7 @@ proofofwork(){ usage(){ echo "$PROGRAM " - echo " hit ak-enter after that !!! " + echo " hit 'ak-zchain --crawl' after that." } if [ -z "$1" ] ; diff --git a/bin/ak-profile b/bin/ak-profile index f4051eb..67b67d1 100755 --- a/bin/ak-profile +++ b/bin/ak-profile @@ -7,7 +7,7 @@ ## ## -h, --help Prints this help message ## -## -i, --index Show current status +## -l, --local-index Show current status ## ## --show Show profile entry from specified DATA ## IPFS CIDv0 @@ -29,9 +29,7 @@ fullprogrampath="$(realpath $0)" PROGRAM=$(basename $0) descriptionString="Profile module" ZPROFILEDIR="$AK_WORKDIR/profile" -TEMP="/tmp/aktmp" -# Outputs to log file in the classic format :) source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_script source $AK_LIBDIR/_ak_ipfs @@ -40,14 +38,16 @@ source $AK_LIBDIR/_ak_zblock # Whatever the command is, we check if $ZPROFILEDIR is there. # If NOT we create it and we change dir there. -if [ ! -d $ZPROFILEDIR ]; then +if [ ! -d $ZPROFILEDIR ] +then mkdir $ZPROFILEDIR - cd $ZPROFILEDIR _ak_log_info "zprofiledir created" else _ak_log_info "zprofiledir found" fi +cd $ZPROFILEDIR + # This is working with DATA blocks. DATA that matched profile/add ACTION # # The profile settings/configuration is part of the blockchain produced. @@ -59,7 +59,7 @@ _ak_modules_profile_show(){ _ak_log_info "Working with $1" _ak_ipfs_cat $(echo $(_ak_ipfs_cat $1) | jq '.ipfs' -r) else - echo "No DATA provided" + _ak_log_error "No DATA provided" exit 1 fi } @@ -71,12 +71,12 @@ _ak_modules_profile_propget(){ then if [ ! -f $ZPROFILEDIR/$1 ] then - echo "property not found" + _ak_log_error "property not found $1" else cat $ZPROFILEDIR/$1 fi else - echo "No particular property... indexing" + _ak_log_error "No particular property... indexing" _ak_modules_profile_index fi } @@ -89,13 +89,13 @@ _ak_modules_profile_propwrite(){ EOF if [ $? == 0 ] then - echo "Added successfully... proceeding" + _ak_log_info "Added successfully... proceeding" IPFS_FILE=$(_ak_ipfs_add $ZPROPERTY_FILE) - echo "Prop writting,,, $IPFS_FILE" + _ak_log_info "Prop writting,,, $IPFS_FILE" _ak_modules_profile_add $ZPROPERTY_KEY cd $ZPROFILEDIR else - echo "Couldn't write to file $ZPROFILEDIR/$TO_FILE" + _ak_log_error "Couldn't write to file $ZPROFILEDIR/$TO_FILE" exit 1 fi } @@ -107,19 +107,19 @@ _ak_modules_profile_propset(){ ZPROPERTY_KEY="$1" if [ ! -f $ZPROPERTY_FILE ] then - echo "No such property: $ZPROPERTY_KEY ... creating" + _ak_log_warning "No such property: $ZPROPERTY_KEY ... creating" ZPROPERTY_VALUE="$2" if [ ! -z "$ZPROPERTY_VALUE" ] then touch $ZPROPERTY_FILE - echo "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE" + _ak_log_debug "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE" _ak_modules_profile_propwrite #"$ZPROPERTY_FILE" "${ZPROPERTY_VALUE}" else - echo "No value for $1" + _ak_log_error "No value for $1" fi else - echo found $ZPROPERTY_FILE - echo "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE" + _ak_log_info "found $ZPROPERTY_FILE" + _ak_log_debug "$ZPROPERTY_KEY = $ZPROPERTY_VALUE in file $ZPROPERTY_FILE" ZPROPERTY_VALUE="$2" read -p "Overwrite $1 with ${ZPROPERTY_VALUE} ? " yn case $yn in @@ -127,11 +127,11 @@ _ak_modules_profile_propset(){ [Nn]* ) exit 130;; * ) echo "Answer please";; esac - echo $IPFS_FILE + _ak_log_debug $IPFS_FILE _ak_modules_profile_show $IPFS_FILE fi else - echo "conditions unmet" + _ak_log_error "conditions unmet" exit 244 fi } @@ -159,10 +159,10 @@ _ak_modules_profile_import(){ then if [ ! -d $1 ] then - echo "Profile folder check: Folder $1 does not exist. Stopping..." + _ak_log_error "Profile folder check: Folder $1 does not exist. Stopping..." exit 4 else - echo "Profile folder check: Folder $1 exists." + _ak_log_info "Profile folder check: Folder $1 exists." fl="$(ls -1 $1)" for f in $fl do @@ -170,7 +170,7 @@ _ak_modules_profile_import(){ done fi else - echo "No value" + _ak_log_error "No value" exit 6 fi exit 224 @@ -178,11 +178,11 @@ _ak_modules_profile_import(){ # Adds a file as a profile/add ACTION on the zchain. _ak_modules_profile_add(){ - TEMP="$(_ak_make_temp_directory)" - cd $TEMP + TEMPASSIN="$(_ak_make_temp_directory)" + cd $TEMPASSIN if [ -f $ZPROFILEDIR/$1 ]; then FILE="$ZPROFILEDIR/$1" - echo "Adding from " $FILE + _ak_log_info "Adding from " $FILE FILE_IPFS_HASH=$(_ak_ipfs_add $FILE) FILE_SIGN_FILE=$(pwd)/$1".asc" _ak_gpg_sign_detached $FILE_SIGN_FILE $FILE @@ -195,26 +195,26 @@ _ak_modules_profile_add(){ } EOF else - echo "File $FILE doesn't exist"; + _ak_log_error "File $FILE doesn't exist" exit 2 fi _ak_zblock_pack "profile/add" $(pwd)/data if [ $? -ne 0 ] then - echo "error??" + _ak_log_error "Error while packing" exit 1 fi - echo "Profile added successfully" + _ak_log_info "Profile zblock added successfully" cd $ZPROFILEDIR - rm -rf "$TEMPASSIN" + rm -rf $TEMPASSIN } if [ ! -z $1 ]; then case $1 in -h | --help) _ak_usage; exit;; - -i | --index) _ak_modules_profile_index; exit;; + -l | --local-index) _ak_modules_profile_index; exit;; --show) _ak_modules_profile_show $2; exit;; -i | --import) _ak_modules_profile_import $2; exit;; -a | --add) _ak_modules_profile_add $2; exit;; diff --git a/bin/ak-schain b/bin/ak-schain new file mode 100755 index 0000000..1221274 --- /dev/null +++ b/bin/ak-schain @@ -0,0 +1,28 @@ +#!/bin/bash +## +## Various tools for schains +## +## Usage: +## +## -h, --help Prints this help message +## +## -c, --crawl Crawl an schain or latest known +## +fullprogrampath="$(realpath $0)" +PROGRAM=$(basename $0) +descriptionString="Schain tools" + +source $AK_LIBDIR/_ak_log +source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_schain + +# Flags to run +if [ ! -z $1 ] +then + case $1 in + -h | --help) _ak_usage; exit;; + -c | --crawl) _ak_schain_crawl_interface $*; exit;; + * ) _ak_usage;; + esac +else _ak_usage +fi diff --git a/bin/ak-schain-latest-cached b/bin/ak-schain-latest-cached deleted file mode 100755 index 18ac1df..0000000 --- a/bin/ak-schain-latest-cached +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_log -if [ ! -f $AK_WORKDIR/schain.latest ] -then - ak-find-latest-mined-sblock > $AK_WORKDIR/schain.latest -fi -cat $AK_WORKDIR/schain.latest diff --git a/bin/ak-unfollow b/bin/ak-unfollow deleted file mode 100755 index c23aeef..0000000 --- a/bin/ak-unfollow +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -PROGRAM="$(basename $0)" -source $AK_LIBDIR/_ak_config -source $AK_LIBDIR/_ak_ipfs -FOLLOWING="$HOME/.arching-kaos/following" -fentries="$(cat $FOLLOWING)" -if [ ! -z $1 ] -then - search="$1" - sed -i -e 's,'"$search"',,g' $FOLLOWING - if [ $? != 0 ] - then - _ak_log_error "sed didn't found $search" - exit 1 - fi - IPFS="$(_ak_ipfs_add $FOLLOWING)" - if [ $? != 0 ] - then - _ak_log_error "IPFS problem" - exit 1 - fi - ak-profile set repositories "$IPFS" - exit 0 -else - echo "Who to unfollow?" - echo "Type following to see them" - exit 1 -fi - - diff --git a/bin/ak-zchain b/bin/ak-zchain index c2ecbc6..df73e7c 100755 --- a/bin/ak-zchain +++ b/bin/ak-zchain @@ -34,6 +34,9 @@ ## ## --calculate-size Calculates the size of a zchain ## +## --crawl Crawls zchains ( --crawl --help for more +## options) +## ## --crawl-self Crawls the local zchain ## ## --crawl-remote-ipfs Crawls a remote zchain @@ -44,9 +47,11 @@ fullprogrampath="$(realpath $0)" PROGRAM=$(basename $0) descriptionString="Zchain tools" -# At least these source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_script +source $AK_LIBDIR/_ak_ipfs +source $AK_LIBDIR/_ak_gpg +source $AK_LIBDIR/_ak_zblock source $AK_LIBDIR/_ak_zchain # Flags to run @@ -55,10 +60,11 @@ if [ ! -z $1 ]; then -h | --help) _ak_usage; exit;; -r | --reset) _ak_zchain_reset; exit;; --rebase) if [ ! -z $2 ]; then _ak_zchain_rebase $2; else exit 1; fi; exit;; - --rebase-back-one) _ak_zchain_rebase "`ak-enter -l 2 | jq -r '.[1].zblock'`" ; exit ;; + --rebase-back-one) _ak_zchain_rebase "`_ak_zchain_crawl -l 2 | jq -r '.[1].zblock'`" ; exit ;; --extract-cids) _ak_zchain_extract_cids $2; exit;; --extract-data-cids) _ak_zchain_extract_data_cids $2; exit;; --calculate-size) _ak_zchain_calculate_size $2; exit;; + --crawl) shift; _ak_zchain_crawl $*; exit;; --crawl-self) _ak_zchain_crawl_self; exit;; --crawl-remote-ipfs) _ak_zchain_crawl_remote_ipfs $2; exit;; --crawl-remote-ipns) _ak_zchain_crawl_remote_ipns $2; exit;; diff --git a/lib/_ak_network b/lib/_ak_network index 1d77eef..25fa68a 100755 --- a/lib/_ak_network +++ b/lib/_ak_network @@ -231,7 +231,6 @@ _ak_network_show_peers_ipfs(){ _ak_not_implemented _ak_network_show_peers_ipfs } - _ak_network_show_peers(){ if [ ! -z $1 ] && [ -n "$1" ] then @@ -246,9 +245,7 @@ _ak_network_show_peers(){ jq -j | \ sed -e 's/]\[/,/g' | \ jq - fi - } _ak_network_ipfs_connect_bootstrap(){ @@ -267,11 +264,9 @@ _ak_network_cjdns_connect(){ tmpon="yes" curl -s "https://arching-kaos.net/files/ak_cjdns_bootstrap_peers" > $peersfile fi - totalpeers="$(jq '. | length' < $peersfile)" number="0" interface="0" - while [ $number -lt $totalpeers ] do address="$(jq -r '.['$number'].address' < $peersfile)" 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 +} diff --git a/lib/_ak_zblock b/lib/_ak_zblock index f379870..278619f 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -457,7 +457,7 @@ _ak_zblock_pack(){ # We check firstly if the encapsulated value of the "ipfs" key has already # appeared in the zchain. TO_CHECK="$(cat $MESSAGE | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g')" - ak-enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq > tempisalreadythere + _ak_zchain_crawl | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' | sort | uniq > tempisalreadythere while IFS="" read -r p || [ -n "$p" ] do if [ "$p" == "$TO_CHECK" ] diff --git a/lib/_ak_zchain b/lib/_ak_zchain index d15048a..5dbcf62 100755 --- a/lib/_ak_zchain +++ b/lib/_ak_zchain @@ -80,18 +80,18 @@ _ak_zchain_rebase(){ _ak_zchain_extract_cids(){ if [ ! -z $1 ] && [ -n "$1" ] then - ak-enter $1 | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq + ak zchain --crawl $1 | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq else - ak-enter | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq + ak zchain --crawl | jq -M | grep Qm | sed -e 's/".*"://g; s/ //g; s/[{,"]//g' | sort | uniq fi } _ak_zchain_extract_data_cids(){ if [ ! -z $1 ] then - ak-enter $1 | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' + ak zchain --crawl $1 | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' else - ak-enter | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' + ak zchain --crawl | jq | grep ipfs | awk '{print $2}' | sed -e 's/"//g;s/,//g' fi } @@ -120,14 +120,107 @@ _ak_zchain_calculate_size(){ rm -rf $temp } +_ak_zchain_crawl(){ + entrance="$(cat $AK_ZLATEST)" + verify=1 + limit=0 + fromIpns=0 + while [ "$#" ]; do + case "$1" in + -h | --help) + printf " +ak zchain --crawl [-N | --no-verify] [-l | --limit ] [zblock] +ak zchain --crawl [-N | --no-verify] [-l | --limit ] -n +Usage: + + --help, -h Print this help and exit + + --chain , -n Crawl specified chain + + --no-verify, -N Don't verify signatures + + Specify IPFS CID for entrance + +Note that combined flags don't work for now +Running with no flags crawls your chain based on AK_ZLATEST environment +variable" + exit 1 + ;; + -l | --limit) + limit=$2 + shift 2 + ;; + -N | --no-verify) + verify=0 + shift + ;; + -n | --chain | --ipns) + fromIpns=1 + ipns=$1 + shift + ol=$1 + entrance="$(_ak_ipns_resolve $1)" + if [ $? -ne 0 ] + then + _ak_log_error "Could not resolve IPNS name" + exit 1 + fi + shift + ;; + *) + test="$1" + if [ ! -z "$test" ] && [ $fromIpns -eq 0 ] + then + _ak_ipfs_cid_v0_check "$test" + entrance="$test" + elif [ -z "$entrance" ] && [ $fromIpns -eq 1 ] + then + entrance="$(cat $AK_ZLATEST)" + fi + break + esac + done + # We assign the IPFS CIDv0 of an empty file as this is used + # as our GENESIS block, hence the "seed" that the tree grows + # from. + seed="$(cat $AK_ZGENESIS)" + # We assume that we found the entrance inside a block, hence + # ZBLOCK is labeled as previous + zblock="$entrance" + # Enter temp folder + TEMPASSIN="$(_ak_make_temp_directory)" + cd $TEMPASSIN + counter=0 + # The loop + # We break the loop from inside the loop + while true + do + if [ $counter -eq 0 ] + then + echo -n '[' + fi + counter=$(($counter + 1)) + _ak_zblock_show "$zblock" + if [ $limit -ne 0 ] && [ $limit -eq $counter ] + then + echo -n ']' + exit 0 + else + echo -n ',' + fi + done +} + _ak_zchain_crawl_self(){ - ak enter + _ak_zchain_crawl } _ak_zchain_crawl_remote_ipfs(){ - ak enter $1 + _ak_zchain_crawl $1 + #ak enter $1 } _ak_zchain_crawl_remote_ipns(){ - ak enter -n $1 + _ak_zchain_crawl -n $1 + #ak enter -n $1 } diff --git a/modules/mixtapes/lib.sh b/modules/mixtapes/lib.sh index 58d7beb..4738a35 100755 --- a/modules/mixtapes/lib.sh +++ b/modules/mixtapes/lib.sh @@ -60,9 +60,9 @@ _ak_modules_mixtapes_get_local_latest(){ cd $tempdir if [ -z "$1" ] then - ak-enter -l 1 | jq > aktempzblock + ak zchain --crawl -l 1 | jq > aktempzblock else - ak-enter -l 1 $1 | jq > aktempzblock + ak zchain --crawl -l 1 $1 | jq > aktempzblock fi curzblock="`cat aktempzblock | jq -r '.[].zblock'`" curaction="`cat aktempzblock | jq -r '.[].action'`" diff --git a/modules/news/lib.sh b/modules/news/lib.sh index 8f1e98a..0cb0d81 100755 --- a/modules/news/lib.sh +++ b/modules/news/lib.sh @@ -168,7 +168,7 @@ _ak_modules_news_read(){ exit 0 fi - ak-enter -l 1 $1 > temp + ak zchain --crawl -l 1 $1 > temp if [ $? -ne 0 ] then echo error @@ -192,7 +192,7 @@ _ak_modules_news_read(){ } _ak_modules_news_html(){ - ak-enter -l 1 $1 > temp + ak zchain --crawl -l 1 $1 > temp if [ $? -ne 0 ] then _ak_log_error "Failed to retrieve zblock $1" @@ -287,9 +287,9 @@ _ak_modules_news_read_latest_local_news(){ cd $TEMP if [ -z "$1" ] then - ak-enter -l 1 | jq > aktempzblock + ak zchain --crawl -l 1 | jq > aktempzblock else - ak-enter -l 1 $1 | jq > aktempzblock + ak zchain --crawl -l 1 $1 | jq > aktempzblock fi curzblock="`cat aktempzblock | jq -r '.[].zblock'`" -- cgit v1.2.3