@@ -3,8 +3,8 @@ import {withPolkadotSdkCompat} from "polkadot-api/polkadot-sdk-compat";
33import { getPolkadotSigner } from "polkadot-api/signer" ;
44import { getWsProvider } from "polkadot-api/ws-provider/web" ;
55import {
6- acala ,
76 assetHub ,
7+ hydration ,
88 XcmV3MultiassetFungibility ,
99 XcmV3WeightLimit ,
1010 XcmV5Junction ,
@@ -35,16 +35,17 @@ const toHuman = (_key: any, value: any) => {
3535} ;
3636
3737async 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