Last active
April 23, 2018 21:42
-
-
Save tyzbit/8b0c6601318acd29da5832101aa9f96e to your computer and use it in GitHub Desktop.
Pay invoices in a simnet cluster (https://gist.github.com/tyzbit/a61179794856566a46b9c0eebe1f9f92)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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