Client: rename rpc call into rpc post or rpc get

This commit is contained in:
Grégoire Henry 2018-04-16 00:44:22 +02:00
parent 642036b226
commit 556e95cef0
13 changed files with 80 additions and 50 deletions

View File

@ -5,11 +5,11 @@ Usage
***** *****
In order to interact with a Tezos node, you may use RPC calls through the In order to interact with a Tezos node, you may use RPC calls through the
client using this command ``tezos-admin-client rpc call <url>``. client using this command ``tezos-admin-client rpc post <url>``.
For instance, if you wish to request the current balance of a given For instance, if you wish to request the current balance of a given
block and contract, you can call the associated RPC via the command : block and contract, you can call the associated RPC via the command :
``$ tezos-admin-client rpc call ``$ tezos-admin-client rpc post
/blocks/<block_id>/proto/context/contracts/<contract_id>/balance``. /blocks/<block_id>/proto/context/contracts/<contract_id>/balance``.
A RPC may takes an *input* and generates an *output* both in JSON A RPC may takes an *input* and generates an *output* both in JSON
@ -19,7 +19,7 @@ input, would display on the standard output : ``{ "balance":
through command-line, you will be prompted to provide the JSON input through command-line, you will be prompted to provide the JSON input
in your default configured text editor. Alternatively, you can provide in your default configured text editor. Alternatively, you can provide
the JSON input using command the JSON input using command
``$ tezos-admin-client rpc call <url> with <JSON>``. Don't forget to quote ``$ tezos-admin-client rpc post <url> with <JSON>``. Don't forget to quote
the JSON according to your shell rules. the JSON according to your shell rules.
You can also obtain the list of RPCs on the command line with You can also obtain the list of RPCs on the command line with

View File

@ -275,7 +275,7 @@ Check out the Alphanet *constants* for this:
:: ::
./alphanet.sh client rpc call /blocks/head/proto/constants ./alphanet.sh client rpc get /blocks/head/proto/constants
Check for the ``endorsement_security_deposit`` and Check for the ``endorsement_security_deposit`` and
``block_security_deposit`` keys of the JSON record. The value is in ``block_security_deposit`` keys of the JSON record. The value is in
@ -318,7 +318,10 @@ the appropriate value:
$ ./alphanet.sh client list known identities $ ./alphanet.sh client list known identities
my_identity: tz1iFY8aDskx9QGbgBy68SNAGgkc7AE2iG9H (public key known) (secret key known) my_identity: tz1iFY8aDskx9QGbgBy68SNAGgkc7AE2iG9H (public key known) (secret key known)
$ ./alphanet.sh client rpc call /blocks/head/proto/helpers/rights/baking/delegate/tz1iFY8aDskx9QGbgBy68SNAGgkc7AE2iG9H with '{}' $ ./alphanet.sh client rpc post /blocks/head/proto/helpers/rights/baking/delegate/tz1iFY8aDskx9QGbgBy68SNAGgkc7AE2iG9H with '{}'
[ { "level": 1400.000000, "priority": 2.000000,"timestamp": "2017-05-19T03:21:52Z" }, ... ] { "ok":
[ { "level": 1400.000000, "priority": 2.000000,
"timestamp": "2017-05-19T03:21:52Z" },
... ] }
.. include:: alphanet_changes.rst .. include:: alphanet_changes.rst

View File

@ -277,7 +277,7 @@ preconfigured for communicating the same-numbered node. For instance:
:: ::
$ tezos-client rpc call blocks/head/hash $ tezos-client rpc post blocks/head/hash
{ "hash": "BLockGenesisGenesisGenesisGenesisGenesisGeneskvg68z" } { "hash": "BLockGenesisGenesisGenesisGenesisGenesisGeneskvg68z" }
When you bootstrap a new network, the network is initialized with a When you bootstrap a new network, the network is initialized with a
@ -288,11 +288,11 @@ activating the whole network. For instance:
:: ::
$ tezos-client rpc call blocks/head/protocol $ tezos-client rpc post blocks/head/protocol
{ "protocol": "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im" } { "protocol": "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im" }
$ tezos-activate-alpha $ tezos-activate-alpha
Injected BMBcK869jaHQDc Injected BMBcK869jaHQDc
$ tezos-client rpc call blocks/head/protocol $ tezos-client rpc post blocks/head/protocol
{ "protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" } { "protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" }
Tune protocol alpha parameters Tune protocol alpha parameters

View File

@ -381,8 +381,8 @@ run_shell() {
display_head() { display_head() {
assert_node_uptodate assert_node_uptodate
exec_docker tezos-client rpc call /blocks/head with '{}' exec_docker tezos-client rpc post /blocks/head with '{}'
exec_docker tezos-client rpc call /blocks/head/proto/context/level with '{}' exec_docker tezos-client rpc post /blocks/head/proto/context/level with '{}'
} }
## Main #################################################################### ## Main ####################################################################

View File

@ -19,10 +19,10 @@ configure_client() {
wait_for_the_node_to_be_ready() { wait_for_the_node_to_be_ready() {
local count=0 local count=0
if "$client" rpc call /blocks/head/hash >/dev/null 2>&1; then return; fi if "$client" rpc post /blocks/head/hash >/dev/null 2>&1; then return; fi
printf "Waiting for the node to initialize..." printf "Waiting for the node to initialize..."
sleep 1 sleep 1
while ! "$client" rpc call /blocks/head/hash >/dev/null 2>&1 while ! "$client" rpc post /blocks/head/hash >/dev/null 2>&1
do do
count=$((count+1)) count=$((count+1))
if [ "$count" -ge 30 ]; then if [ "$count" -ge 30 ]; then

View File

@ -290,12 +290,12 @@ let list url (cctxt : #Client_context.full) =
end else return () end else return ()
let schema url (cctxt : #Client_context.full) = let schema meth url (cctxt : #Client_context.full) =
let args = String.split '/' url in let args = String.split '/' url in
let open RPC_description in let open RPC_description in
RPC_description.describe cctxt ~recurse:false args >>=? function RPC_description.describe cctxt ~recurse:false args >>=? function
| Static { services } -> begin | Static { services } -> begin
match RPC_service.MethMap.find `POST services with match RPC_service.MethMap.find meth services with
| exception Not_found -> | exception Not_found ->
cctxt#message cctxt#message
"No service found at this URL (but this is a valid prefix)\n%!" >>= fun () -> "No service found at this URL (but this is a valid prefix)\n%!" >>= fun () ->
@ -315,12 +315,12 @@ let schema url (cctxt : #Client_context.full) =
"No service found at this URL (but this is a valid prefix)\n%!" >>= fun () -> "No service found at this URL (but this is a valid prefix)\n%!" >>= fun () ->
return () return ()
let format url (cctxt : #Client_context.io_rpcs) = let format meth url (cctxt : #Client_context.io_rpcs) =
let args = String.split '/' url in let args = String.split '/' url in
let open RPC_description in let open RPC_description in
RPC_description.describe cctxt ~recurse:false args >>=? function RPC_description.describe cctxt ~recurse:false args >>=? function
| Static { services } -> begin | Static { services } -> begin
match RPC_service.MethMap.find `POST services with match RPC_service.MethMap.find meth services with
| exception Not_found -> | exception Not_found ->
cctxt#message cctxt#message
"No service found at this URL (but this is a valid prefix)\n%!" >>= fun () -> "No service found at this URL (but this is a valid prefix)\n%!" >>= fun () ->
@ -366,18 +366,19 @@ let display_answer (cctxt : #Client_context.full) = function
cctxt#message "Unexpected server answer\n%!" >>= fun () -> cctxt#message "Unexpected server answer\n%!" >>= fun () ->
return () return ()
let call raw_url (cctxt : #Client_context.full) = let call meth raw_url (cctxt : #Client_context.full) =
let uri = Uri.of_string raw_url in let uri = Uri.of_string raw_url in
let args = String.split_path (Uri.path uri) in let args = String.split_path (Uri.path uri) in
RPC_description.describe cctxt ~recurse:false args >>=? function RPC_description.describe cctxt ~recurse:false args >>=? function
| Static { services } -> begin | Static { services } -> begin
match RPC_service.MethMap.find `POST services with match RPC_service.MethMap.find meth services with
| exception Not_found -> | exception Not_found ->
cctxt#message cctxt#message
"No service found at this URL (but this is a valid prefix)\n%!" >>= fun () -> "No service found at this URL with this method \
(but this is a valid prefix)\n%!" >>= fun () ->
return () return ()
| { input = None } -> | { input = None } ->
cctxt#generic_json_call `POST uri >>=? cctxt#generic_json_call meth uri >>=?
display_answer cctxt display_answer cctxt
| { input = Some input } -> | { input = Some input } ->
fill_in ~show_optionals:false input >>= function fill_in ~show_optionals:false input >>= function
@ -385,14 +386,14 @@ let call raw_url (cctxt : #Client_context.full) =
cctxt#error "%s" msg >>= fun () -> cctxt#error "%s" msg >>= fun () ->
return () return ()
| Ok json -> | Ok json ->
cctxt#generic_json_call `POST ~body:json uri >>=? cctxt#generic_json_call meth ~body:json uri >>=?
display_answer cctxt display_answer cctxt
end end
| _ -> | _ ->
cctxt#message "No service found at this URL\n%!" >>= fun () -> cctxt#message "No service found at this URL\n%!" >>= fun () ->
return () return ()
let call_with_json raw_url json (cctxt: #Client_context.full) = let call_with_json meth raw_url json (cctxt: #Client_context.full) =
let uri = Uri.of_string raw_url in let uri = Uri.of_string raw_url in
match Data_encoding.Json.from_string json with match Data_encoding.Json.from_string json with
| exception Assert_failure _ -> | exception Assert_failure _ ->
@ -404,10 +405,10 @@ let call_with_json raw_url json (cctxt: #Client_context.full) =
"Failed to parse the provided json: %s\n%!" "Failed to parse the provided json: %s\n%!"
err err
| Ok body -> | Ok body ->
cctxt#generic_json_call `POST ~body uri >>=? cctxt#generic_json_call meth ~body uri >>=?
display_answer cctxt display_answer cctxt
let call_with_file_or_json url maybe_file (cctxt: #Client_context.full) = let call_with_file_or_json meth url maybe_file (cctxt: #Client_context.full) =
begin begin
match TzString.split ':' ~limit:1 maybe_file with match TzString.split ':' ~limit:1 maybe_file with
| [ "file" ; filename] -> | [ "file" ; filename] ->
@ -421,7 +422,20 @@ let call_with_file_or_json url maybe_file (cctxt: #Client_context.full) =
"cannot read file (%s)" (Printexc.to_string exn)) "cannot read file (%s)" (Printexc.to_string exn))
| _ -> return maybe_file | _ -> return maybe_file
end >>=? fun json -> end >>=? fun json ->
call_with_json url json cctxt call_with_json meth url json cctxt
let meth_params ?(name = "HTTP method") ?(desc = "") params =
param ~name ~desc
(parameter ~autocomplete:(fun _ ->
return @@
List.map String.lowercase_ascii @@
List.map Resto.string_of_meth @@
[ `GET ; `POST ; `DELETE ; `PUT ; `PATCH ])
(fun _ name ->
match Resto.meth_of_string (String.uppercase_ascii name) with
| None -> failwith "Unknown HTTP method: %s" name
| Some meth -> return meth))
params
let group = let group =
{ Clic.name = "rpc" ; { Clic.name = "rpc" ;
@ -448,32 +462,45 @@ let commands = [
command ~group command ~group
~desc: "Get the input and output JSON schemas of an RPC." ~desc: "Get the input and output JSON schemas of an RPC."
no_options no_options
(prefixes [ "rpc" ; "schema" ] @@ string ~name: "url" ~desc: "the RPC url" @@ stop) (prefixes [ "rpc" ; "schema" ] @@
meth_params @@
string ~name: "url" ~desc: "the RPC url" @@
stop)
(fun () -> schema) ; (fun () -> schema) ;
command ~group command ~group
~desc: "Get the humanoid readable input and output formats of an RPC." ~desc: "Get the humanoid readable input and output formats of an RPC."
no_options no_options
(prefixes [ "rpc" ; "format" ] @@ string ~name: "url" ~desc: "the RPC URL" @@ stop) (prefixes [ "rpc" ; "format"] @@
meth_params @@
string ~name: "url" ~desc: "the RPC URL" @@
stop)
(fun () -> format) ; (fun () -> format) ;
command ~group command ~group
~desc: "Call an RPC.\n\ ~desc: "Call an RPC with the GET method."
If input data is needed, a text editor will be popped up."
no_options no_options
(prefixes [ "rpc" ; "call" ] @@ string ~name: "url" ~desc: "the RPC URL" @@ stop) (prefixes [ "rpc" ; "get" ] @@ string ~name: "url" ~desc: "the RPC URL" @@ stop)
(fun () -> call) ; (fun () -> call `GET) ;
command ~group command ~group
~desc: "Call an RPC providing input data via the command line." ~desc: "Call an RPC with the POST method.\n\
If input data is needed, a text editor will be popped up."
no_options no_options
(prefixes [ "rpc" ; "call" ] @@ string ~name: "url" ~desc: "the RPC URL" (prefixes [ "rpc" ; "post" ] @@ string ~name: "url" ~desc: "the RPC URL" @@ stop)
(fun () -> call `POST) ;
command ~group
~desc: "Call an RPC with the POST method, \
\ providing input data via the command line."
no_options
(prefixes [ "rpc" ; "post" ] @@ string ~name: "url" ~desc: "the RPC URL"
@@ prefix "with" @@ prefix "with"
@@ string ~name:"input" @@ string ~name:"input"
~desc:"the raw JSON input to the RPC\n\ ~desc:"the raw JSON input to the RPC\n\
For instance, use `{}` to send the empty document.\n\ For instance, use `{}` to send the empty document.\n\
Alternatively, use `file:path` to read the JSON data from a file." Alternatively, use `file:path` to read the JSON data from a file."
@@ stop) @@ stop)
(fun () -> call_with_file_or_json) (fun () -> call_with_file_or_json `POST)
] ]

View File

@ -13,13 +13,13 @@ $client -w none config update
sleep 2 sleep 2
#tests for the rpc service raw_context #tests for the rpc service raw_context
$client rpc call '/blocks/head/raw_context/version' | assert '{ "content": "616c706861" }' $client rpc post '/blocks/head/raw_context/version' | assert '{ "content": "616c706861" }'
$client rpc call '/blocks/head/raw_context/non-existent' | assert 'No service found at this URL' $client rpc post '/blocks/head/raw_context/non-existent' | assert 'No service found at this URL'
$client rpc call '/blocks/head/raw_context/delegates/?depth=2' | assert '{ "content": $client rpc post '/blocks/head/raw_context/delegates/?depth=2' | assert '{ "content":
{ "ed25519": { "ed25519":
{ "02": null, "a9": null, "c5": null, "da": null, "e7": null } } }' { "02": null, "a9": null, "c5": null, "da": null, "e7": null } } }'
$client rpc call '/blocks/head/raw_context/non-existent?depth=-1' | assert 'No service found at this URL' $client rpc post '/blocks/head/raw_context/non-existent?depth=-1' | assert 'No service found at this URL'
$client rpc call '/blocks/head/raw_context/non-existent?depth=0' | assert 'No service found at this URL' $client rpc post '/blocks/head/raw_context/non-existent?depth=0' | assert 'No service found at this URL'
bake bake

View File

@ -37,7 +37,7 @@ $admin_client list protocols
#these commands cannot be used in this case because the client does not #these commands cannot be used in this case because the client does not
#know about the new protocol #know about the new protocol
#$client --protocol $protocol_short bake for bootstrap1 -max-priority 512 #$client --protocol $protocol_short bake for bootstrap1 -max-priority 512
#$client --protocol $protocol_version rpc call /blocks/head with {} #$client --protocol $protocol_version rpc post /blocks/head with {}
echo echo
echo End of test echo End of test

View File

@ -19,7 +19,7 @@ protocol_version="PsxS1brZfzzXCiFwirbMtQr4X5XR6SiHQ46HajpFDdk9GBXR6vy"
$admin_client inject protocol "$test_dir/demo" $admin_client inject protocol "$test_dir/demo"
$admin_client list protocols $admin_client list protocols
$client activate protocol $protocol_version with fitness 1 and key dictator and parameters $parameters_file $client activate protocol $protocol_version with fitness 1 and key dictator and parameters $parameters_file
answ=$($client -p ProtoALphaALph rpc call /blocks/head/protocol with {} 2>/dev/null) answ=$($client -p ProtoALphaALph rpc post /blocks/head/protocol with {} 2>/dev/null)
if ! grep "$protocol_version" <<< $answ ; then if ! grep "$protocol_version" <<< $answ ; then
exit 1 exit 1

View File

@ -37,7 +37,7 @@ $admin_client list protocols
#these commands cannot be used in this case because the client does not #these commands cannot be used in this case because the client does not
#know about the new protocol #know about the new protocol
#$client --protocol $protocol_short bake for bootstrap1 -max-priority 512 #$client --protocol $protocol_short bake for bootstrap1 -max-priority 512
#$client --protocol $protocol_version rpc call /blocks/head with {} #$client --protocol $protocol_version rpc post /blocks/head with {}
echo echo
echo End of test echo End of test

View File

@ -40,7 +40,7 @@ assert_propagation_level() {
level=$1 level=$1
printf "\n\nAsserting all nodes have reached level %s\n" "$level" printf "\n\nAsserting all nodes have reached level %s\n" "$level"
for client in "${client_instances[@]}"; do for client in "${client_instances[@]}"; do
( $client rpc call /blocks/head/proto/context/level \ ( $client rpc post /blocks/head/proto/context/level \
| assert_in_output "\"level\": $level" ) \ | assert_in_output "\"level\": $level" ) \
|| exit 2 || exit 2
done done
@ -51,7 +51,7 @@ assert_protocol() {
proto=$1 proto=$1
printf "\n\nAsserting protocol propagation\n" printf "\n\nAsserting protocol propagation\n"
for client in "${client_instances[@]}"; do for client in "${client_instances[@]}"; do
( $client rpc call /blocks/head/protocol | assert_in_output "$proto" ) \ ( $client rpc post /blocks/head/protocol | assert_in_output "$proto" ) \
|| exit 2 || exit 2
done done
} }
@ -102,7 +102,7 @@ assert_contains_operation() {
hash="$1" hash="$1"
printf "Asserting operations list contains '$hash'\n" printf "Asserting operations list contains '$hash'\n"
for client in "${client_instances[@]}"; do for client in "${client_instances[@]}"; do
( $client rpc call /blocks/head/operations with {} \ ( $client rpc post /blocks/head/operations with {} \
| assert_in_output $hash ) \ | assert_in_output $hash ) \
|| exit 2 || exit 2
done done

View File

@ -57,10 +57,10 @@ cleanup_clients() {
wait_for_the_node_to_be_ready() { wait_for_the_node_to_be_ready() {
local count=0 local count=0
if $client rpc call blocks/head/hash >/dev/null 2>&1; then return; fi if $client rpc post blocks/head/hash >/dev/null 2>&1; then return; fi
printf "Waiting for the node to initialize..." printf "Waiting for the node to initialize..."
sleep 1 sleep 1
while ! $client rpc call blocks/head/hash >/dev/null 2>&1 while ! $client rpc post blocks/head/hash >/dev/null 2>&1
do do
count=$((count+1)) count=$((count+1))
if [ "$count" -ge 30 ]; then if [ "$count" -ge 30 ]; then
@ -301,7 +301,7 @@ The client is now properly initialized. In the rest of this shell
session, you might now run \`tezos-client\` to communicate with a session, you might now run \`tezos-client\` to communicate with a
tezos node launched with \`launch-sandboxed-node $1\`. For instance: tezos node launched with \`launch-sandboxed-node $1\`. For instance:
tezos-client rpc call blocks/head/protocol tezos-client rpc post blocks/head/protocol
Note: if the current protocol version, as reported by the previous Note: if the current protocol version, as reported by the previous
command, is "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im", you command, is "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im", you

View File

@ -160,7 +160,7 @@ module S : sig
block <id>. The optional parameter <depth> controls the size of the block <id>. The optional parameter <depth> controls the size of the
tree, default is 1. tree, default is 1.
Example: Example:
tezos-client rpc call /blocks/head/raw_context/v1?depth=2 tezos-client rpc post /blocks/head/raw_context/v1?depth=2
*) *)
val raw_context: val raw_context:
([ `POST ], unit, ([ `POST ], unit,