test -s api-usd || echo 1 > api-usd
read -r price < api-usd
. /dev/shm/UpdateTip-bitcoin
#ntx=$(bch.sh getblockheader $best | grep -w nTx | tr -cd '[0-9]')
prevbytes=$(grep -o '"gmi_bytes":[0-9]\+' /dev/shm/datab.json | tr -cd '[0-9]')
#prevntx=$(grep -o '"ntx":[0-9]\+' /dev/shm/datab.json | tr -cd '[0-9]')
echo $prevbytes >&2
sko=$(shortkode.sh $best)
sk="$height $sko"
ako=$(anecdotalk.sh $best)
ak="$height ak: $ako"
time=$(/bin/date -u +%s -d "$date")
. /tmp/gmif-main
mm=$((1000*$total_fee/$bytes))
blocks=$((($bytes+999999)/1000000))
newmm=$(( ($total_fee+999)/1000/$blocks ))
test $newmm -lt 101 && newmm=101
test $blocks -eq 1 && newmm=100
printf {
{
cat <<EOF
"price":${price:-1}
"best":"$best"
"height":$height
"sk":"$sk"
"sko":"$sko"
"ak":"$ak"
"ako":"$ako"
"time":$time
"date":"$date"
"mm":"$newmm"
"blocks":$blocks
"gmi_size":$size
"gmi_bytes":$bytes
EOF
} | paste -s -d "," | tr -d '\n'
printf }

echo $mm | safecat.sh /tmp/gmm-main
echo $newmm | safecat.sh /tmp/newmm-main
