Skip to content

Commit dd8ea79

Browse files
Change to Hydration
1 parent c127621 commit dd8ea79

File tree

5 files changed

+95
-111
lines changed

5 files changed

+95
-111
lines changed

β€Ž.snippets/code/tutorials/interoperability/xcm-observability/forwarded-xcm.htmlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"type": "SetTopic",
21-
"value": "0xb4b8d2c87622cbad983d8f2c92bfe28e12d587e13d15ea4fdabe8f771bf86bce"
21+
"value": "0x3b5650b78230aebb8f2573d2c5e8356494ab01e39e716087c177bf871dce70b9"
2222
}
2323
]
2424
</pre>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div class="termynal" data-termynal>
22
<span data-ty="input">npx tsx limited-reserve-transfer-assets.ts</span>
33
<span data-ty>βœ… Local dry run successful.</span>
4-
<span data-ty>πŸ“¦ Finalised on Polkadot Asset Hub in block #9079592: 0x6de0cd268f07ec040a69dbbcb81f86c6fc4954dfa7fc914edd5dae1e3f235083</span>
5-
<span data-ty>πŸ“£ Last message Sent on Polkadot Asset Hub: 0xb4b8d2c87622cbad983d8f2c92bfe28e12d587e13d15ea4fdabe8f771bf86bce</span>
6-
<span data-ty>πŸ“¦ Finalised on Acala in block #8826386: 0xfda51e7e411ee59c569fc051ef51431b04edebcc5d45d7b1d1bdfcce9627638a</span>
7-
<span data-ty>πŸ“£ Last message Processed on Acala: 0xb4b8d2c87622cbad983d8f2c92bfe28e12d587e13d15ea4fdabe8f771bf86bce</span>
8-
<span data-ty>βœ… Message ID matched.</span>
4+
<span data-ty>πŸ“¦ Finalised on Polkadot Asset Hub in block #9437493: 0xa47d5749011efdb78da86f492a5a3ac7eef7c74fbeacb6d8d545dee4e36bf20b</span>
5+
<span data-ty>πŸ“£ Last message Sent on Polkadot Asset Hub: 0xbc19a72ee865c04abd3d2517de92db20ce402d1197b88f640462606bc784cd85</span>
6+
<span data-ty>πŸ“¦ Finalised on Hydration in block #8675854: 0xd21cd7b01fa3cd57e74893536135cdd8f0e60ee5570ad7dcf5bbf0b35ab44fc7</span>
7+
<span data-ty>πŸ“£ Last message Processed on Hydration: 0xbc19a72ee865c04abd3d2517de92db20ce402d1197b88f640462606bc784cd85</span>
8+
<span data-ty>βœ… Processed Message ID matched.</span>
99
</div>

β€Ž.snippets/code/tutorials/interoperability/xcm-observability/limited-reserve-transfer-assets.tsβ€Ž

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {withPolkadotSdkCompat} from "polkadot-api/polkadot-sdk-compat";
33
import {getPolkadotSigner} from "polkadot-api/signer";
44
import {getWsProvider} from "polkadot-api/ws-provider/web";
55
import {
6-
acala,
76
assetHub,
7+
hydration,
88
XcmV3MultiassetFungibility,
99
XcmV3WeightLimit,
1010
XcmV5Junction,
@@ -35,16 +35,17 @@ const toHuman = (_key: any, value: any) => {
3535
};
3636

3737
async function main() {
38-
const assetHubClient = createClient(
38+
const para1Name = "Polkadot Asset Hub";
39+
const para1Client = createClient(
3940
withPolkadotSdkCompat(getWsProvider("ws://localhost:8000")),
4041
);
41-
const assetHubApi = assetHubClient.getTypedApi(assetHub);
42+
const para1Api = para1Client.getTypedApi(assetHub);
4243

43-
const parachainName = "Acala";
44-
const parachainClient = createClient(
44+
const para2Name = "Hydration";
45+
const para2Client = createClient(
4546
withPolkadotSdkCompat(getWsProvider("ws://localhost:8001")),
4647
);
47-
const parachainApi = parachainClient.getTypedApi(acala);
48+
const para2Api = para2Client.getTypedApi(hydration);
4849

4950
const entropy = mnemonicToEntropy(DEV_PHRASE);
5051
const miniSecret = entropyToMiniSecret(entropy);
@@ -56,10 +57,10 @@ async function main() {
5657

5758
const origin = Enum("system", Enum("Signed", aliceAddress));
5859
const tx: Transaction<any, string, string, any> =
59-
assetHubApi.tx.PolkadotXcm.limited_reserve_transfer_assets({
60+
para1Api.tx.PolkadotXcm.limited_reserve_transfer_assets({
6061
dest: XcmVersionedLocation.V5({
6162
parents: 1,
62-
interior: XcmV5Junctions.X1(XcmV5Junction.Parachain(2000)),
63+
interior: XcmV5Junctions.X1(XcmV5Junction.Parachain(2034)),
6364
}),
6465
beneficiary: XcmVersionedLocation.V5({
6566
parents: 0,
@@ -90,7 +91,7 @@ async function main() {
9091
console.log("πŸ‘€ Executing XCM:", JSON.stringify(decodedCall, toHuman, 2));
9192

9293
try {
93-
const dryRunResult: any = await assetHubApi.apis.DryRunApi.dry_run_call(
94+
const dryRunResult: any = await para1Api.apis.DryRunApi.dry_run_call(
9495
origin,
9596
decodedCall,
9697
XCM_VERSION,
@@ -106,79 +107,70 @@ async function main() {
106107
} else {
107108
console.log("βœ… Local dry run successful.");
108109

109-
const parachainBlockBefore = await parachainClient.getFinalizedBlock();
110+
let parachainBlockBefore = await para2Client.getFinalizedBlock();
110111
const extrinsic = await tx.signAndSubmit(aliceSigner);
111112
const block = extrinsic.block;
112-
console.log(
113-
`πŸ“¦ Finalised on Polkadot Asset Hub in block #${block.number}: ${block.hash}`,
114-
);
113+
console.log(`πŸ“¦ Finalised on ${para1Name} in block #${block.number}: ${block.hash}`);
115114

116115
if (!extrinsic.ok) {
117116
const dispatchError = extrinsic.dispatchError;
118117
if (dispatchError.type === "Module") {
119118
const modErr: any = dispatchError.value;
120-
console.error(
121-
`❌ Dispatch error in module: ${modErr.type} β†’ ${modErr.value?.type}`,
122-
);
119+
console.error(`❌ Dispatch error in module: ${modErr.type} β†’ ${modErr.value?.type}`);
123120
} else {
124-
console.error(
125-
"❌ Dispatch error:",
126-
JSON.stringify(dispatchError, toHuman, 2),
127-
);
121+
console.error("❌ Dispatch error:", JSON.stringify(dispatchError, toHuman, 2));
128122
}
129123
}
130124

131-
const sentEvents = await assetHubApi.event.PolkadotXcm.Sent.pull();
125+
const sentEvents = await para1Api.event.PolkadotXcm.Sent.pull();
132126
if (sentEvents.length > 0) {
133127
const sentMessageId = sentEvents[0].payload.message_id.asHex();
134-
console.log(
135-
`πŸ“£ Last message Sent on Polkadot Asset Hub: ${sentMessageId}`,
136-
);
128+
console.log(`πŸ“£ Last message Sent on ${para1Name}: ${sentMessageId}`);
137129

138130
let processedMessageId = undefined;
139131
const maxRetries = 8;
140132
for (let i = 0; i < maxRetries; i++) {
141-
const parachainBlockAfter = await parachainClient.getFinalizedBlock();
133+
const parachainBlockAfter = await para2Client.getFinalizedBlock();
142134
if (parachainBlockAfter.number == parachainBlockBefore.number) {
143135
const waiting = 1_000 * (i + 1);
144136
console.log(
145-
`⏳ Waiting ${waiting}ms for ${parachainName} block to be finalised (${i + 1}/${maxRetries})...`,
137+
`⏳ Waiting ${waiting}ms for ${para2Name} block to be finalised (${i + 1}/${maxRetries})...`,
146138
);
147139
await new Promise((resolve) => setTimeout(resolve, waiting));
148140
continue;
149141
}
150142

151143
console.log(
152-
`πŸ“¦ Finalised on ${parachainName} in block #${parachainBlockAfter.number}: ${parachainBlockAfter.hash}`,
144+
`πŸ“¦ Finalised on ${para2Name} in block #${parachainBlockAfter.number}: ${parachainBlockAfter.hash}`,
153145
);
154-
const processedEvents =
155-
await parachainApi.event.MessageQueue.Processed.pull();
146+
const processedEvents = await para2Api.event.MessageQueue.Processed.pull();
147+
const processingFailedEvents = await para2Api.event.MessageQueue.ProcessingFailed.pull();
156148
if (processedEvents.length > 0) {
157149
processedMessageId = processedEvents[0].payload.id.asHex();
158-
console.log(
159-
`πŸ“£ Last message Processed on ${parachainName}: ${processedMessageId}`,
160-
);
150+
console.log(`πŸ“£ Last message Processed on ${para2Name}: ${processedMessageId}`);
151+
break;
152+
} else if (processingFailedEvents.length > 0) {
153+
processedMessageId = processingFailedEvents[0].payload.id.asHex();
154+
console.log(`πŸ“£ Last message ProcessingFailed on ${para2Name}: ${processedMessageId}`);
155+
break;
161156
} else {
162-
console.log(`πŸ“£ No Processed events on ${parachainName} found.`);
157+
console.log(`πŸ“£ No Processed events on ${para2Name} found.`);
158+
parachainBlockBefore = parachainBlockAfter; // Update the block before to the latest one
163159
}
164-
165-
break;
166160
}
167161

168162
if (processedMessageId === sentMessageId) {
169-
console.log("βœ… Message ID matched.");
163+
console.log("βœ… Processed Message ID matched.");
170164
} else {
171-
console.error(
172-
"❌ Processed message ID does not match sent message ID.",
173-
);
165+
console.error("❌ Processed Message ID does not match Sent Message ID.");
174166
}
175167
} else {
176-
console.log("πŸ“£ No Sent events on Polkadot Asset Hub found.");
168+
console.log(`πŸ“£ No Sent events on ${para1Name} found.`);
177169
}
178170
}
179171
} finally {
180-
assetHubClient.destroy();
181-
parachainClient.destroy();
172+
para1Client.destroy();
173+
para2Client.destroy();
182174
}
183175
}
184176

0 commit comments

Comments
Β (0)