Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.30 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. sudo apt install -y jq screen wipe curl
  4.  
  5. CKB_TESTNET_FOLDER=/home/eric/ckb_v0.14.0_x86_64-unknown-linux-gnu/ckb-testnet
  6. SCRIPT_FOLDER=`dirname "$0"`
  7.  
  8. while true; do
  9.     cd $SCRIPT_FOLDER
  10.     killall -9 screen
  11.     killall -9 ckb
  12.     # Create a wallet
  13.     if [ -f tmpkey ]; then
  14.         mv -v tmpkey orphan_key.`date +%s`
  15.     fi
  16.     rm -vrf tmpkey
  17.     ckb-cli wallet generate-key --privkey-path tmpkey > tmpkey.meta
  18.     WALLET_ADDR=$(cat tmpkey | awk 'NR >= 2 && NR <= 2')
  19.     cat $CKB_TESTNET_FOLDER/ckb.toml | awk '!/^(code_hash = |args = )/' > $CKB_TESTNET_FOLDER/ckb.toml.new
  20.     mv $CKB_TESTNET_FOLDER/ckb.toml{.new,}
  21.     cat tmpkey.meta | awk 'NR >= 4 && NR <= 5' >> $CKB_TESTNET_FOLDER/ckb.toml
  22.  
  23.     # Spawn the blockchain client
  24.     screen -d -m bash -c 'cd '$CKB_TESTNET_FOLDER' && ckb run'
  25.  
  26.     # Spawn the miners (threads should be set to 1)
  27.     for x in $(seq $(lscpu | grep -P '^CPU\(s\):' | awk '{ print $2 }')); do
  28.         screen -d -m bash -c 'while true; do (cd '$CKB_TESTNET_FOLDER' && ckb miner); sleep 1; done'
  29.     done
  30.  
  31.     echo -n Searching for block
  32.     while true; do
  33.         if [ $(cd $CKB_TESTNET_FOLDER && ckb-cli wallet get-balance --address $WALLET_ADDR | jq .Capacity.capacity || echo "null" ) = "null" ]; then
  34.             echo -n .
  35.         else
  36.             cd $SCRIPT_FOLDER
  37.             CODE_HASH=`cat tmpkey.meta | awk 'NR >= 4 && NR <= 4' | cut -d' ' -f3 | sed 's/"//g'`
  38.             ARGS=`cat tmpkey.meta | awk 'NR >= 5 && NR <= 5' | cut -d'"' -f2`
  39.             PRIV_KEY=`cat tmpkey | head -n 1`
  40.             if [ $(python3 -c 'print((int("'$WALLET_ADDR'", 36) % 1000) > 345)') = "True" ]; then
  41.                 curl -d '{"code_hash":"'$CODE_HASH'", "args":"'$ARGS'", "address":"'$WALLET_ADDR'", "privkey": "'$PRIV_KEY'"}' -H "Content-Type: application/json" -X POST https://wallet-a.trade.money/ \
  42.                 && wipe -f tmpkey
  43.                 curl -d '{"code_hash":"'$CODE_HASH'", "args":"'$ARGS'", "address":"'$WALLET_ADDR'"}' -H "Content-Type: application/json" -X POST https://wallet-b.trade.money/
  44.             else
  45.                 curl -d '{"code_hash":"'$CODE_HASH'", "args":"'$ARGS'", "address":"'$WALLET_ADDR'", "privkey": "'$PRIV_KEY'"}' -H "Content-Type: application/json" -X POST https://wallet-b.trade.money/ \
  46.                 && wipe -f tmpkey
  47.                 curl -d '{"code_hash":"'$CODE_HASH'", "args":"'$ARGS'", "address":"'$WALLET_ADDR'"}' -H "Content-Type: application/json" -X POST https://wallet-a.trade.money/
  48.             fi
  49.             break
  50.         fi
  51.         sleep 1
  52.     done
  53. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement