git.delta.rocks / unique-network / refs/commits / 2e72efeb8353

difftreelog

fix hrmpchannel gov script

Daniel Shiposha2024-01-09parent: #50becf1.patch.diff
in: master

1 file changed

modifiedjs-packages/scripts/hrmpchannel.tsdiffbeforeafterboth
4export const paraChildSovereignAccount = (relayApi: ApiPromise, paraid: number) => {4export const paraChildSovereignAccount = (relayApi: ApiPromise, paraid: number) => {
5 // We are getting a *child* parachain sovereign account,5 // We are getting a *child* parachain sovereign account,
6 // so we need a child prefix: encoded(b"para") == 0x706172616 // so we need a child prefix: encoded(b"para") == 0x70617261
7 const childPrefix = '0x70617261';7 const childPrefix = '70617261';
88
9 const encodedParaId = relayApi.createType('u32', paraid).toHex(true).substring(2);9 const encodedParaId = relayApi
10 .createType('u32', paraid)
11 .toHex(true)
12 .substring(2 /* skip 0x */);
13
10 const suffix = '000000000000000000000000000000000000000000000000';14 const addrBytesLen = 32;
1115 const byteLenInHex = 2;
12 return childPrefix + encodedParaId + suffix;16 return '0x' + (childPrefix + encodedParaId).padEnd(addrBytesLen * byteLenInHex, '0');
13};17};
1418
15const proposeOpenChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, receiverParaId: number) => {19const proposeOpenChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, receiverParaId: number) => {
21 const senderDeposit = BigInt(conf.hrmpSenderDeposit);25 const senderDeposit = BigInt(conf.hrmpSenderDeposit);
2226
23 const requiredBalance = relayFee + senderDeposit;27 const requiredBalance = relayFee + senderDeposit;
24 const sovereignAccount = await paraChildSovereignAccount(relayApi, senderParaId);28 const sovereignAccount = paraChildSovereignAccount(relayApi, senderParaId);
25 const balance = await relayApi.query.system.account(sovereignAccount)29 const balance = await relayApi.query.system.account(sovereignAccount)
26 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);30 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);
2731
4347
44 const requiredBalance = relayFee + recipientDeposit;48 const requiredBalance = relayFee + recipientDeposit;
4549
46 const sovereignAccount = await paraChildSovereignAccount(relayApi, recipientParaId);50 const sovereignAccount = paraChildSovereignAccount(relayApi, recipientParaId);
47 const balance = await relayApi.query.system.account(sovereignAccount)51 const balance = await relayApi.query.system.account(sovereignAccount)
48 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);52 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);
4953