Skip to content

Instantly share code, notes, and snippets.

@tyzbit
Last active April 23, 2018 21:42
Show Gist options
  • Save tyzbit/8b0c6601318acd29da5832101aa9f96e to your computer and use it in GitHub Desktop.
Save tyzbit/8b0c6601318acd29da5832101aa9f96e to your computer and use it in GitHub Desktop.
#!/bin/bash
nodenames=(
"alice"
"bob"
"charlie"
"derek"
"emily"
"frank"
"gina"
"heather"
"irene"
)
# generate an invoice, takes node name and amt
geninvoice() {
docker exec -it $1 lncli addinvoice --amt $2 | grep -Po "pay_req\": \"\K[^\"]+"
}
# pay an invoice, takes nodename and invoice
payinvoice() {
docker exec -it $1 lncli payinvoice $2
}
# simulate a payment, arg is a string of two node IDs
simpayment() {
sender=${1%[0-9]}
receiver=${1#[0-9]}
echo "Trying to make ${nodenames[$sender]} pay ${nodenames[$receiver]}"
invoice=$(geninvoice ${nodenames[$receiver]} 20000)
payinvoice ${nodenames[$sender]} $invoice
}
if [[ -z $1 ]]; then
i=0; for n in ${nodenames[@]}; do
echo "$n: $i"
let i=i+1
done
echo "To transact, pick two numbers and concactenate them."
echo "example: for alice to pay bob, enter 01"
read -p "Pick nodes to transact: " t
simpayment $t
else
simpayment $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment