From e2c10c5a7525f5f18b858a302a7e5602b59c89f8 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Wed, 07 Feb 2024 10:12:32 +0000 Subject: [PATCH] feat: skip-balance-check option --- --- a/js-packages/scripts/hrmpchannel.ts +++ b/js-packages/scripts/hrmpchannel.ts @@ -16,7 +16,7 @@ return '0x' + (childPrefix + encodedParaId).padEnd(addrBytesLen * byteLenInHex, '0'); }; -const proposeOpenChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, receiverParaId: number) => { +const proposeOpenChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, receiverParaId: number, skipBalanceCheck: boolean) => { const conf: any = await relayApi.query.configuration.activeConfig() .then(data => data.toJSON()); const maxCapacity = conf.hrmpChannelMaxCapacity; @@ -29,7 +29,7 @@ const balance = await relayApi.query.system.account(sovereignAccount) .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint); - if(balance < requiredBalance) { + if(!skipBalanceCheck && balance < requiredBalance) { throw Error(`Not enough balance on the sender's sovereign account: balance(${balance}) < requiredBalance(${requiredBalance})`); } @@ -40,7 +40,7 @@ ).method.toHex(); }; -const proposeAcceptChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, recipientParaId: number) => { +const proposeAcceptChannel = async (relayApi: ApiPromise, relayFee: bigint, senderParaId: number, recipientParaId: number, skipBalanceCheck: boolean) => { const conf: any = await relayApi.query.configuration.activeConfig() .then(data => data.toJSON()); const recipientDeposit = BigInt(conf.hrmpRecipientDeposit); @@ -51,7 +51,7 @@ const balance = await relayApi.query.system.account(sovereignAccount) .then(accountInfo => (accountInfo.toJSON() as any).data.free as bigint); - if(balance < requiredBalance) { + if(!skipBalanceCheck && balance < requiredBalance) { throw Error(`Not enough balance on the recipient's sovereign account: balance(${balance}) < requiredBalance(${requiredBalance})`); } @@ -59,8 +59,14 @@ }; async function main() { - if(process.argv.length != 6) { - console.log('Usage: yarn hrmpChannel '); + let skipBalanceCheck; + if(process.argv.length == 6) { + skipBalanceCheck = false; + } + else if(process.argv.length == 7 && process.argv[6] == 'skip-balance-check') { + skipBalanceCheck = true; + } else { + console.log('Usage: yarn hrmpChannel [skip-balance-check]'); process.exit(1); } @@ -90,10 +96,11 @@ const relayFee = 2n * BigInt(10 ** relayDecimals); let encodedRelayCall: string; + if(op == 'open') { - encodedRelayCall = await proposeOpenChannel(relayApi, relayFee, uniqueParaId, otherParaId); + encodedRelayCall = await proposeOpenChannel(relayApi, relayFee, uniqueParaId, otherParaId, skipBalanceCheck); } else if(op == 'accept') { - encodedRelayCall = await proposeAcceptChannel(relayApi, relayFee, otherParaId, uniqueParaId); + encodedRelayCall = await proposeAcceptChannel(relayApi, relayFee, otherParaId, uniqueParaId, skipBalanceCheck); } else { throw Error(`Unknown hrmp channel operation: ${op}`); } -- gitstuff