Advertisement
Narayan

bashscript

Sep 1st, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.63 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. trap '' 2 # ignore ctrl+c
  4.  
  5. main_menu() {
  6.    while true
  7.       do
  8.          clear # Clear screen for each loop of menu
  9.          echo "============="
  10.          echo "Menu ---"
  11.          echo "============="
  12.          echo "[1] Send BTC to single address"
  13.          echo "[2] Send BTC to multiple addresses"
  14.          echo "[3] Check Balance"
  15.          echo "[4] Check transaction details"
  16.          echo "[0] Exit"
  17.          echo -e "Enter an option <return>"
  18.          read -r -p '> '  answer # Create variable to hold option
  19.  
  20.          case "$answer" in
  21.             1) send_single_BTC "$address"
  22.                ;;
  23.             2) send_to_mult_addr
  24.                ;;
  25.             3) check_balance
  26.                ;;
  27.             4) echo "Checking TxID details..."
  28.                ;;
  29.             0) echo "Exiting..."
  30.                exit
  31.                ;;
  32.          esac
  33.          echo -e "Hit <return> to continue"
  34.          read -r input
  35.       done
  36. }
  37.  
  38. send_single_BTC(){
  39.    echo "Which address to send:"
  40.    read -r -p '> ' address
  41.    confirm_input "address" "$address"
  42.    echo "How much BTC to send:"
  43.    read -r -p '> ' amount
  44.    confirm_input "amount" "$amount"
  45.    echo Sending "$amount" "BTC" to "$address"
  46.    echo bitcoin-cli sendtoaddress "$address" "$amount" false
  47.    echo "Transaction complete"
  48. }
  49.  
  50. check_balance(){
  51.    echo "Enter address to check balance:"
  52.    read -r -p '> ' address
  53.    confirm_input "address" "$address"
  54.    echo Checking Full Node data...
  55.    echo Address "$address" balance is:
  56.    bitcoin-cli getreceivedbyaddress "$address" 1
  57. }
  58.  
  59. confirm_input(){
  60.    echo Please confirm "$1" "$2". Type YES to confirm:
  61.    read -r -p'> ' input
  62.    if [ "$input" != "YES" ]; then
  63.       echo Action cancelled. "$input_type" not confirmed!
  64.       exit
  65.    fi
  66. }
  67.  
  68. load_addr_data(){
  69.    declare -ag addr_arr
  70.    
  71.    echo "Enter file path containing addresses:"
  72.    read -r -p '> ' addr_fp
  73.    if [ ! -f "$addr_fp" ]; then
  74.       echo "$addr_fp" not found!
  75.       return 1
  76.    fi
  77.    num_addr=$(wc -l "$addr_fp")
  78.    readarray -t addr_arr < "$addr_fp"
  79.    ((i++))
  80.    #while (( ${#addr_arr[@]} > i )); do
  81.    #   printf "${addr_arr[i++]}\n"
  82.    #done
  83. }
  84.  
  85. send_to_mult_addr(){
  86.    load_addr_data
  87.    val1=0.02
  88.    count=0
  89.    change_addr="bc1qqqr047m9quyvsgaqyf6h69kt5wzvnqdz4uydkc"
  90.    com_params="\"\" \"{\""
  91.    
  92.    for i in "${addr_arr[@]}"
  93.    do
  94.       ((count++))
  95.       com_params+="$i"
  96.       if [ "$count" -lt "$num_addr" ]; then
  97.          com_params+="\":$val1, "
  98.       else
  99.          com_params+="\":$val1"
  100.       fi
  101.    done
  102.    com_params+="}\" 6 \"Periodic payments\""
  103.    printf "%s" "$com_params"
  104. }
  105.  
  106. main_menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement