-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock2JSON.sh
executable file
·80 lines (55 loc) · 1.92 KB
/
block2JSON.sh
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
#!/bin/bash
#{
export PATH=$PATH:./:/usr/bin
#1) primecoind getblockhash
blockhash=$(primecoind getblockhash $1)
#2) primecoind getblock
#testing - a transaction that i know about
#blockhash="abae9a5b0bc6ee0a1aa1461778631f9f1fa83f426a6bd2613b1ec193b5560b17"
block=$(primecoind getblock $blockhash)
trans=$(echo $block | jq '.tx')
confirmations=$(echo $block | jq '.confirmations')
time=$(echo $block | jq '.time')
prev=$(echo $block | jq '.previousblockhash')
next=$(echo $block | jq '.nextblockhash')
#echo $1 $blockhash $confirmations $time $prev $next
#exit
php ./insertBlock.php $1 $blockhash $confirmations $time $prev $next
transArray=( $( echo $trans | jq -r '.[]' ) )
#echo ${transArray[@]} > /var/www/html/xpm-bal/debug
for i in ${transArray[@]}; do
#echo $i
#3) primecoind getrawtransaction
raw=$(primecoind getrawtransaction "$i")
#echo $raw
echo ${#raw}
#4) primecoind decoderawtransaction
singleTrans=$(primecoind decoderawtransaction $raw)
#echo primecoind decoderawtransaction $raw
#echo $singleTrans >> /var/www/html/xpm-bal/debug
#top level transaction id
txid=$( echo $singleTrans | jq -r '.txid' )
addressesArray=( $( echo $singleTrans | jq -r '.vout[] .scriptPubKey .addresses[]' ) )
echo $addressesArray
valuesArray=( $( echo $singleTrans | jq -r '.vout[] .value' ) )
hexArray=( $( echo $singleTrans | jq -r '.vout[] .scriptPubKey .hex' ) )
#echo $singleTrans
if [ ${#addressesArray[@]} == ${#valuesArray[@]} ] && [ ${#addressesArray[@]} == ${#hexArray[@]} ] && [ ${#valuesArray[@]} == ${#hexArray[@]} ]
then
k='feeling fine!'
#echo $k
#exit
else
echo "NOT"
exit
fi
for ((j=0; j<${#addressesArray[@]}; j++)); do
echo ${addressesArray[$j]}
#block_id, tx_id, hex, value, address
php ./insertTrans.php $1 $txid ${hexArray[$j]} ${addressesArray[$j]} ${valuesArray[$j]}
#echo
done
#echo $txid $value $address >> /var/www/html/xpm-bal/debug
#exit
done
#} >> debug2