Guest User

Untitled

a guest
Sep 10th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. #!/bin/sh
  2. # Tmux script to create 4 dcrd nodes connected in series. Useful for testing
  3. # message relaying
  4. # Network layout:
  5. # master <-> 1 <-> 2 <-> 3
  6. # 19555 19665 19675 19685
  7.  
  8.  
  9. set -e
  10.  
  11. SESSION="dcrd-serial-nodes"
  12. NODES_ROOT=~/dcrdsimnetnodes
  13. RPCUSER="USER"
  14. RPCPASS="PASS"
  15. WALLET_SEED="b280922d2cffda44648346412c5ec97f429938105003730414f10b01e1402eac"
  16. WALLET_MINING_ADDR="SsWKp7wtdTZYabYFYSc9cnxhwFEjA5g4pFc" # NOTE: This must be changed if the seed is changed.
  17. WALLET_XFER_ADDR="Sso52TPnorVkSaRYzHmi4FgU8F5BFEDZsiK" # same as above
  18.  
  19. if [ -d "${NODES_ROOT}" ] ; then
  20. rm -R "${NODES_ROOT}"
  21. fi
  22.  
  23. mkdir -p "${NODES_ROOT}/"{master,1,2,3,wallet}
  24.  
  25. cat > "${NODES_ROOT}/dcrd.conf" <<EOF
  26. rpcuser=${RPCUSER}
  27. rpcpass=${RPCPASS}
  28. simnet=1
  29. logdir=./log
  30. datadir=./data
  31. ; debuglevel=FEES=DEBUG,TXMP=TRACE
  32. txindex=1
  33. EOF
  34.  
  35. cat > "${NODES_ROOT}/dcrctl.conf" <<EOF
  36. rpcuser=${RPCUSER}
  37. rpcpass=${RPCPASS}
  38. simnet=1
  39. EOF
  40.  
  41. cat > "${NODES_ROOT}/wallet.conf" <<EOF
  42. username=${RPCUSER}
  43. password=${RPCPASS}
  44. simnet=1
  45. logdir=./log
  46. appdata=./data
  47. pass=123
  48. enablevoting=1
  49. enableticketbuyer=1
  50. ticketbuyer.nospreadticketpurchases=1
  51. ticketbuyer.maxperblock=5
  52. ; ticketbuyer.minfee=0.002
  53. EOF
  54.  
  55. cd ${NODES_ROOT} && tmux -2 new-session -d -s $SESSION
  56.  
  57. ################################################################################
  58. # Setup the master (mining) node
  59. ################################################################################
  60.  
  61. tmux rename-window -t $SESSION:0 'master'
  62. tmux split-window -v
  63. tmux select-pane -t 0
  64. tmux send-keys "cd master" C-m
  65. tmux send-keys "dcrd -C ../dcrd.conf --listen 127.0.0.1:19555 --miningaddr=${WALLET_MINING_ADDR}" C-m
  66. tmux resize-pane -D 15
  67. tmux select-pane -t 1
  68. tmux send-keys "cd master" C-m
  69.  
  70. cat > "${NODES_ROOT}/master/ctl" <<EOF
  71. #!/bin/sh
  72. dcrctl -C ../dcrctl.conf \$*
  73. EOF
  74. chmod +x "${NODES_ROOT}/master/ctl"
  75.  
  76. cat > "${NODES_ROOT}/master/mine" <<EOF
  77. #!/bin/sh
  78. NUM=1
  79. case \$1 in
  80. ''|*[!0-9]*) ;;
  81. *) NUM=\$1 ;;
  82. esac
  83.  
  84. for i in \$(seq \$NUM) ; do
  85. dcrctl -C ../dcrctl.conf generate 1
  86. sleep 0.3
  87. done
  88. EOF
  89. chmod +x "${NODES_ROOT}/master/mine"
  90. sleep 3
  91. tmux send-keys "./ctl generate 32" C-m
  92.  
  93. ################################################################################
  94. # Setup the wallet
  95. ################################################################################
  96.  
  97. tmux new-window -t $SESSION:1 -n 'wallet'
  98. tmux split-window -v
  99. tmux select-pane -t 0
  100. tmux resize-pane -D 15
  101. tmux send-keys "cd wallet" C-m
  102. tmux send-keys "dcrwallet -C ../wallet.conf --create" C-m
  103. sleep 2
  104. tmux send-keys "123" C-m "123" C-m "n" C-m "y" C-m
  105. sleep 1
  106. tmux send-keys "${WALLET_SEED}" C-m C-m
  107. tmux send-keys "dcrwallet -C ../wallet.conf" C-m
  108. tmux select-pane -t 1
  109. tmux send-keys "cd wallet" C-m
  110.  
  111. cat > "${NODES_ROOT}/wallet/ctl" <<EOF
  112. #!/bin/sh
  113. dcrctl -C ../dcrctl.conf --wallet -c ./data/rpc.cert \$*
  114. EOF
  115. chmod +x "${NODES_ROOT}/wallet/ctl"
  116.  
  117. cat > "${NODES_ROOT}/wallet/tickets" <<EOF
  118. #!/bin/sh
  119. NUM=1
  120. case \$1 in
  121. ''|*[!0-9]*) ;;
  122. *) NUM=\$1 ;;
  123. esac
  124.  
  125. ./ctl purchaseticket default 999999 1 \`./ctl getnewaddress\` \$NUM
  126. EOF
  127. chmod +x "${NODES_ROOT}/wallet/tickets"
  128. tmux send-keys "./tickets 300"
  129.  
  130. cat > "${NODES_ROOT}/wallet/xfer" <<EOF
  131. #!/bin/sh
  132. FEE=0.001
  133. case \$1 in
  134. ''|*[!0-9\.]*) FEE=\`python -c "import random ; print((1e5 + random.expovariate(0.00002)) / 1e8)"\` ;;
  135. *) FEE=\$1 ;;
  136. esac
  137. ./ctl settxfee \$FEE
  138. ./ctl sendtoaddress ${WALLET_XFER_ADDR} 0.1
  139. ./ctl settxfee 0.001
  140. EOF
  141. chmod +x "${NODES_ROOT}/wallet/xfer"
  142.  
  143.  
  144. ################################################################################
  145. # Setup the serially connected nodes
  146. ################################################################################
  147.  
  148. cat > "${NODES_ROOT}/1/ctl" <<EOF
  149. #!/bin/sh
  150. dcrctl -C ../dcrctl.conf -s 127.0.0.1:19566 \$*
  151. EOF
  152. chmod +x "${NODES_ROOT}/1/ctl"
  153.  
  154. cat > "${NODES_ROOT}/2/ctl" <<EOF
  155. #!/bin/sh
  156. dcrctl -C ../dcrctl.conf -s 127.0.0.1:19576 \$*
  157. EOF
  158. chmod +x "${NODES_ROOT}/2/ctl"
  159.  
  160. cat > "${NODES_ROOT}/3/ctl" <<EOF
  161. #!/bin/sh
  162. dcrctl -C ../dcrctl.conf -s 127.0.0.1:19586 \$*
  163. EOF
  164. chmod +x "${NODES_ROOT}/3/ctl"
  165.  
  166.  
  167.  
  168. tmux new-window -t $SESSION:2 -n 'wallet'
  169. tmux send-keys "cd 1" C-m
  170. tmux send-keys "dcrd -C ../dcrd.conf --listen 127.0.0.1:19565 --rpclisten :19566 --connect 127.0.0.1:19555 " C-m
  171. tmux split-window -v
  172. tmux select-pane -t 1
  173. tmux send-keys "cd 2" C-m
  174. tmux send-keys "dcrd -C ../dcrd.conf --listen 127.0.0.1:19575 --rpclisten :19576 --connect 127.0.0.1:19565 " C-m
  175. tmux split-window -v
  176. tmux select-pane -t 2
  177. tmux send-keys "cd 3" C-m
  178. tmux send-keys "dcrd -C ../dcrd.conf --listen 127.0.0.1:19585 --rpclisten :19586 --connect 127.0.0.1:19575 " C-m
  179. tmux select-layout even-vertical
  180.  
  181.  
  182.  
  183. tmux attach-session -t $SESSION
Add Comment
Please, Sign In to add comment