Search code examples
nearprotocol

How to match data_receipt to transaction?


For example we have: data_receipt with id = Ft9SKhvk7YTgMtZBQt741RHRpF9GDtrVUXbm7Txr1GYK

This receipt we can find only in chunk. We can easily match it with block, but not with transactions.

Transactions does not have data_receipt.

Can anyone explain how I can match it with transaction?


Solution

  • I found how it work near indexer github

    if let Some(transaction_hash) = 
                tx_hashes_for_receipts.get(&receipt_or_data_id) {
                Some(models::Receipt::from_receipt_view(
                        r,
                        block_hash,
                        transaction_hash,
                        chunk_hash,
                        index as i32,
                        block_timestamp,
                    ))
            }
    

    It's mean that receipt is data, receipt have data_id in core of tree. And some transaction have receipt with field data_id included to output_data_receivers

    data_id from output_data_receivers equal to data_id from data_receipt

    data receipt: Ft9SKhvk7YTgMtZBQt741RHRpF9GDtrVUXbm7Txr1GYK with data_id : HWCSA1gNd7NviQ4ZmqNZ7P6fy5RA93NGbXjmQSNWpJxc

    {
       "jsonrpc": "2.0",
       "id": "dontcare",
       "method": "chunk",
       "params": {
         "chunk_id": "DBTgMT3NMnkof9pX5Lg1dZvfBB6REJD3vibEQThkjnWe"
        }
    }
    

    transaction getting in parsing process: EToG7FhgJyDBg1VbFhyRSSxYTZ9SGPjy1tVnbBTPbdth this transaction have receipt : 5VDF57ehUt43oZ2yfULj8QL9wR9aojEXUkjD4XQB7rj2

    {
    "jsonrpc": "2.0",
    "id": "dontcare",
    "method": "EXPERIMENTAL_tx_status",
    "params": [
        "EToG7FhgJyDBg1VbFhyRSSxYTZ9SGPjy1tVnbBTPbdth",
        "9nearapps.near"
        ]
    }
    

    this receipt have output_data_receivers and in tree have data_id: HWCSA1gNd7NviQ4ZmqNZ7P6fy5RA93NGbXjmQSNWpJxc

    "output_data_receivers": [
        {
        "data_id": "HWCSA1gNd7NviQ4ZmqNZ7P6fy5RA93NGbXjmQSNWpJxc",
        "receiver_id": "v1.nearapps.near"
        }
    ]
    

    Ps. Sorry for my english