joininbox/scripts/menu.payjoin.sh

208 lines
4.4 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
2020-06-22 15:25:23 +01:00
source /home/joinmarket/joinin.conf
source /home/joinmarket/_functions.sh
checkRPCwallet
function receivePayJoin() {
# wallet
2020-06-22 15:15:43 +01:00
chooseWallet
# mixdepth
trap 'rm -f "$mixdepth"' EXIT
mixdepth=$(mktemp -p /dev/shm/)
dialog --backtitle "Choose a mixdepth to receive to" \
--title "Choose a mixdepth to receive to" \
--inputbox "
Enter a number between 0 to 4 to choose the mixdepth
(make sure there is at least one UTXO there already)" 10 60 2> $mixdepth
openMenuIfCancelled $?
# amount
trap 'rm -f "$amount"' EXIT
amount=$(mktemp -p /dev/shm/)
dialog --backtitle "Choose the amount" \
--title "Choose the amount" \
--inputbox "
Enter the amount to receive in satoshis" 9 60 2> $amount
openMenuIfCancelled $?
if [ ${RPCoverTor} = "on" ];then
2021-10-03 00:37:34 +01:00
tor="torsocks"
else
tor=""
fi
# check command
dialog --backtitle "Confirm the details" \
--title "Confirm the details" \
--yesno "
Receive: $(cat $amount) sats
To the wallet:
$(echo $(cat $wallet) | sed "s#$walletPath##g")
2020-07-16 13:31:25 +01:00
mixdepth: $(cat $mixdepth)
2020-07-16 13:31:25 +01:00
" 12 55
# make decision
pressed=$?
case $pressed in
0)
clear
2020-06-22 14:11:58 +01:00
# display
echo "Running the command:
$tor python receive-payjoin.py -m$(cat $mixdepth) \
$(echo $(cat $wallet) | sed "s#$walletPath##g") $(cat $amount)
"
2020-10-14 09:10:12 +01:00
echo "Will wait for the ephemeral Tor Hidden Service to be created.
Can cancel the process by pressing CTRL+C .
"
2020-06-22 14:11:58 +01:00
# run
$tor python ~/joinmarket-clientserver/scripts/receive-payjoin.py \
-m$(cat $mixdepth) $(cat $wallet) $(cat $amount)
;;
1)
echo "Cancelled"
exit 1
;;
255)
echo "ESC pressed."
exit 1
;;
esac
}
function sendPayJoin() {
# wallet
2020-06-22 15:15:43 +01:00
chooseWallet
# mixdepth
trap 'rm -f "$mixdepth"' EXIT
mixdepth=$(mktemp -p /dev/shm/)
dialog --backtitle "Choose a mixdepth to send from" \
--title "Choose a mixdepth to send from" \
--inputbox "
2020-06-22 15:15:43 +01:00
Enter a number between 0 to 4 to choose the mixdepth" 9 60 2> $mixdepth
openMenuIfCancelled $?
2020-07-16 13:31:25 +01:00
# receiveURI
trap 'rm -f "$receiveURI"' EXIT
receiveURI=$(mktemp -p /dev/shm/)
2020-07-16 13:31:25 +01:00
dialog --backtitle "Receive URI" \
--title "Receive URI" \
--inputbox "
2020-07-16 13:31:25 +01:00
Paste the Receive URI to send to" 9 60 2> $receiveURI
openMenuIfCancelled $?
2020-06-22 14:37:10 +01:00
# txfee
trap 'rm -f "$txfee"' EXIT
txfee=$(mktemp -p /dev/shm/)
dialog --backtitle "Choose the miner fee" \
--title "Choose the miner fee" \
--inputbox "
Enter the miner fee to be used for the transaction in sat/byte
Leave empty to use the default fee (set in the joinmarket.cfg)" 10 67 2> "$txfee"
openMenuIfCancelled $?
varTxfee=$(cat "$txfee")
if [ ${#varTxfee} -eq 0 ]; then
txfeeMessage="default (set in the joinmarket.cfg)"
txfeeOption=""
else
txfeeMessage="$varTxfee sat/byte"
if [ ${#varTxfee} -eq 1 ]; then
# https://github.com/openoms/joininbox/issues/64
txfeeOption="--txfee=1001"
else
txfeeOption="--txfee=$((varTxfee * 1000))"
fi
fi
if [ ${RPCoverTor} = "on" ]; then
2021-10-03 00:37:34 +01:00
tor="torsocks"
2020-06-22 14:37:10 +01:00
else
tor=""
fi
# check command
dialog --backtitle "Confirm the selections" \
--title "Confirm the details" \
--yesno "
Send to:
2020-07-16 13:31:25 +01:00
$(cat $receiveURI)
from the wallet:
$(sed "s#$walletPath##g" < "$wallet")
mixdepth: $(cat "$mixdepth")
Miner fee: $txfeeMessage
" 16 55
# make decision
pressed=$?
case $pressed in
0)
2020-06-22 14:37:10 +01:00
# display
echo "Running the command:
$tor python sendpayment.py -m$(cat "$mixdepth") \
$(sed "s#$walletPath##g" < "$wallet") \
$(cat "$receiveURI") $txfeeOption
2020-06-22 14:37:10 +01:00
"
# run
$tor python ~/joinmarket-clientserver/scripts/sendpayment.py \
-m"$(cat "$mixdepth")" "$(cat "$wallet")" "$(cat "$receiveURI")" $txfeeOption
;;
1)
echo "Cancelled"
exit 1
;;
255)
echo "ESC pressed."
exit 1
;;
esac
}
# BASIC MENU INFO
2020-10-14 09:10:12 +01:00
HEIGHT=8
WIDTH=48
CHOICE_HEIGHT=20
2020-10-14 09:10:12 +01:00
TITLE="PayJoin options"
2020-10-14 09:39:28 +01:00
MENU=""
OPTIONS=()
BACKTITLE="JoininBox GUI"
# Basic Options
OPTIONS+=(\
SEND "Send a payment with PayJoin" \
RECEIVE "Receive a payment with PayJoin" \
)
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--ok-label "Select" \
--cancel-label "Back" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
case $CHOICE in
2020-06-21 01:03:29 +01:00
RECEIVE)
receivePayJoin
2020-10-14 01:18:11 +01:00
echo ""
echo "Press ENTER to return to the menu..."
read key
2020-06-21 01:03:29 +01:00
;;
SEND)
sendPayJoin
2020-10-14 01:18:11 +01:00
echo ""
echo "Press ENTER to return to the menu..."
read key
;;
esac