Created
April 8, 2018 18:27
-
-
Save davidlj95/b0d55521de3aa8b76fed011cf1985bd4 to your computer and use it in GitHub Desktop.
Extends the functionality of the bitcoin-cli tool allowing to select multiple configurations with the first parameter and other extra cool funcs
This file contains 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 | |
# Description: Allows to switch between RPC | |
# client configurations inside | |
# ~/.bitcoin folder. If no | |
# config found, takes default | |
# Usage: | |
# bitcoin-cli <node_config> [args] | |
# | |
# Passes ~/.bitcoin/<node_config>.conf as | |
# the configuration file to bitcoin-cli | |
# command | |
# | |
# Arguments: | |
# CONFIG: Name of the configuration file | |
CONFIG="$1" | |
# Constants: | |
# APP: Binary of real bitcoin-cli | |
APP="/usr/local/bin/bitcoin-cli" | |
# CONF_DIR: Directory where Bitcoin configs | |
# are saved | |
CONF_DIR="$HOME/.bitcoin" | |
# 1. Check if passed config | |
opt_config="" | |
# No-config | |
if [[ ! -z "$1" ]]; then | |
# Existing config | |
config_file="$CONF_DIR/$1.conf" | |
if [[ -f "$config_file" ]]; then | |
opt_config="-conf=$1.conf" | |
shift | |
else | |
# Configuration does not exist, taking defaults | |
echo "Configuration $config_file does not exist" | |
echo "Using default bitcoin.conf" | |
fi | |
fi | |
# 2. Decode by tx id | |
if [[ "$1" == "decoderawtransaction" ]] && [[ ${#2} -eq 64 ]]; then | |
raw_tx=$("$APP" $opt_config "getrawtransaction" "${2}") | |
# Not found raw tx | |
if [[ -z "$raw_tx" ]]; then | |
echo "The tx was not found" | |
exit | |
else | |
# Second parameter must be raw tx | |
set -- "${@:1:1}" "$raw_tx" "${@:3}" | |
fi | |
fi | |
# Call bitcoin-cli | |
"$APP" $opt_config "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment