Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # NOTE: Depends on "jq" - http://stedolan.github.io/jq/
- #
- # example of call: getblockhash [12345]
- # getrawtransaction ["6ab513d9bc689089de3b5e2130a2dad70af76f2b108dc30e81a836e9abb31a4e"]
- #
- if [ '$1' == '' ]; then
- echo "Usage: $0 <url> [username] [password]"
- exit 1
- fi
- server="$1"
- prompt="$server>"
- username="$2"
- password="$3"
- history -r ~/.jsonrpc-netcat.hist
- while read -p "$prompt" -e line; do
- if [ "$line" != "" ]; then
- history -s "$line"
- cmd="$( cut -d '[' -f 1 <<< "$line" )"
- args="$( cut -d '[' -f 2- <<< "$line" )"
- args="[$args"
- cmd="$( cut -d ' ' -f 1 <<< "$cmd" )"
- request="{\"method\":\"$cmd\", \"params\":$args, \"id\":\"foo\"}"
- result=$(wget --http-user=$username -nv --http-password=$password --progress=dot --header="Content-Type: application/json" --header="Accept: application/json" "--post-data=$request" --header="Connection: close" -O - $server)
- echo -n "ERROR: "
- echo $result | jq .error
- echo -n "RESULT: "
- echo $result | jq .result
- fi;
- done
- echo ""
- history -w ~/.jsonrpc-netcat.hist
Advertisement
Add Comment
Please, Sign In to add comment