blob: 4537d2f01887ff37d1a4cd4855ec2d2572f66526 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#!/bin/bash
# ak-enter
#
# Using this tool, we can seek a whole zchain, if available from
# an IPFS CID or an IPNS link.
#
# Default (no arguments) will retrieve the local ZCHAIN starting
# from the IPFS CID stored in the file that is tracked by the
# $AK_ZLATEST environment variable.
#
# ak-enter [-n IPNS_LINK]
# ak-enter [IPFS CID]
# ak-enter -N
# ak-enter -h
# ak-enter
## ak-enter [-N | --no-verify] [-l | --limit <number>] [zblock]
## ak-enter [-N | --no-verify] [-l | --limit <number>] -n <zchain>
## Usage:
## --help, -h Print this help and exit
## --chain <ipns-link>, -n <ipns-link> Crawl specified chain
## --no-verify, -N Don't verify signatures
## <ipfs-link> 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
#
# Returns a JSON array representing the chain retrieved.
# Logs messages to $LOGSFILE.
fullprogrampath="$(realpath $0)"
PROGRAM="$(basename $0)"
descriptionString="Crawl an arching kaos chain"
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
# Start of tests
#entrance="QmW5WVXCJfhb4peHG6cbEdamC24vZzMX2Vz386vpENh38U"
#entrance="QmNjQq7GkuXGF8kFT1z2Mv3i4JhY7sBXVUmHDiR1zkQjoE"
#entrance="QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH"
# End of tests
entrance="$(cat $AK_ZLATEST)"
verify=1
limit=0
fromIpns=0
while [ "$#" ]; do
case "$1" in
-h | --help)
_ak_usage
;;
-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
logit "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-tempassin)"
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
|