@@ -28209,7 +28209,7 @@ In complex XCM flows, such as transfers that span multiple parachains, you may w
2820928209Create a new script, `deposit-reserve-asset-with-set-topic.ts`
2821028210
2821128211```ts
28212- import {Binary, createClient, Enum} from "polkadot-api";
28212+ import {Binary, BlockInfo, createClient, Enum, PolkadotClient, TypedApi } from "polkadot-api";
2821328213import {withPolkadotSdkCompat} from "polkadot-api/polkadot-sdk-compat";
2821428214import {getPolkadotSigner} from "polkadot-api/signer";
2821528215import {getWsProvider} from "polkadot-api/ws-provider/web";
@@ -28247,6 +28247,38 @@ const toHuman = (_key: any, value: any) => {
2824728247 return value;
2824828248};
2824928249
28250+ async function getProcessedMessageId(client: PolkadotClient, api: TypedApi<any>, name: String, blockBefore: BlockInfo): Promise<String> {
28251+ let processedMessageId = undefined;
28252+ const maxRetries = 8;
28253+ for (let i = 0; i < maxRetries; i++) {
28254+ const blockAfter = await client.getFinalizedBlock();
28255+ if (blockAfter.number == blockBefore.number) {
28256+ const waiting = 1_000 * (2 ** i);
28257+ console.log(`β³ Waiting ${waiting / 1_000}s for ${name} block to be finalised (${i + 1}/${maxRetries})...`);
28258+ await new Promise((resolve) => setTimeout(resolve, waiting));
28259+ continue;
28260+ }
28261+
28262+ console.log(`π¦ Finalised on ${name} in block #${blockAfter.number}: ${blockAfter.hash}`);
28263+ const processedEvents = await api.event.MessageQueue.Processed.pull();
28264+ const processingFailedEvents = await api.event.MessageQueue.ProcessingFailed.pull();
28265+ if (processedEvents.length > 0) {
28266+ processedMessageId = processedEvents[0].payload.id.asHex();
28267+ console.log(`π£ Last message Processed on ${name}: ${processedMessageId}`);
28268+ break;
28269+ } else if (processingFailedEvents.length > 0) {
28270+ processedMessageId = processingFailedEvents[0].payload.id.asHex();
28271+ console.log(`π£ Last message ProcessingFailed on ${name}: ${processedMessageId}`);
28272+ break;
28273+ } else {
28274+ console.log(`π£ No Processed events on ${name} found.`);
28275+ blockBefore = blockAfter; // Update the block before to the latest one
28276+ }
28277+ }
28278+
28279+ return processedMessageId;
28280+ }
28281+
2825028282async function main() {
2825128283 const para1Name = "Polkadot Asset Hub";
2825228284 const para1Client = createClient(
@@ -28287,7 +28319,9 @@ async function main() {
2828728319 fun: XcmV3MultiassetFungibility.Fungible(1_000_000_000n),
2828828320 },
2828928321 ]),
28322+
2829028323 XcmV5Instruction.ClearOrigin(),
28324+
2829128325 XcmV5Instruction.BuyExecution({
2829228326 fees: {
2829328327 id: {
@@ -28298,6 +28332,7 @@ async function main() {
2829828332 },
2829928333 weight_limit: XcmV3WeightLimit.Unlimited(),
2830028334 }),
28335+
2830128336 XcmV5Instruction.DepositReserveAsset({
2830228337 assets: XcmV5AssetFilter.Wild(XcmV5WildAsset.All()),
2830328338 dest: {
@@ -28315,12 +28350,16 @@ async function main() {
2831528350 },
2831628351 weight_limit: XcmV3WeightLimit.Unlimited(),
2831728352 }),
28353+
2831828354 XcmV5Instruction.DepositAsset({
2831928355 assets: XcmV5AssetFilter.Wild(XcmV5WildAsset.All()),
2832028356 beneficiary,
2832128357 }),
28358+
28359+ XcmV5Instruction.SetTopic(Binary.fromHex(expectedMessageId)),
2832228360 ],
2832328361 }),
28362+
2832428363 XcmV5Instruction.SetTopic(Binary.fromHex(expectedMessageId)),
2832528364 ]);
2832628365
@@ -28360,10 +28399,10 @@ async function main() {
2836028399 if (polkadotXcmSentEvent === undefined) {
2836128400 console.log(`β οΈ PolkadotXcm.Sent is available in runtimes built from stable2503-5 or later.`);
2836228401 } else {
28363- let parachainBlockBefore = await para2Client.getFinalizedBlock();
28402+ let para2BlockBefore = await para2Client.getFinalizedBlock();
2836428403 const extrinsic = await tx.signAndSubmit(aliceSigner);
28365- const block = extrinsic.block;
28366- console.log(`π¦ Finalised on ${para1Name} in block #${block .number}: ${block .hash}`);
28404+ const para1BlockBefore = extrinsic.block;
28405+ console.log(`π¦ Finalised on ${para1Name} in block #${para1BlockBefore .number}: ${para1BlockBefore .hash}`);
2836728406
2836828407 if (!extrinsic.ok) {
2836928408 const dispatchError = extrinsic.dispatchError;
@@ -28380,43 +28419,16 @@ async function main() {
2838028419 const sentMessageId = sentEvents[0].payload.message_id.asHex();
2838128420 console.log(`π£ Last message Sent on ${para1Name}: ${sentMessageId}`);
2838228421 if (sentMessageId === expectedMessageId) {
28383- console.log(" β
Sent message ID matched." );
28422+ console.log(` β
Sent Message ID on ${para1Name} matched.` );
2838428423 } else {
28385- console.error("β Sent message ID does not match expexted message ID.");
28386- }
28387-
28388- let processedMessageId = undefined;
28389- const maxRetries = 8;
28390- for (let i = 0; i < maxRetries; i++) {
28391- const parachainBlockAfter = await para2Client.getFinalizedBlock();
28392- if (parachainBlockAfter.number == parachainBlockBefore.number) {
28393- const waiting = 1_000 * (2 ** i);
28394- console.log(`β³ Waiting ${waiting}ms for ${para2Name} block to be finalised (${i + 1}/${maxRetries})...`);
28395- await new Promise((resolve) => setTimeout(resolve, waiting));
28396- continue;
28397- }
28398-
28399- console.log(`π¦ Finalised on ${para2Name} in block #${parachainBlockAfter.number}: ${parachainBlockAfter.hash}`);
28400- const processedEvents = await para2Api.event.MessageQueue.Processed.pull();
28401- const processingFailedEvents = await para2Api.event.MessageQueue.ProcessingFailed.pull();
28402- if (processedEvents.length > 0) {
28403- processedMessageId = processedEvents[0].payload.id.asHex();
28404- console.log(`π£ Last message Processed on ${para2Name}: ${processedMessageId}`);
28405- break;
28406- } else if (processingFailedEvents.length > 0) {
28407- processedMessageId = processingFailedEvents[0].payload.id.asHex();
28408- console.log(`π£ Last message ProcessingFailed on ${para2Name}: ${processedMessageId}`);
28409- break;
28410- } else {
28411- console.log(`π£ No Processed events on ${para2Name} found.`);
28412- parachainBlockBefore = parachainBlockAfter; // Update the block before to the latest one
28413- }
28424+ console.error(`β Sent Message ID [${sentMessageId}] on ${para1Name} doesn't match expexted Message ID [${expectedMessageId}].`);
2841428425 }
2841528426
28427+ let processedMessageId = await getProcessedMessageId(para2Client, para2Api, para2Name, para2BlockBefore);
2841628428 if (processedMessageId === expectedMessageId) {
28417- console.log(" β
Processed Message ID matched." );
28429+ console.log(` β
Processed Message ID on ${para2Name} matched.` );
2841828430 } else {
28419- console.error(" β Processed Message ID does not match expected Message ID." );
28431+ console.error(` β Processed Message ID [${processedMessageId}] on ${para2Name} doesn't match expected Message ID [${expectedMessageId}].` );
2842028432 }
2842128433 } else {
2842228434 console.log(`π£ No Sent events on ${para1Name} found.`);
@@ -28449,12 +28461,12 @@ code/tutorials/interoperability/xcm-observability/forwarded-xcm-custom.html
2844928461<div class="termynal" data-termynal>
2845028462 <span data-ty="input">npx tsx limited-reserve-transfer-assets.ts</span>
2845128463 <span data-ty>β
Local dry run successful.</span>
28452- <span data-ty>π¦ Finalised on Polkadot Asset Hub in block #9437981: 0xf3c33536a2687f20947fb25cf2b3d70c4917ff84e7a8f205f5a58a188bda7a3d </span>
28464+ <span data-ty>π¦ Finalised on Polkadot Asset Hub in block #9471830: 0x98bd858739b3b5dd558def60cbd85d5e7fb2f4e33b0c00e1895e316541d727d9 </span>
2845328465 <span data-ty>π£ Last message Sent on Polkadot Asset Hub: 0xd60225f721599cb7c6e23cdf4fab26f205e30cd7eb6b5ccf6637cdc80b2339b2</span>
28454- <span data-ty>β
Sent message ID matched.</span>
28455- <span data-ty>π¦ Finalised on Hydration in block #8676869: 0x55e3e0eeec7396d00ad776d85ea60f935d6e90a99cfde97b25a550845e084f92 </span>
28466+ <span data-ty>β
Sent Message ID on Polkadot Asset Hub matched.</span>
28467+ <span data-ty>π¦ Finalised on Hydration in block #8749233: 0xe1413c5126698d7189d6f55a38e62d07ea4915078c2b1f3914d70f670e79e162 </span>
2845628468 <span data-ty>π£ Last message Processed on Hydration: 0xd60225f721599cb7c6e23cdf4fab26f205e30cd7eb6b5ccf6637cdc80b2339b2</span>
28457- <span data-ty>β
Processed Message ID matched.</span>
28469+ <span data-ty>β
Processed Message ID on Hydration matched.</span>
2845828470</div>
2845928471
2846028472## Workaround for Older Runtimes
0 commit comments