aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2024-06-10 16:35:33 +0300
committerkaotisk <kaotisk@arching-kaos.org>2024-06-10 16:35:33 +0300
commit1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5 (patch)
treef21a99f6817de34d86eb1c2ff163e2d55463267b /lib
parent943f034f2bb2df772853a1de2e07d84a6c510c2a (diff)
downloadarching-kaos-tools-1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5.tar.gz
arching-kaos-tools-1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5.tar.bz2
arching-kaos-tools-1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5.zip
Refactoring
Diffstat (limited to 'lib')
-rwxr-xr-xlib/_ak_zblock238
-rwxr-xr-xlib/_ak_zchain4
2 files changed, 11 insertions, 231 deletions
diff --git a/lib/_ak_zblock b/lib/_ak_zblock
index 8a83479..ae95159 100755
--- a/lib/_ak_zblock
+++ b/lib/_ak_zblock
@@ -386,242 +386,22 @@ _ak_zblock_gen_html(){
arg="$(mktemp)"
_ak_zblock_show "$1" | jq > $arg
- ( \
- # Create HTML document
- echo "<!DOCTYPE html>"
- echo "<html>"
- echo "<head>"
- echo " <title>Arching Kaos Chain Data</title>"
- echo ' <meta charset="UTF-8">'
- echo ' <meta name="viewport" content="width=device-width, initial-scale=1">'
- echo ' <style>
- body {
- background-color: #000;
- color: lightgreen;
- padding: 2%;
- width: auto;
- font-family: monospace;
- font-size: 1rem;
- }
- h1, h2, h3, h4 {
- text-align: left;
- }
- td {
- text-align: initial;
- background-color: #090909;
- border: 1px dashed #444;
- font-size: 1rem;
- padding: 1vh 1vw;
- margin: 0;
- }
- p, summary {
- background: #061624;
- border: 1px solid #827c7c;
- padding: 1vh 1vw;
- margin: 0;
- color: lightgreen;
- font-style: normal;
- text-decoration: none;
- }
- summary:hover {
- background: lightgreen;
- color: #061624;
- }
- a {
- color: #042746;
- background-color: lightyellow;
- border: 1px solid #827c7c;
- padding: 1vh 1vw;
- margin: 0;
- font-style: normal;
- text-decoration: none;
- }
- a:hover {
- background-color: lightgreen;
- color: #042746;
- }
- details {
- /*! padding: 1vh 1vw; */
- border: 1px dotted;
- background-color: #1d4055;
- }
- footer {
- text-align: center;
- }
- </style>'
- echo "</head>"
- echo "<body>"
-
- # Iterate through each argument and parse data
- if [ -f "$arg" ]
- then
- # Extract data from argument
- zblock=$(cat $arg | jq -r '.zblock')
- block=$(cat $arg | jq -r '.block')
- timestamp=$(cat $arg | jq -r '.timestamp')
- block_signature=$(cat $arg | jq -r '.block_signature')
- detach=$(cat $arg | jq -r '.detach')
- data=$(cat $arg | jq -r '.data')
- module=$(cat $arg | jq -r '.module')
- action=$(cat $arg | jq -r '.action')
- gpg=$(cat $arg | jq -r '.gpg')
- previous=$(cat $arg | jq -r '.previous')
- datablock=$(cat $arg | jq -r ".$data")
-
- # Output data in HTML format
- echo " <h1>$PROGRAM</h1>"
- echo " <h2>🔎 $zblock</h2>"
- if [ "$module" == "news" ] && [ "$action" == "add" ]
- then
- ak-news -x $zblock
- fi
- echo " <h2>ℹī¸ $zblock</h2>"
- echo " <table>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>đŸ“Ļ ZBLOCK</pre>"
- echo " </td>"
- echo " <td>"
- echo " <details>"
- echo " <summary>$zblock</summary>"
- echo " <pre>$(_ak_ipfs_cat $zblock | jq)</pre>"
- echo " </details>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>đŸ“Ļ BLOCK</pre>"
- echo " </td>"
- echo " <td>"
- echo " <details>"
- echo " <summary>$block</summary>"
- echo " <pre>$(_ak_ipfs_cat $block | jq)</pre>"
- echo " </details>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>🔏 BLOCK SIGNATURE</pre>"
- echo " </td>"
- echo " <td>"
- echo " <details>"
- echo " <summary>$block_signature</summary>"
- echo " <pre>$(_ak_ipfs_cat $block_signature)</pre>"
- echo " </details>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>⌚ TIMESTAMP</pre>"
- echo " </td>"
- echo " <td>"
- echo " <p>$timestamp</p>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>🔌 MODULE</pre>"
- echo " </td>"
- echo " <td>"
- echo " <p>$module</p>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>đŸĒ§ ACTION</pre>"
- echo " </td>"
- echo " <td>"
- echo " <p>$action</p>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>🔑 GPG</pre>"
- echo " </td>"
- echo " <td>"
- echo " <details>"
- echo " <summary>$gpg</summary>"
- echo " <pre>$(_ak_ipfs_cat $gpg)</pre>"
- echo " </details>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>đŸ“Ļ PREVIOUS</pre>"
- echo " </td>"
- echo " <td>"
- echo ' <a target="_blank" href="http://z.kaotisk-hund.com/files/zblocks-as-html/zblock-'$previous'.html">🔗 '$previous'</a>'
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>đŸ“Ļ DATA</pre>"
- echo " </td>"
- echo " <td>"
- echo " <details>"
- echo " <summary>$data</summary>"
- echo " <pre>$datablock</pre>"
- echo " </details>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>🔏 DATA_SIGNATURE</pre>"
- echo " </td>"
- echo " <td>"
- echo " <details>"
- echo " <summary>$detach</summary>"
- echo " <pre>$(_ak_ipfs_cat $detach)</pre>"
- echo " </details>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>📄 ipfs</pre>"
- echo " </td>"
- echo " <td>"
- echo ' <a target="_blank" href="http://gw.ipfs.z.kaotisk-hund.com/ipfs/'$(echo $datablock | jq -r '.ipfs')'">'🔗 $(echo $datablock | jq -r '.ipfs')'</a>'
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>🔏 detach</pre>"
- echo " </td>"
- echo " <td>"
- echo " <details>"
- echo " <summary>$(echo $datablock | jq -r '.detach')</summary>"
- echo " <pre>$(_ak_ipfs_cat $(echo $datablock | jq -r '.detach'))</pre>"
- echo " </details>"
- echo " </td>"
- echo " </tr>"
- echo " </table>"
- echo " <table>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>📃 Rendered ZBLOCK</pre>"
- echo " </td>"
- echo " </tr>"
- echo " <tr>"
- echo " <td>"
- echo " <pre>$(cat $arg | jq)</pre>"
- echo " </td>"
- echo " </tr>"
- echo " </table>"
- fi
+ _ak_generate_html_header > zblock-$1.html
+ _ak_generate_html_zblock $arg >> zblock-$1.html
+
time_ended=$(date -u +%s.%N)
se=$(echo $time_ended | cut -d '.' -f 1)
nse=$(echo $time_ended | cut -d '.' -f 2)
- echo " <hr>"
- echo -n " <footer>Generated by $PROGRAM on $(datehuman) in $(( $se - $ss ))."
+ printf ' <hr>\n' >> zblock-$1.html
+ printf ' <footer>Generated by $PROGRAM on $(datehuman) in $(( $se - $ss )).' >> zblock-$1.html
if [ $nse -lt $nss ]
then
- echo "$(( 1$nse - $nss )) seconds</footer>"
+ printf '%s seconds</footer>\n' "$(( 1$nse - $nss ))" >> zblock-$1.html
else
- echo "$(( $nse - $(echo -n $nss|sed 's/^0*//') )) seconds</footer>"
+ printf '%s seconds</footer>' "$(( $nse - $(echo -n $nss|sed 's/^0*//') ))" >> zblock-$1.html
fi
-
- echo "</body>"
- echo "</html>" ) > zblock-$1.html
+ printf '</body>' >> zblock-$1.html
+ printf '</html>' >> zblock-$1.html
rm $arg
}
diff --git a/lib/_ak_zchain b/lib/_ak_zchain
index 2573524..8ba431d 100755
--- a/lib/_ak_zchain
+++ b/lib/_ak_zchain
@@ -2,7 +2,7 @@
source $AK_LIBDIR/_ak_ipfs
source $AK_LIBDIR/_ak_log
-_ak_zchain_reset (){
+_ak_zchain_reset(){
echo "Reseting ZLATEST to ZGENESIS"
cp $ZGENESIS $ZLATEST
if [ $? != 0 ]; then exit 1; fi
@@ -39,7 +39,7 @@ _ak_zchain_reset (){
exit 0
}
-_ak_zchain_rebase (){
+_ak_zchain_rebase(){
if [ ! -n "$1" ]; then exit 1; fi
ZTARGET="$1"
echo "Reseting ZLATEST to ZTARGET"