github.com/XinFinOrg/xdcchain@v1.1.0/docker/XDCchain/entrypoint.sh (about)

     1  #!/bin/sh
     2  
     3  # vars from docker env
     4  # - IDENTITY (default to empty)
     5  # - PASSWORD (default to empty)
     6  # - PRIVATE_KEY (default to empty)
     7  # - BOOTNODES (default to empty)
     8  # - EXTIP (default to empty)
     9  # - VERBOSITY (default to 3)
    10  # - MAXPEERS (default to 25)
    11  # - SYNC_MODE (default to 'full')
    12  # - NETWORK_ID (default to '89')
    13  # - WS_SECRET (default to empty)
    14  # - NETSTATS_HOST (default to 'netstats-server:3000')
    15  # - NETSTATS_PORT (default to 'netstats-server:3000')
    16  
    17  # constants
    18  DATA_DIR="data"
    19  KEYSTORE_DIR="keystore"
    20  
    21  # variables
    22  genesisPath=""
    23  params=""
    24  accountsCount=$(
    25    XDC account list --datadir $DATA_DIR  --keystore $KEYSTORE_DIR \
    26    2> /dev/null \
    27    | wc -l
    28  )
    29  
    30  # file to env
    31  for env in IDENTITY PASSWORD PRIVATE_KEY BOOTNODES WS_SECRET NETSTATS_HOST \
    32             NETSTATS_PORT EXTIP SYNC_MODE NETWORK_ID ANNOUNCE_TXS STORE_REWARD DEBUG_MODE MAXPEERS; do
    33    file=$(eval echo "\$${env}_FILE")
    34    if [[ -f $file ]] && [[ ! -z $file ]]; then
    35      echo "Replacing $env by $file"
    36      export $env=$(cat $file)
    37    elif [[ "$env" == "BOOTNODES" ]] && [[ ! -z $file ]]; then
    38      echo "Bootnodes file is not available. Waiting for it to be provisioned..."
    39      while true ; do
    40        if [[ -f $file ]] && [[ $(grep -e enode $file) ]]; then
    41          echo "Fount bootnode file."
    42          break
    43        fi
    44        echo "Still no bootnodes file, sleeping..."
    45        sleep 5
    46      done
    47      export $env=$(cat $file)
    48    fi
    49  done
    50  
    51  # networkid
    52  if [[ ! -z $NETWORK_ID ]]; then
    53    case $NETWORK_ID in
    54      88 )
    55        genesisPath="mainnet.json"
    56        ;;
    57      89 )
    58        genesisPath="testnet.json"
    59        params="$params --XDC-testnet --gcmode archive --rpcapi db,eth,net,web3,personal,debug"
    60        ;;
    61      90 )
    62        genesisPath="devnet.json"
    63        ;;
    64      * )
    65        echo "network id not supported"
    66        ;;
    67    esac
    68    params="$params --networkid $NETWORK_ID"
    69  fi
    70  
    71  # data dir
    72  if [[ ! -d $DATA_DIR/XDC ]]; then
    73    echo "No blockchain data, creating genesis block."
    74    XDC init $genesisPath --datadir $DATA_DIR 2> /dev/null
    75  fi
    76  
    77  # identity
    78  if [[ -z $IDENTITY ]]; then
    79    IDENTITY="unnamed_$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6)"
    80  fi
    81  
    82  # password file
    83  if [[ ! -f ./password ]]; then
    84    if [[ ! -z $PASSWORD ]]; then
    85      echo "Password env is set. Writing into file."
    86      echo "$PASSWORD" > ./password
    87    else
    88      echo "No password set (or empty), generating a new one"
    89      $(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32} > password)
    90    fi
    91  fi
    92  
    93  # private key
    94  if [[ $accountsCount -le 0 ]]; then
    95    echo "No accounts found"
    96    if [[ ! -z $PRIVATE_KEY ]]; then
    97      echo "Creating account from private key"
    98      echo "$PRIVATE_KEY" > ./private_key
    99      XDC  account import ./private_key \
   100        --datadir $DATA_DIR \
   101        --keystore $KEYSTORE_DIR \
   102        --password ./password
   103      rm ./private_key
   104    else
   105      echo "Creating new account"
   106      XDC account new \
   107        --datadir $DATA_DIR \
   108        --keystore $KEYSTORE_DIR \
   109        --password ./password
   110    fi
   111  fi
   112  account=$(
   113    XDC account list --datadir $DATA_DIR  --keystore $KEYSTORE_DIR \
   114    2> /dev/null \
   115    | head -n 1 \
   116    | cut -d"{" -f 2 | cut -d"}" -f 1
   117  )
   118  echo "Using account $account"
   119  params="$params --unlock $account"
   120  
   121  # bootnodes
   122  if [[ ! -z $BOOTNODES ]]; then
   123    params="$params --bootnodes $BOOTNODES"
   124  fi
   125  
   126  # extip
   127  if [[ ! -z $EXTIP ]]; then
   128    params="$params --nat extip:${EXTIP}"
   129  fi
   130  
   131  # syncmode
   132  if [[ ! -z $SYNC_MODE ]]; then
   133    params="$params --syncmode ${SYNC_MODE}"
   134  fi
   135  
   136  # netstats
   137  if [[ ! -z $WS_SECRET ]]; then
   138    echo "Will report to netstats server ${NETSTATS_HOST}:${NETSTATS_PORT}"
   139    params="$params --ethstats ${IDENTITY}:${WS_SECRET}@${NETSTATS_HOST}:${NETSTATS_PORT}"
   140  else
   141    echo "WS_SECRET not set, will not report to netstats server."
   142  fi
   143  
   144  # annonce txs
   145  if [[ ! -z $ANNOUNCE_TXS ]]; then
   146    params="$params --announce-txs"
   147  fi
   148  
   149  # store reward
   150  if [[ ! -z $STORE_REWARD ]]; then
   151    params="$params --store-reward"
   152  fi
   153  
   154  # debug mode
   155  if [[ ! -z $DEBUG_MODE ]]; then
   156    params="$params --gcmode archive --rpcapi db,eth,net,web3,personal,debug"
   157  fi
   158  
   159  # maxpeers
   160  if [[ -z $MAXPEERS ]]; then
   161    MAXPEERS=25
   162  fi
   163  
   164  # dump
   165  echo "dump: $IDENTITY $account $BOOTNODES"
   166  
   167  set -x
   168  
   169  exec XDC $params \
   170    --verbosity $VERBOSITY \
   171    --datadir $DATA_DIR \
   172    --keystore $KEYSTORE_DIR \
   173    --identity $IDENTITY \
   174    --maxpeers $MAXPEERS \
   175    --password ./password \
   176    --port 30303 \
   177    --txpool.globalqueue 5000 \
   178    --txpool.globalslots 5000 \
   179    --rpc \
   180    --rpccorsdomain "*" \
   181    --rpcaddr 0.0.0.0 \
   182    --rpcport 8545 \
   183    --rpcvhosts "*" \
   184    --ws \
   185    --wsaddr 0.0.0.0 \
   186    --wsport 8546 \
   187    --wsorigins "*" \
   188    --mine \
   189    --gasprice "250000000" \
   190    --targetgaslimit "84000000" \
   191    "$@"