From 9d4d939b89cbe6c589ba16926242abcc8f081d9e Mon Sep 17 00:00:00 2001 From: Zach Ramsay Date: Thu, 18 Jan 2018 15:35:00 +0000 Subject: [PATCH 1/2] docs: tx formats: closes #1083, #536 --- docs/using-tendermint.rst | 53 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/using-tendermint.rst b/docs/using-tendermint.rst index a7749d47b..7956a972a 100644 --- a/docs/using-tendermint.rst +++ b/docs/using-tendermint.rst @@ -68,7 +68,7 @@ Transactions ------------ To send a transaction, use ``curl`` to make requests to the Tendermint -RPC server: +RPC server, for example: :: @@ -93,6 +93,54 @@ Visit http://localhost:46657 in your browser to see the list of other endpoints. Some take no arguments (like ``/status``), while others specify the argument name and use ``_`` as a placeholder. +Formatting +~~~~~~~~~~ + +The following nuances when sending/formatting transactions should +be taken into account: + +With ``GET``: + +To send a UTF8 string byte array, quote the value of the tx pramater: + +:: + + curl http://localhost:46657/broadcast_tx_commit?tx="hello" + +which sends a 5 byte transaction: "h e l l o" [68 65 6c 6c 6f]. + +Using a special character: + +:: + + curl http://localhost:46657/broadcast_tx_commit?tx="€5" + +sends a 4 byte transaction: "€5" (UTF8) [e2 82 ac 35]. + +To send as raw hex, omit quotes AND prefix the hex string with ``0x``: + +:: + + curl http://localhost:46657/broadcast_tx_commit?tx=0x01020304 + +which sends a 4 byte transaction: [01 02 03 04]. + +With ``POST`` (using ``json``), the raw hex must be ``base64`` encoded: + +:: + + curl -X POST http://localhots:46657 + { + "method": broadcast_tx_commit", + "jsonrpc": "2.0", + "params": {"tx": "AQIDBA=="}, + "id": "" + } + +which sends the same 4 byte transaction: [01 02 03 04]. + +Note that raw hex cannot be used in ``POST`` transactions. + Reset ----- @@ -196,6 +244,9 @@ can take on the order of a second. For a quick result, use ``broadcast_tx_sync``, but the transaction will not be committed until later, and by that point its effect on the state may change. +Note: see the Transactions => Formatting section for details about +transaction formating. + Tendermint Networks ------------------- From e764a180d8e60f76554238a225ecde3e759b50df Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 18 Jan 2018 18:58:21 -0500 Subject: [PATCH 2/2] docs: fix tx formats [ci skip] --- docs/using-tendermint.rst | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/using-tendermint.rst b/docs/using-tendermint.rst index 7956a972a..f4b0cb089 100644 --- a/docs/using-tendermint.rst +++ b/docs/using-tendermint.rst @@ -105,15 +105,24 @@ To send a UTF8 string byte array, quote the value of the tx pramater: :: - curl http://localhost:46657/broadcast_tx_commit?tx="hello" + curl 'http://localhost:46657/broadcast_tx_commit?tx="hello"' which sends a 5 byte transaction: "h e l l o" [68 65 6c 6c 6f]. +Note the URL must be wrapped with single quoes, else bash will ignore the double quotes. +To avoid the single quotes, escape the double quotes: + +:: + + curl http://localhost:46657/broadcast_tx_commit?tx=\"hello\" + + + Using a special character: :: - curl http://localhost:46657/broadcast_tx_commit?tx="€5" + curl 'http://localhost:46657/broadcast_tx_commit?tx="€5"' sends a 4 byte transaction: "€5" (UTF8) [e2 82 ac 35]. @@ -129,13 +138,7 @@ With ``POST`` (using ``json``), the raw hex must be ``base64`` encoded: :: - curl -X POST http://localhots:46657 - { - "method": broadcast_tx_commit", - "jsonrpc": "2.0", - "params": {"tx": "AQIDBA=="}, - "id": "" - } + curl --data-binary '{"jsonrpc":"2.0","id":"anything","method":"broadcast_tx_commit","params": {"tx": "AQIDBA=="}}' -H 'content-type:text/plain;' http://localhost:46657 which sends the same 4 byte transaction: [01 02 03 04].