-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbcurl.bash
More file actions
executable file
·45 lines (39 loc) · 1.13 KB
/
bcurl.bash
File metadata and controls
executable file
·45 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
method=$1
# This doesn't work with boolean inputs. They're currently being quoted, they should not be.
# re='^[0-9]+([0-9]?[.][0-9]+)?$'
re='^[0-9]+([.][0-9]+)?$'
bool_re='^(true|false)'
params=""
total=$#
((counter=1))
for var in $@
do
# if it's the first argument ($1, the method name), skip it
if [[ $counter -eq 1 ]]
then
((counter=counter + 1))
continue
fi
# If variable is a number,
if [[ $var =~ $re ]]
then
# Don't put in quotes
params="$params $var"
# var is a word
else
# put the word var in quotes
params="$params \"$var\""
fi
#if it's not the last var, add a comma
if [[ $counter -ne $total ]]
then
params="$params,"
# it is the last var, so don't add a comma
else
params="$params"
fi
((counter=counter + 1))
done
# Uncomment out --trace-ascii /dev/stdout to get verbose trace data on curl POST
curl --user u:p --data-binary "{\"jsonrpc\": \"1.0\", \"id\":\"bcurl\", \"method\": \"$1\", \"params\": [$params]}" -H 'content-type: text/plain'\; http://dev.sndl.io:18332/ | underscore print --outfmt pretty #--trace-ascii /dev/stdout