Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@askz
Last active May 29, 2018 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askz/744ea7706dd6dbc816c688f0c74e3098 to your computer and use it in GitHub Desktop.
Save askz/744ea7706dd6dbc816c688f0c74e3098 to your computer and use it in GitHub Desktop.
Universal rpc call
#!/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