aboutsummaryrefslogtreecommitdiff
path: root/bin/ak-stellar-get-participants
blob: 838ad08dc41a243ae307230f7ae04f93b6d604a8 (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
#!/bin/bash
PROGRAM="$(basename $0)"
tempdir=`mktemp -d`
tempfile="$tempdir/tmp"
tempaddr="$tempdir/tmpaddr"
logit(){
    ak-logthis "<$PROGRAM>" "$1" "$2"
}
stellarParticipants="$AK_WORKDIR/stellar-network-participants"
stellarParticipantsOnline="$AK_WORKDIR/stellar-network-participants-online"
if [ ! -f "$stellarParticipants" ]
then
    touch $stellarParticipants
fi
if [ ! -f "$stellarParticipantsOnline" ]
then
    touch $stellarParticipantsOnline
fi
if [ ! -f "$tempdir" ]
then
    touch $tempdir
fi
if [ ! -f "$tempaddr" ]
then
    touch $tempaddr
fi

if [ ! -z $1 ] && [ "$1" == "-l" ] && [ ! -z $2 ]
then
    limit=$2
else
    limit=3
fi

show_ids(){
    i=0
    flag=0
    while [ "$i" -lt "$limit" ]
    do
        test="$(cat $tempfile | jq '.["_embedded"]' | jq .'["records"]' | jq '.['$i']' | jq '.["id"]' | sed -e 's/\"//g')"
        while IFS="" read -r p || [ -n "$p" ]
        do
            if [ "$p" == "$test" ]
            then
                flag=1
                break
            fi
        done < $stellarParticipants
        if [ "$flag" == "0" ]
        then
            echo $test >> $stellarParticipants
            logit "[INFO]" "Added $test"
        else
            logit "[INFO]" "$test already there. Skipping..."
        fi
        i="$(expr $i + 1)"
    done
}

get_next_page(){
    cat $tempfile | grep -1 next | grep https | sed -e 's/^.*https/https/' | sed -e 's/\u0026/\&/g; s/"//g; s/\\//g'
}

proceed_to_next_page(){

    nextURL="$(get_next_page)"
    curl "$nextURL" > $tempfile 2>/dev/null
}

get_asset_holders(){
    curl https://horizon.stellar.org/accounts\?asset\=ARCHINGKAOS:GB4QVKD6NW3CSNO5TNPARAWNPPXOPSSTKB35XCWB7PUNBIQTK3DVELB2\&limit\=$limit > $tempfile 2>/dev/null
}

get_asset_holders
while [ "$(tail -1 $stellarParticipants)" != "null" ]
do
    show_ids
    proceed_to_next_page
done

grep G $stellarParticipants > $tempaddr
cat $tempaddr > $stellarParticipants
rm $tempfile $tempaddr
while IFS="" read -r p || [ -n "$p" ]
do
    flag=0
    test="$(curl https://horizon.stellar.org/accounts/$p/data/config 2>/dev/null | grep value)"
    if [ "$?" == 0 ]
    then
        addressValuePair="$(printf '%s %s\n' "$p" "$(echo $test | sed -e 's/^.*: "//g; s/"//g' | base64 -d)")"
        while IFS="" read -r x || [ -n "$x" ]
        do
            if [ "$x" == "$addressValuePair" ]
            then
                flag=1
                break
            fi
        done < $stellarParticipantsOnline
        if [ "$flag" == "0" ]
        then
            echo $addressValuePair >> $stellarParticipantsOnline
            logit "[INFO]" "$p is configured with  $(echo $addressValuePair | awk '{ print $2 }'). Added to online participants."
        else
            logit "[INFO]" "$(echo $addressValuePair | awk '{ print $2 }') is already in $stellarParticipantsOnline. Skipping..."
        fi
    fi
done < $stellarParticipants