Skip to content

Commit f9074cf

Browse files
committed
fix: prettier
1 parent 1df2094 commit f9074cf

File tree

3 files changed

+206
-150
lines changed

3 files changed

+206
-150
lines changed
Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
import { Binary, createClient, Enum } from "polkadot-api";
2-
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
3-
import { getWsProvider } from "polkadot-api/ws-provider/web";
4-
import { assetHub } from "@polkadot-api/descriptors";
5-
import { sr25519CreateDerive } from "@polkadot-labs/hdkd";
6-
import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy, ss58Address } from "@polkadot-labs/hdkd-helpers";
1+
import { Binary, createClient, Enum } from 'polkadot-api';
2+
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';
3+
import { getWsProvider } from 'polkadot-api/ws-provider/web';
4+
import { assetHub } from '@polkadot-api/descriptors';
5+
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
6+
import {
7+
DEV_PHRASE,
8+
entropyToMiniSecret,
9+
mnemonicToEntropy,
10+
ss58Address,
11+
} from '@polkadot-labs/hdkd-helpers';
712

813
const XCM_VERSION = 5;
914

1015
async function main() {
11-
const provider = withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"));
12-
const client = createClient(provider);
13-
const api = client.getTypedApi(assetHub);
16+
const provider = withPolkadotSdkCompat(getWsProvider('ws://localhost:8000'));
17+
const client = createClient(provider);
18+
const api = client.getTypedApi(assetHub);
1419

15-
const entropy = mnemonicToEntropy(DEV_PHRASE);
16-
const miniSecret = entropyToMiniSecret(entropy);
17-
const derive = sr25519CreateDerive(miniSecret);
18-
const alice = derive("//Alice");
19-
const aliceAddress = ss58Address(alice.publicKey);
20+
const entropy = mnemonicToEntropy(DEV_PHRASE);
21+
const miniSecret = entropyToMiniSecret(entropy);
22+
const derive = sr25519CreateDerive(miniSecret);
23+
const alice = derive('//Alice');
24+
const aliceAddress = ss58Address(alice.publicKey);
2025

21-
const callData = Binary.fromHex(
22-
"0x1f0803010100411f0300010100fc39fcf04a8071b7409823b7c82427ce67910c6ed80aa0e5093aff234624c8200304000002043205011f0092e81d790000000000"
23-
);
24-
const tx: any = await api.txFromCallData(callData);
25-
const origin = Enum("system", Enum("Signed", aliceAddress));
26-
const dryRunResult: any = await api.apis.DryRunApi.dry_run_call(origin, tx.decodedCall, XCM_VERSION);
27-
console.dir(dryRunResult.value, { depth: null });
26+
const callData = Binary.fromHex(
27+
'0x1f0803010100411f0300010100fc39fcf04a8071b7409823b7c82427ce67910c6ed80aa0e5093aff234624c8200304000002043205011f0092e81d790000000000',
28+
);
29+
const tx: any = await api.txFromCallData(callData);
30+
const origin = Enum('system', Enum('Signed', aliceAddress));
31+
const dryRunResult: any = await api.apis.DryRunApi.dry_run_call(
32+
origin,
33+
tx.decodedCall,
34+
XCM_VERSION,
35+
);
36+
console.dir(dryRunResult.value, { depth: null });
2837

29-
client.destroy();
38+
client.destroy();
3039
}
3140

32-
main().catch(console.error);
41+
main().catch(console.error);
Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,90 @@
1-
import { Binary, createClient, Transaction } from "polkadot-api";
2-
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
3-
import { getPolkadotSigner } from "polkadot-api/signer";
4-
import { getWsProvider } from "polkadot-api/ws-provider/web";
5-
import { assetHub } from "@polkadot-api/descriptors";
6-
import { sr25519CreateDerive } from "@polkadot-labs/hdkd";
7-
import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy } from "@polkadot-labs/hdkd-helpers";
1+
import { Binary, createClient, Transaction } from 'polkadot-api';
2+
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';
3+
import { getPolkadotSigner } from 'polkadot-api/signer';
4+
import { getWsProvider } from 'polkadot-api/ws-provider/web';
5+
import { assetHub } from '@polkadot-api/descriptors';
6+
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
7+
import {
8+
DEV_PHRASE,
9+
entropyToMiniSecret,
10+
mnemonicToEntropy,
11+
} from '@polkadot-labs/hdkd-helpers';
812

913
const toHuman = (_key: any, value: any) => {
10-
if (typeof value === "bigint") {
11-
return Number(value);
12-
}
14+
if (typeof value === 'bigint') {
15+
return Number(value);
16+
}
1317

14-
if (value && typeof value === "object" && typeof value.asHex === "function") {
15-
return value.asHex();
16-
}
18+
if (value && typeof value === 'object' && typeof value.asHex === 'function') {
19+
return value.asHex();
20+
}
1721

18-
return value;
22+
return value;
1923
};
2024

2125
function getSigner() {
22-
const entropy = mnemonicToEntropy(DEV_PHRASE);
23-
const miniSecret = entropyToMiniSecret(entropy);
24-
const derive = sr25519CreateDerive(miniSecret);
25-
const alice = derive("//Alice");
26+
const entropy = mnemonicToEntropy(DEV_PHRASE);
27+
const miniSecret = entropyToMiniSecret(entropy);
28+
const derive = sr25519CreateDerive(miniSecret);
29+
const alice = derive('//Alice');
2630

27-
return getPolkadotSigner(alice.publicKey, "Sr25519", alice.sign);
31+
return getPolkadotSigner(alice.publicKey, 'Sr25519', alice.sign);
2832
}
2933

3034
async function main() {
31-
const provider = withPolkadotSdkCompat(getWsProvider("ws://localhost:8000"));
32-
const client = createClient(provider);
33-
const api = client.getTypedApi(assetHub);
34-
const aliceSigner = getSigner();
35+
const provider = withPolkadotSdkCompat(getWsProvider('ws://localhost:8000'));
36+
const client = createClient(provider);
37+
const api = client.getTypedApi(assetHub);
38+
const aliceSigner = getSigner();
3539

36-
const callData = Binary.fromHex(
37-
"0x1f0803010100411f0300010100fc39fcf04a8071b7409823b7c82427ce67910c6ed80aa0e5093aff234624c8200304000002043205011f0092e81d790000000000"
38-
);
39-
const tx: Transaction<any, string, string, any> = await api.txFromCallData(callData);
40-
console.log("👀 Executing XCM:", JSON.stringify(tx.decodedCall, toHuman, 2));
40+
const callData = Binary.fromHex(
41+
'0x1f0803010100411f0300010100fc39fcf04a8071b7409823b7c82427ce67910c6ed80aa0e5093aff234624c8200304000002043205011f0092e81d790000000000',
42+
);
43+
const tx: Transaction<any, string, string, any> =
44+
await api.txFromCallData(callData);
45+
console.log('👀 Executing XCM:', JSON.stringify(tx.decodedCall, toHuman, 2));
4146

42-
await new Promise<void>((resolve) => {
43-
const subscription = tx.signSubmitAndWatch(aliceSigner).subscribe((ev) => {
44-
if (ev.type === "finalized" || (ev.type === "txBestBlocksState" && ev.found)) {
45-
console.log(`📦 Included in block #${ev.block.number}: ${ev.block.hash}`);
47+
await new Promise<void>((resolve) => {
48+
const subscription = tx.signSubmitAndWatch(aliceSigner).subscribe((ev) => {
49+
if (
50+
ev.type === 'finalized' ||
51+
(ev.type === 'txBestBlocksState' && ev.found)
52+
) {
53+
console.log(
54+
`📦 Included in block #${ev.block.number}: ${ev.block.hash}`,
55+
);
4656

47-
if (!ev.ok) {
48-
const dispatchError = ev.dispatchError;
49-
if (dispatchError.type === "Module") {
50-
const modErr: any = dispatchError.value;
51-
console.error(`❌ Dispatch error in module: ${modErr.type}${modErr.value?.type}`);
52-
} else {
53-
console.error("❌ Dispatch error:", JSON.stringify(dispatchError, toHuman, 2));
54-
}
55-
}
57+
if (!ev.ok) {
58+
const dispatchError = ev.dispatchError;
59+
if (dispatchError.type === 'Module') {
60+
const modErr: any = dispatchError.value;
61+
console.error(
62+
`❌ Dispatch error in module: ${modErr.type}${modErr.value?.type}`,
63+
);
64+
} else {
65+
console.error(
66+
'❌ Dispatch error:',
67+
JSON.stringify(dispatchError, toHuman, 2),
68+
);
69+
}
70+
}
5671

57-
for (const event of ev.events) {
58-
console.log("📣 Event:", event.type, JSON.stringify(event.value, toHuman, 2));
59-
}
72+
for (const event of ev.events) {
73+
console.log(
74+
'📣 Event:',
75+
event.type,
76+
JSON.stringify(event.value, toHuman, 2),
77+
);
78+
}
6079

61-
console.log("✅ Process completed, exiting...");
62-
subscription.unsubscribe();
63-
resolve();
64-
}
65-
});
80+
console.log('✅ Process completed, exiting...');
81+
subscription.unsubscribe();
82+
resolve();
83+
}
6684
});
85+
});
6786

68-
client.destroy();
87+
client.destroy();
6988
}
7089

71-
main().catch(console.error);
90+
main().catch(console.error);

0 commit comments

Comments
 (0)