#!/usr/bin/env bash
# Copyright (c) 2016-2024 The Hush developers
# Distributed under the GPLv3 software license, see the accompanying
# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html

#set -ex
echo "...Checking DRAGONX.conf"

if [ ! -e "$HOME/.hush/DRAGONX/DRAGONX.conf" ]; then
    mkdir -p $HOME/.hush/DRAGONX

    DATE=$(date)
    echo "...Creating DRAGONX.conf"
    cat <<EOF > $HOME/.hush/DRAGONX/DRAGONX.conf
# Generated by docker-entrypoint.sh at $DATE
rpcuser=dragonx
rpcpassword=${rpcpassword:-`dd if=/dev/urandom bs=33 count=1 2>/dev/null | base64`}
txindex=1
bind=${listenip:-127.0.0.1}
rpcbind=${listenip:-127.0.0.1}
# Some knobs you might want to turn
debug=0
zdebug=0
zindex=0
EOF

    cat $HOME/.hush/DRAGONX/DRAGONX.conf
fi

if [ $# -gt 0 ]; then
    args=("$@")
elif [  -z ${assetchain+x} ]; then
    args=("-gen -genproclimit=${genproclimit:-2} -pubkey=${pubkey}")
else
    args=("-pubkey=${pubkey} -ac_name=${assetchain} -addnode=${seednode}")
fi

echo "Running: dragonxd ${args[@]}"

exec dragonxd ${args[@]}
