Skip to content

Instantly share code, notes, and snippets.

@midnightmagic
Created October 5, 2011 17:14
Show Gist options
  • Save midnightmagic/1265052 to your computer and use it in GitHub Desktop.
Save midnightmagic/1265052 to your computer and use it in GitHub Desktop.
Block decoder in bash
#!/bin/bash
unset LASTBLOCK
while true
do
if [ -e LAST_BLOCK_EXAMINED ]
then
LASTBLOCK=$( cat LAST_BLOCK_EXAMINED )
fi
if [ -z "$LASTBLOCK" ]
then
LASTBLOCK=0
fi
CURBLOCK=$( namecoind getinfo|grep -i blocks|awk '{ print $3 }'|sed -e 's/,//g' )
if [ "$CURBLOCK" -gt "$LASTBLOCK" ]
then
# echo i have work to do: $(( $CURBLOCK - $LASTBLOCK)) blocks
for i in $( seq $(( $LASTBLOCK + 1 )) $CURBLOCK )
do
# echo working on "$i", from $(( $LASTBLOCK + 1 )) to $CURBLOCK
echo -n $i.. $'\r' >&2
if [ -e TRIGGERS ]
then
while read j
do
TRIGGERBLOCK=$( echo $j | cut -d ' ' -f 1 )
NAME=$( echo $j | cut -d ' ' -f 2 )
REST=$( echo $j | cut -d ' ' --complement -f 1,2 )
if [ "$i" -ge "$TRIGGERBLOCK" ]
then
echo $'\n' trigger: $REST >&2
echo -n $NAME: >> named_raw_output
$REST
else
echo $TRIGGERBLOCK $NAME $REST >> /tmp/$$
fi
done < TRIGGERS
# mv /tmp/$$ TRIGGERS
fi
namecoind getblockbycount "$i" | grep scriptPubKey|grep OP_2DROP|grep ': "2' | while read NEWITEM
do
NEWNAME=$( echo "$NEWITEM" | awk '{ print $4 }'|xxd -r -p )
NEWVAL=$( echo "$NEWITEM" | awk '{ print $6 }'|xxd -r -p )
if [ ! -z "$NEWITEM" ]
then
MYTIME=$( namecoind getblockbycount "$i" | grep '"time"' | awk '{ print $3 }' | sed -e 's/,//g' )
echo $MYTIME:$( date +"%Y/%m/%d:%H:%M:%S" -d @"$MYTIME" ):"$i":"$NEWNAME := $NEWVAL"
fi
done
namecoind getblockbycount "$i" | grep scriptPubKey|grep OP_2DROP|grep ': "3' | while read NEWITEM
do
NAMEUPDATE=$( echo "$NEWITEM" | awk '{ print $4 }'|xxd -r -p )
UPDATEVAL=$( echo "$NEWITEM" | awk '{ print $5 }'|xxd -r -p )
CHECKOP=$( echo "$NEWITEM" | awk '{ print $6 }' )
if [ ! -z "$NEWITEM" -a "$CHECKOP" != "123" ]
then
MYTIME=$( namecoind getblockbycount "$i" | grep '"time"' | awk '{ print $3 }' | sed -e 's/,//g' )
echo $MYTIME:$( date +"%Y/%m/%d:%H:%M:%S" -d @"$MYTIME" ):"(update)":"$i":"$NAMEUPDATE := $UPDATEVAL"
fi
done
done
# echo -n "update file with $i blocks.." >&2
echo -n "$i" > LAST_BLOCK_EXAMINED
# echo ok.
fi
sleep 50
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment