git.delta.rocks / unique-network / refs/commits / e2c10c5a7525

difftreelog

feat skip-balance-check option

Daniel Shiposha2024-02-07parent: #f921192.patch.diff
in: master

1 file changed

modifiedjs-packages/scripts/hrmpchannel.tsdiffbeforeafterboth
16 return '0x' + (childPrefix + encodedParaId).padEnd(addrBytesLen * byteLenInHex, '0');16 return '0x' + (childPrefix + encodedParaId).padEnd(addrBytesLen * byteLenInHex, '0');
17};17};
1818
19const proposeOpenChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, receiverParaId: number) => {19const proposeOpenChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, receiverParaId: number, skipBalanceCheck: boolean) => {
20 const conf: any = await relayApi.query.configuration.activeConfig()20 const conf: any = await relayApi.query.configuration.activeConfig()
21 .then(data => data.toJSON());21 .then(data => data.toJSON());
22 const maxCapacity = conf.hrmpChannelMaxCapacity;22 const maxCapacity = conf.hrmpChannelMaxCapacity;
29 const balance = await relayApi.query.system.account(sovereignAccount)29 const balance = await relayApi.query.system.account(sovereignAccount)
30 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);30 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);
3131
32 if(balance < requiredBalance) {32 if(!skipBalanceCheck && balance < requiredBalance) {
33 throw Error(`Not enough balance on the sender's sovereign account: balance(${balance}) < requiredBalance(${requiredBalance})`);33 throw Error(`Not enough balance on the sender's sovereign account: balance(${balance}) < requiredBalance(${requiredBalance})`);
34 }34 }
3535
40 ).method.toHex();40 ).method.toHex();
41};41};
4242
43const proposeAcceptChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, recipientParaId: number) => {43const proposeAcceptChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, recipientParaId: number, skipBalanceCheck: boolean) => {
44 const conf: any = await relayApi.query.configuration.activeConfig()44 const conf: any = await relayApi.query.configuration.activeConfig()
45 .then(data => data.toJSON());45 .then(data => data.toJSON());
46 const recipientDeposit = BigInt(conf.hrmpRecipientDeposit);46 const recipientDeposit = BigInt(conf.hrmpRecipientDeposit);
51 const balance = await relayApi.query.system.account(sovereignAccount)51 const balance = await relayApi.query.system.account(sovereignAccount)
52 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);52 .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint);
5353
54 if(balance < requiredBalance) {54 if(!skipBalanceCheck && balance < requiredBalance) {
55 throw Error(`Not enough balance on the recipient's sovereign account: balance(${balance}) < requiredBalance(${requiredBalance})`);55 throw Error(`Not enough balance on the recipient's sovereign account: balance(${balance}) < requiredBalance(${requiredBalance})`);
56 }56 }
5757
58 return relayApi.tx.hrmp.hrmpAcceptOpenChannel(senderParaId).method.toHex();58 return relayApi.tx.hrmp.hrmpAcceptOpenChannel(senderParaId).method.toHex();
59};59};
6060
61async function main() {61async function main() {
62 let skipBalanceCheck;
62 if(process.argv.length != 6) {63 if(process.argv.length == 6) {
64 skipBalanceCheck = false;
65 }
66 else if(process.argv.length == 7 && process.argv[6] == 'skip-balance-check') {
67 skipBalanceCheck = true;
68 } else {
63 console.log('Usage: yarn hrmpChannel <RELAY_URL> <OUR_CHAIN_URL> <OTHER_CHAIN_URL> <open | accept>');69 console.log('Usage: yarn hrmpChannel <RELAY_URL> <OUR_CHAIN_URL> <OTHER_CHAIN_URL> <open | accept> [skip-balance-check]');
64 process.exit(1);70 process.exit(1);
65 }71 }
6672
92 let encodedRelayCall: string;98 let encodedRelayCall: string;
99
93 if(op == 'open') {100 if(op == 'open') {
94 encodedRelayCall = await proposeOpenChannel(relayApi, relayFee, uniqueParaId, otherParaId);101 encodedRelayCall = await proposeOpenChannel(relayApi, relayFee, uniqueParaId, otherParaId, skipBalanceCheck);
95 } else if(op == 'accept') {102 } else if(op == 'accept') {
96 encodedRelayCall = await proposeAcceptChannel(relayApi, relayFee, otherParaId, uniqueParaId);103 encodedRelayCall = await proposeAcceptChannel(relayApi, relayFee, otherParaId, uniqueParaId, skipBalanceCheck);
97 } else {104 } else {
98 throw Error(`Unknown hrmp channel operation: ${op}`);105 throw Error(`Unknown hrmp channel operation: ${op}`);
99 }106 }