Skip to content

Instantly share code, notes, and snippets.

@vindard
Created May 16, 2021 15:10
Show Gist options
  • Save vindard/afbfcc403db4c76ea7cb51b734f6d84c to your computer and use it in GitHub Desktop.
Save vindard/afbfcc403db4c76ea7cb51b734f6d84c to your computer and use it in GitHub Desktop.
Lightning Network chan_id format converter
#!/bin/bash
# Usage: pass any number of chan_id values with 'x' character in them to be converted
# e.g. $ ./chan_id.sh 674831x113x1
convert() {
export VAL=$1
if [[ ! -z $VAL ]]; then
CONV=$(python3 -c "import os; arr = os.environ.get('VAL', '').rstrip().split('x'); print( (int(arr[0]) << 40) + (int(arr[1]) << 16) + int(arr[2]) )")
fi
echo "$VAL -> $CONV"
}
for i in "$@"; do
convert $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment