ava-labs / avalanchejs

The Avalanche Platform JavaScript Library
Other
321 stars 164 forks source link

Questions Regarding Deserialization of blockExtraData #870

Open SebastianGruza opened 3 months ago

SebastianGruza commented 3 months ago

Context I have been working on decoding blockExtraData in the Avalanche C-Chain and encountered some issues. I noticed the decoder code in the "legacy" branch and have some questions regarding its functionality and location in the newer branches.

  1. Location of blockExtraData Decoder Why is the decoder code added to blockExtraData in AvalancheJS only present in the "legacy" branch (blockExtraDataDecoder.ts) and not in more recent branches/tags and master? Or is it located somewhere else? If so, where can it be found?

  2. Decoding Errors The code added in the thread seems not to decode all types of blockExtraData content. For example, for the hex code "0x000000000000000000010427d4b22a2a78bcddd456742caf91b56badbff985ee19aef14573e7343fd652ed5f38341e436e5d46e2bb00b45d62ae97d1b050c64bc634ae10626739e35c4b0000000224c9b5a1cf43117c9386b7536f05205b2b160d02ed8b68c17a393b384341ca7f0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000005000000001dcd65000000000100000000fee38848738edb70e5952e5bab6788228a8ff8fdcdbc511fc803ca779c4481aa0000000121e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff00000005000000000bebc2000000000100000000000000029b6581f86a76f6816dd0b26e064362bf39365662000000000bebc20021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff9b6581f86a76f6816dd0b26e064362bf39365662000000001dcd650021e67317cbc4be2aeb00677ad6462778a8f52274b9d605df2591b23027a87dff000000020000000900000001c03d4cb185dc4cff1df5c3b1804c7949dd4fc6e68e9e59814f87a229ec6ffe837d1d864475e3bcd3c85ec762caa09047648c83e0fca73e9266df79e5bcee53e3010000000900000001c03d4cb185dc4cff1df5c3b1804c7949dd4fc6e68e9e59814f87a229ec6ffe837d1d864475e3bcd3c85ec762caa09047648c83e0fca73e9266df79e5bcee53e301" from C-Chain block number 31584, we encounter the error "RangeError: Trying to access beyond buffer length." Is there an open-source code that correctly decodes such transactions?

  3. Mismatched Decoding Information Another example comes from block number 40064885. For this block, the decoding returns only one output with the following content:

    {
        "Transaction": {
            "Type": "ImportTx",
            "TypeID": 0,
            "NetworkID": 1,
            "BlockchainID": "2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5",
            "BlockchainIDName": "C-Chain",
            "SourceChain": "11111111111111111111111111111111LpoYY",
            "SourceChainName": "P-Chain",
            "NumberOfImportedInputs": 1,
            "ImportedInputs": [
                {
                    "Type": "TransferableInput",
                    "TransactionId": "2D17UkRojsgbSmXssjPyUt1j7PmL5TGPBJjEAzEHWeJz2kKpAi",
                    "OutputId": 0,
                    "AssetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z",
                    "Input": {
                        "Type": "SECPTransferInput",
                        "TypeID": 5,
                        "SignaturesIds": [
                            {
                                "Type": "SigIdx",
                                "Source": "0x0000000000000000000000000000000000000000",
                                "Bytes": "0x00000000",
                                "BytesSize": 4
                            }
                        ],
                        "Amount": "0x0000001a69441201",
                        "AmountValue": "0x1a69441201",
                        "DecimalAmountValue": "113.435218433 AVAX"
                    }
                }
            ],
            "NumberOfOutputs": 1,
            "Outputs": [
                {
                    "Address": "0xb15e2147a0228aa0eaacbe2f87ffa40ab37094dc",
                    "Amount": "0x0000001a693eb766",
                    "AmountValue": "0x1a693eb766",
                    "DecimalAmountValue": "113.434867558 AVAX",
                    "AssetID": "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z"
                }
            ]
        }
    }

    However, AVASCAN shows the following information for this block:

    {
        "chainId": "43114",
        "ecosystems": ["avalanche"],
        "blockNumber": 40064885,
        "txIndex": 1315649253,
        "timestamp": "2024-01-07T19:50:31.000Z",
        "from": {"id": "0xe51366e97A0c9Ea2a1B3F7cfdFD3edDCBA625213"},
        "txHash": "6w6TxEVhSsUjNdHgpKNnXcCwrtANe8fANsZniJVNBniLY1CHt",
        "type": "pvm_export",
        "value": "28705189063000000000",
        "burnedFees": "350937000000000"
    },
    {
        "chainId": "43114",
        "ecosystems": ["avalanche"],
        "blockNumber": 40064885,
        "txIndex": 574265426,
        "timestamp": "2024-01-07T19:50:31.000Z",
        "from": {"id": "c-avax1lgvq7qfe5xle370ypfgc06uwhmp8quhz86fka6"},
        "to": {"id": "0xB15e2147A0228aA0eaaCBe2f87ffa40Ab37094DC"},
        "txHash": "e7AWaf2vbSeRerkD6GB1Y4UmGKA6SceGwuDxFVu9S4xWzhKw2",
        "type": "pvm_import",
        "value": "113434867558000000000",
        "burnedFees": "350875000000000"
    }

    Therefore, I have the following questions: a) Is it possible to obtain a txHash from blockExtraData on C-Chain similar to the one in AVASCAN? b) Is it possible to obtain AVAX address IDs in the "c-avax..." format from blockExtraData on C-Chain? c) How can we also decode a transaction of type pvm_export as shown in the above example?

I greatly appreciate your time and assistance in addressing these questions. Your expertise and guidance are invaluable. Thank you in advance for your support.