decred.org/dcrdex@v1.0.5/dex/testing/dcr/create-wallet.sh (about)

     1  #!/usr/bin/env bash
     2  # Script for creating dcr wallets, dcr harness should be running before executing.
     3  set -e
     4  
     5  # The following are required script arguments
     6  TMUX_WIN_ID=$1
     7  NAME=$2
     8  SEED=$3
     9  RPC_PORT=$4
    10  USE_SPV=$5
    11  ENABLE_VOTING=$6
    12  HTTPPROF_PORT=$7
    13  MANUAL_TICKETS=$8
    14  VSP_PUBKEY=$9
    15  
    16  WALLET_DIR="${NODES_ROOT}/${NAME}"
    17  mkdir -p ${WALLET_DIR}
    18  
    19  export SHELL=$(which bash)
    20  
    21  # Connect to alpha or beta node
    22  DCRD_SPV_PORT="${ALPHA_NODE_PORT}"
    23  DCRD_RPC_PORT="${ALPHA_NODE_RPC_PORT}"
    24  DCRD_RPC_CERT="${NODES_ROOT}/alpha/rpc.cert"
    25  if [ "${NAME}" = "beta" ] || [ "${NAME}" = "alpha-clone" ]; then
    26    DCRD_SPV_PORT="${BETA_NODE_PORT}"
    27    DCRD_RPC_PORT="${BETA_NODE_RPC_PORT}"
    28    DCRD_RPC_CERT="${NODES_ROOT}/beta/rpc.cert"
    29  fi
    30  
    31  # wallet config
    32  cat > "${WALLET_DIR}/${NAME}.conf" <<EOF
    33  simnet=1
    34  nogrpc=1
    35  appdata=${WALLET_DIR}
    36  logdir=${WALLET_DIR}/log
    37  debuglevel=debug
    38  username=${RPC_USER}
    39  password=${RPC_PASS}
    40  rpclisten=127.0.0.1:${RPC_PORT}
    41  rpccert=${WALLET_DIR}/rpc.cert
    42  pass=${WALLET_PASS}
    43  EOF
    44  
    45  if [ "${USE_SPV}" = "1" ]; then
    46    cat >> "${WALLET_DIR}/${NAME}.conf" <<EOF
    47  spvconnect=127.0.0.1:${DCRD_SPV_PORT}
    48  spv=1
    49  EOF
    50  else
    51    cat >> "${WALLET_DIR}/${NAME}.conf" <<EOF
    52  rpcconnect=127.0.0.1:${DCRD_RPC_PORT}
    53  cafile=${DCRD_RPC_CERT}
    54  EOF
    55  fi
    56  
    57  if [ "${ENABLE_VOTING}" = "1" ]; then
    58  cat >> "${WALLET_DIR}/${NAME}.conf" <<EOF
    59  enablevoting=1
    60  EOF
    61  fi
    62  
    63  if [ "${MANUAL_TICKETS}" = "1" ]; then
    64  cat >> "${WALLET_DIR}/${NAME}.conf" <<EOF
    65  manualtickets=1
    66  EOF
    67  fi
    68  
    69  if [ "${ENABLE_VOTING}" = "2" ]; then
    70  cat >> "${WALLET_DIR}/${NAME}.conf" <<EOF
    71  enablevoting=1
    72  enableticketbuyer=1
    73  ticketbuyer.limit=6
    74  ; NOTE: when regenerating the chain from genesis, might need to comment out this line:
    75  ticketbuyer.balancetomaintainabsolute=1000
    76  EOF
    77  fi
    78  
    79  if [ "${VSP_PUBKEY}" != "_" ]; then
    80  cat >> "${WALLET_DIR}/${NAME}.conf" <<EOF
    81  vsp.url=http://127.0.0.1:19591
    82  vsp.pubkey=${VSP_PUBKEY}
    83  EOF
    84  fi
    85  
    86  if [ "${HTTPPROF_PORT}" != "_" ]; then
    87  echo "profile=127.0.0.1:${HTTPPROF_PORT}" >> "${WALLET_DIR}/${NAME}.conf"
    88  fi
    89  
    90  # wallet ctl config
    91  cat > "${WALLET_DIR}/${NAME}-ctl.conf" <<EOF
    92  rpcuser=${RPC_USER}
    93  rpcpass=${RPC_PASS}
    94  rpccert=${WALLET_DIR}/rpc.cert
    95  rpcserver=127.0.0.1:${RPC_PORT}
    96  EOF
    97  
    98  # wallet ctl script
    99  cat > "${NODES_ROOT}/harness-ctl/${NAME}" <<EOF
   100  #!/usr/bin/env bash
   101  dcrctl -C "${WALLET_DIR}/${NAME}-ctl.conf" --wallet \$*
   102  EOF
   103  chmod +x "${NODES_ROOT}/harness-ctl/${NAME}"
   104  
   105  # wallet setup data
   106  cat > "${WALLET_DIR}/wallet.answers" <<EOF
   107  y
   108  n
   109  y
   110  ${SEED}
   111  EOF
   112  
   113  # create and unlock the wallet
   114  tmux new-window -t $TMUX_WIN_ID -n w-"${NAME}" $SHELL
   115  tmux send-keys -t $TMUX_WIN_ID "set +o history" C-m
   116  tmux send-keys -t $TMUX_WIN_ID "cd ${WALLET_DIR}" C-m
   117  
   118  echo "Creating simnet ${NAME} wallet"
   119  tmux send-keys -t $TMUX_WIN_ID "dcrwallet -C ${NAME}.conf --create < wallet.answers; tmux wait-for -S ${NAME}" C-m
   120  tmux wait-for ${NAME}
   121  
   122  echo "Starting simnet ${NAME} wallet"
   123  tmux send-keys -t $TMUX_WIN_ID "dcrwallet -C ${NAME}.conf" C-m