Last active
May 29, 2018 08:02
-
-
Save askz/744ea7706dd6dbc816c688f0c74e3098 to your computer and use it in GitHub Desktop.
Universal rpc call
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 | |
TICKER=$(echo $1 | tr '[:upper:]' '[:lower:]') | |
METHOD=$2 | |
PARAMS="${@:3}" | |
RPCUSER=main | |
RPCPORT=net | |
function join_by { local IFS="$1"; shift; echo "$*"; } | |
function usage { echo "$0 <BTC|KMD|MNZ> <method> [param1 param2 ...]"; } | |
if [[ -z $TICKER ]]; then | |
usage; | |
exit 1; | |
fi | |
if [[ -z $METHOD ]]; then | |
usage; | |
exit 1; | |
fi | |
if [[ ! -z $PARAMS ]]; then | |
JSONPARAMS=$(jq -n --arg method "$METHOD" --arg v "$PARAMS" '{ "method": $method, "params": ($v|split(" "))}' ) | |
else | |
JSONPARAMS=$(jq -n --arg method "$METHOD" '{ "method": $method }') | |
fi | |
function rpc_call { echo $(echo $JSONPARAMS | http --auth $RPCUSER:$RPCPORT POST localhost:$1 -b | jq '.result'); } | |
function btc { echo $(rpc_call 8332 $1); } | |
function mnz { echo $(rpc_call 14337 $1); } | |
function kmd { echo $(rpc_call 7771 $1); } | |
echo $("$TICKER" $JSONPARAMS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment