I have written a bash script to simulate the transactions between the nodes. The code is as follows:
#!/bin/bash
MAX_NODES=2
MY_PATH=/home/ubuntu/test
CLIENT=/usr/local/bin/bitcoin-cli
declare -a addr
function fcomp() {
/usr/bin/awk -v n1=$1 -v n2=$2 'BEGIN{ if (n1>n2) exit 0; exit 1}'
}
json="'{"
#get addresses to send
for ((i = 1; i <= MAX_NODES; i++));
do
addr[$i-1]="$($CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i/ getnewaddress myaccount)"
if [ "$i" -lt "$MAX_NODES" ]
then
json="$json\"${addr[$i-1]}\":0.00001, "
else
json="$json\"${addr[$i-1]}\":0.00001"
fi
done
json="$json}'"
echo $json
#loop to send money to other nodes
for ((i = 1; i <= MAX_NODES; i++));
do
balance=`$CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i/ getbalance`
if fcomp $balance 0.002; then
$CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i sendmany myaccount $json
fi
done
echo json output:
'{"mj2FrDhEomSzyQtRoGY78oVRPcQs5L5o95":0.00001, "mkxnkT3kx9dsFS8V3qYydpL1o5F5MfwCvM":0.00001}'
I get the following error:
error: Error parsing JSON:'{"mj2FrDhEomSzyQtRoGY78oVRPcQs5L5o95":0.00001,