difftreelog
feat skip-balance-check option
in: master
1 file changed
js-packages/scripts/hrmpchannel.tsdiffbeforeafterboth16 return '0x' + (childPrefix + encodedParaId).padEnd(addrBytesLen * byteLenInHex, '0');16 return '0x' + (childPrefix + encodedParaId).padEnd(addrBytesLen * byteLenInHex, '0');17};17};181819const 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);313132 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 }353540 ).method.toHex();40 ).method.toHex();41};41};424243const 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);535354 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 }575758 return relayApi.tx.hrmp.hrmpAcceptOpenChannel(senderParaId).method.toHex();58 return relayApi.tx.hrmp.hrmpAcceptOpenChannel(senderParaId).method.toHex();59};59};606061async 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 }667292 let encodedRelayCall: string;98 let encodedRelayCall: string;9993 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 }