9

I am trying to query the RPC parse operation endpoint

The RPC documentation only states that this endpoint Parse operations and I can't seem to find example of how to use it on the web.

What I am aim to do is basically reverse what the forge endpoint does in order to get the JSON from an hex encoded operation.

Here are the step I am using to query the endpoint:

Forge operation

Query:

POST
https://alphanet-node.tzscan.io/chains/main/blocks/head/helpers/forge/operations

Body:

{
    "branch": "BLpcXF8ADJbGuyUKNv7TypXRd5rqnoPn3PMqJLNBeRSr4VFeUuK",
    "contents": [
        {
            "kind": "transaction",
            "source": "tz1NfEiS2uJsX43vowNjau5pdqg3Nvy8whvc",
            "destination": "KT1Ec3jNXyxyA54nezwcjGDRoutECJCQjpya",
            "fee": "1274",
            "counter": "86610",
            "gas_limit": "10100",
            "storage_limit": "0",
            "amount": "5060726"
        }
    ]
}

Response:

"92122a7e654cdff09e22a7be1b7d41bd279ffa197a0137e6fea0d3ed3ce95fc00800002122d44d997e158c36c60649d198c4175dad425efa09d2a405f44e00f6f0b40201420eaa410ac21addf427211cddd6115cba385a940000"

Now trying to reverse the forge operation

Query:

https://alphanet-node.tzscan.io/chains/main/blocks/head/helpers/parse/operations

Body:

{
    "operations": [
        {
            "data": "92122a7e654cdff09e22a7be1b7d41bd279ffa197a0137e6fea0d3ed3ce95fc00800002122d44d997e158c36c60649d198c4175dad425efa09d2a405f44e00f6f0b40201420eaa410ac21addf427211cddd6115cba385a940000",
            "branch": "BLpcXF8ADJbGuyUKNv7TypXRd5rqnoPn3PMqJLNBeRSr4VFeUuK"
        }
    ]
}

Response:

[
    {
        "kind": "branch",
        "id": "proto.003-PsddFKi3.operation.cannot_parse"
    }
]

Is the parse operation endpoint really doing what I expect? If so how should this endpoint need to be queried to reverse the forge endpoint?

1 Answer 1

6
+50

The problem is that /parse/operations expects signed operations. You can just add 64 zero bytes to the end:

{
    "operations": [
        {
            "data": "0800002122d44d997e158c36c60649d198c4175dad425efa09d2a405f44e00f6f0b40201420eaa410ac21addf427211cddd6115cba385a94000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "branch": "BLpcXF8ADJbGuyUKNv7TypXRd5rqnoPn3PMqJLNBeRSr4VFeUuK"
        }
    ]
}

Be warned that if you trust the output of these RPCs, you are trusting the node.

Also notice that the "check_signature" option for /parse/operations has no effect, as you can see by setting it to true...

4
  • 1
    Could you give a complete example of this, doing a forge, sign, then parse? Even after adding the 0's, I still cannot get parse to work.
    – utdrmac
    Sep 17, 2019 at 5:18
  • I guess the question + answer gives a complete example, I might expand the answer sometime later. Two quick checks: You added 128 zeros (= 64 zero bytes)? You stripped off the first 32 bytes (64 characters) from forge, which are the branch / block hash? (I failed to mention that in my answer.)
    – Tom
    Sep 18, 2019 at 8:32
  • The above examples all deal with transfer operations and I was trying to decode an endorsement. They are a bit different. I was able to get it working after reading some other posts and ocaml code. Thanks
    – utdrmac
    Sep 19, 2019 at 14:40
  • I think your data value might contain an odd number of hex characters. Could you verify that you can actually run this code again and update the answer if anything is missing? Also: Is this main net or a test net like Carthage net? Sep 20, 2020 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.