Skip to content

Commit 0680bda

Browse files
committed
feat(codegen): add whitelist
1 parent 16786fc commit 0680bda

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/pages/codegen.md

+48
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,51 @@ const finalizedCall = await xcmSendTx.signAndSubmit(signer)
120120
:::info
121121
`getTypedApi` has nearly no cost at runtime, so it can be safely called many times.
122122
:::
123+
124+
## Whitelist
125+
126+
In order to reduce the size of PAPI descriptors bundle, one could filter which calls, queries, etc wants to use and ship with the dApp. This part is particularly interesting when developing web-based dApps, rather than NodeJS or Desktop apps, where bundle size is less critical.
127+
128+
In order to enable the whitelist feature of the codegen, one has to write a `whitelist.ts` file that our CLI can understand. The shape is as follows:
129+
130+
```ts
131+
import { DotWhitelistEntry } from "@polkadot-api/descriptors"
132+
133+
const dotWhitelist: DotWhitelistEntry[] = [
134+
// this will get all calls, queries, and consts inside Balances pallet
135+
"*.Balances",
136+
137+
// this just a specific tx
138+
"tx.XcmPallet.transfer_assets",
139+
140+
// all queries inside system pallet
141+
"query.System.*",
142+
143+
// all constants
144+
"const.*",
145+
]
146+
147+
// the export name has to *EXACTLY* match `whitelist`
148+
export const whitelist = [...dotWhitelist]
149+
```
150+
151+
If you generated descriptors for key `dot` (or any other `key` you used to generate the descriptors) you will have that `<Key>WhitelistEntry` helper type that will provide type checking for your whitelist. You can explore all options that you can choose in your IDE. Of course, this can be multichain, let's see an example of it (for `dot` and `dotAh` descriptor keys).
152+
153+
```ts
154+
import {
155+
DotAhWhitelistEntry,
156+
DotWhitelistEntry,
157+
} from "@polkadot-api/descriptors"
158+
159+
const dotWhitelist: DotWhitelistEntry[] = ["tx.XcmPallet.transfer_assets"]
160+
161+
const ahWhitelist: DotAhWhitelistEntry[] = ["tx.PolkadotXcm.transfer_assets"]
162+
163+
export const whitelist = [...dotWhitelist, ...ahWhitelist]
164+
```
165+
166+
This file could be placed anywhere, but we recommend placing it at `.papi/whitelist.ts`.
167+
168+
In order to generate descriptors taking into account the whitelist, the command should be `papi generate --whitelist .papi/whitelist.ts` (or just `papi --whitelist .papi/whitelist.ts`), or any other directory you chose to save your file. We recommend setting a script in your `package.json` that takes care of it.
169+
170+
A full working example of a dApp with whitelist could be found at [our repo](https://github.com/polkadot-api/polkadot-api/tree/main/examples/vite).

0 commit comments

Comments
 (0)