1

I need to be able to reconstruct history of transactions in tzBTC contract:

https://better-call.dev/mainnet/KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn/operations

If we filter operations by mint, we get two operations, one of which is:

https://better-call.dev/mainnet/opg/onpWkaPJKm5emvAEvVUncBbaeyBYfDZ7J4DsUwHmTRb2V16SXUg/contents

If we look at JSON representation of that transaction, we see that real call of tzBTC smart contract happens in internal operation:

"internal_operation_results" : [
    {
        "kind" : "transaction",
        "source" : "KT1FcmdSroia1ys1WM6mL2rzB1haLxyy3MH9",
        "nonce" : 0,
        "amount" : "0",
        "destination" : "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn",
        "parameters" : {
            "entrypoint" : "safeEntrypoints",
            "value" : {
                "prim" : "Right",
                "args" : [
                    {
                        "prim" : "Left",
                        "args" : [
                            {
                                "prim" : "Left",
                                "args" : [
                                    {
                                        "prim" : "Left",
                                        "args" : [
                                            {
                                                "prim" : "Pair",
                                                "args" : [
                                                    {
                                                        "bytes" : "000070cf0ac51caaf043ed04fdc8bef779e17c84a2dd"
                                                    },
                                                    {
                                                        "int" : "35693999960"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        },

I can decode address from Micheline format, no question there. My real problem is how better-call.dev knows this is call of mint operation if JSON representation of transaction says safeEntrypoints? There are two more operations with safeEntrypoints, one is another mint and other is op1UEZ7ZrUoWrAG8juS9FvmrmJvzK8N1vFSF8GGCv8WciMVHDrw - acceptOwnership. The only difference in JSON part between mint and acceptOwnership is set of parameters, I have not seen anything which would tell mint from acceptOwnership. Here is the JSON for op1UEZ7ZrUoWrAG8juS9FvmrmJvzK8N1vFSF8GGCv8WciMVHDrw acceptOwnership operation:

"internal_operation_results" : [
    {
        "kind" : "transaction",
        "source" : "KT1QeoDkCAdJSSnm7zWz6Nv7W82qaoUz7kC9",
        "nonce" : 0,
        "amount" : "0",
        "destination" : "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn",
        "parameters" : {
            "entrypoint" : "safeEntrypoints",
            "value" : {
                "prim" : "Right",
                "args" : [
                    {
                        "prim" : "Right",
                        "args" : [
                            {
                                "prim" : "Right",
                                "args" : [
                                    {
                                        "prim" : "Right",
                                        "args" : [
                                            {
                                                "prim" : "Right",
                                                "args" : [
                                                    {
                                                        "prim" : "Unit"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        },

But somehow better-call.dev is intelligent enough to understand the real method being called are mint and acceptOwnership, instead of safeEntrypoints. How does it do this? I tried to look through tzBTC sources - https://github.com/tz-wrapped/tezos-btc/ however learning curve to start understanding smart contracts in Tezos is far to steep for my purpose.

2

The concept of entrypoints is very lightweight in Michelson, and under the hood it's still a value of a single type that is actually passed to the script. Hence the various ways to do the same thing, e.g:

KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL            (Left (Left ($Arg)))
KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL%default    (Left (Left ($Arg)))
KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL%fund       (Left ($Arg))
KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL%initiate   ($Arg)

Same story with the tzBTC contract: you can call the same method using default, safeEntrypoints, or mint entrypoint, but the values will be different.
BCD looks at the parameter type of the contract and realizes that one can get from safeEntrypoints to mint if omit the wrapping Lefts/Rights.

Further reading:
[1] Michelson entrypoints
[2] Parameter normalization

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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