Skip to content

Commit 41465b3

Browse files
authored
Merge pull request #652 from subquery/near-receipt-handler
Add missing receipt handler docs
2 parents c792ec7 + 6d33368 commit 41465b3

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

docs/indexer/build/manifest/near.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ The following table explains filters supported by different handlers.
306306
| ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
307307
| [near/BlockHandler](../mapping/near.md#block-handler) | `modulo`, `timestamp` |
308308
| [near/TransactionHandler](../mapping/near.md#transaction-handler) | `sender`, `reciever` |
309-
| [near/ActionHandler](../mapping/near.md#message-handler) | `type`, `sender`, `receiver`, `methodName`, 'args', 'publicKey', 'accessKey', 'beneficiaryId' |
309+
| [near/ReceiptHandler](../mapping/near.md#receipt-handler) | `sender`, `receiver`, `signer` |
310+
| [near/ActionHandler](../mapping/near.md#message-handler) | `type`, `sender`, `receiver`, `methodName`, `args`, `publicKey`, `accessKey`, `beneficiaryId` |
310311

311312
Default runtime mapping filters are an extremely useful feature to decide what block, transaction, or action will trigger a mapping handler.
312313

docs/indexer/build/mapping/near.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ export async function handleTransaction(
5656

5757
The `NearTransaction` encapsulates transaction info, result, the corresponding block details and the list of `NearAction` entities that occured in the specific transaction.
5858

59+
## Receipt Handler
60+
61+
You can use receipt handlers to capture information about each of the receipts in a block. To achieve this, a defined ReceiptHandler will be called once for every receipt. You should use [Receipt Filters](../manifest/near.md#mapping-handlers-and-filters) in your manifest to filter receipts to reduce the time it takes to index data and improve mapping performance.
62+
63+
```ts
64+
import { NearTransactionReceipt } from "@subql/types-near";
65+
66+
export async function handleReceipt(
67+
receipt: NearTransactionReceipt,
68+
): Promise<void> {
69+
logger.info(`Handling receipt at ${receipt.block_height}`);
70+
71+
const receiptRecord = NearReceiptEntity.create({
72+
id: `${receipt.block_height}-${receipt.receipt_id}`,
73+
signer: receipt.Action?.signer_id,
74+
receiver: receipt.receiver_id,
75+
});
76+
77+
await receiptRecord.save();
78+
}
79+
```
80+
81+
The `NearReceipt` encapsulates receipt info, result, the corresponding block details and the list of `NearAction` entities that occured in the specific receipt.
82+
5983
## Action Handler
6084

6185
You can use action handlers to capture information from each action in a transaction. To achieve this, a defined ActionHandler will be called once for every action. You should use [Mapping Filters](../manifest/near.md#mapping-handlers-and-filters) in your manifest to filter actions to reduce the time it takes to index data and improve mapping performance.
@@ -106,4 +130,3 @@ export async function handleAction(
106130
We also support some [API RPC methods here](https://github.com/subquery/subql-near/blob/main/packages/types/src/global.ts) that are remote calls that allow the mapping function to interact with the actual node and chain state.
107131

108132
Documents in [NEAR `JsonRpcProvider`](https://docs.near.org/tools/near-api-js/reference/classes/providers_json_rpc_provider.JsonRpcProvider.html) provide some methods to interact with the NEAR RPC API.
109-

0 commit comments

Comments
 (0)