#!/bin/bash
GREEN='\033[0;32m'
NC='\033[0m' # No Color
clear
echo -e "${GREEN}#"
echo -e "#   This script generates the necessary json blob for the Oracle Job-Setup section in the docs"
echo -e "#   source: https://docs.goplugin.co/oracle/job-setup"
echo -e "#"
echo -e "#   The script uses the 'name' & 'endpoint' variables from your local VARS file & prompts"
echo -e "#   you to enter the newly generated Oracle contract address (which was generated by the Oracle Deployment section)"
echo -e "#"
echo -e "#   The script checks for leading  / trailing white spaces and removes as necessary"
echo -e "#   & converts the 'xdc' prefix to '0x' as necessary"
echo -e "#"
echo -e "#${NC}"
sleep 0.5s
source ~/"plinode_$(hostname -f)".vars
read -p 'Enter your Oracle Contract Address : ' _INPUT
ORACLE_ADDR="$(echo $_INPUT | sed '/^$/d;/^\\s*$/d;s/^xdc/0x/g')"
#echo "$_INPUT"
#echo "$ORACLE_ADDR"
diff -u <(echo "$_INPUT") <(echo "$ORACLE_ADDR")
sleep 2s

cat <<EOF > ~/plinode_local_testjob.json
{
    "initiators":[
        {
            "type":"external",
            "params":{
      "name": "$PLI_L_INIT_NAME",
               "body": {
      "endpoint": "$PLI_E_INIT_NAME",
      "addresses": ["$ORACLE_ADDR"]
    }
            }
        }
    ],
    "tasks":[
        {
            "type":"sleep",
            "confirmations":null,
            "params":{
            }
        },
        {
            "type":"ethbool",
            "confirmations":null,
            "params":{
            }
        },
        {
            "type":"ethtx",
            "confirmations":null,
            "params":{
            }
        }
    ],
    "startAt":null,
    "endAt":null
}
EOF
sleep 1s
echo
echo " Local node json blob for test job - copy & paste"
echo
echo
cat ~/plinode_local_testjob.json