-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update for univesal channel and update README
- Loading branch information
Showing
3 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// We require the Hardhat Runtime Environment explicitly here. This is optional | ||
// but useful for running the script in a standalone fashion through `node <script>`. | ||
// | ||
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat | ||
// will compile your contracts, add the Hardhat Runtime Environment's members to the | ||
// global scope, and execute the script. | ||
const hre = require('hardhat'); | ||
const config = require('../config.json'); | ||
const sendConfig = config.sendUniversalPacket; | ||
|
||
async function main() { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
const networkName = hre.network.name; | ||
// Get the contract type from the config and get the contract | ||
const contractType = config["deploy"][`${networkName}`]; | ||
|
||
const ibcAppSrc = await hre.ethers.getContractAt( | ||
`${contractType}`, | ||
sendConfig[`${networkName}`]["portAddr"] | ||
); | ||
|
||
// Do logic to prepare the packet | ||
const channelId = sendConfig[`${networkName}`]["channelId"]; | ||
const channelIdBytes = hre.ethers.encodeBytes32String(channelId); | ||
const timeoutSeconds = sendConfig[`${networkName}`]["timeout"]; | ||
|
||
// Send the packet | ||
await ibcAppSrc.connect(accounts[1]).sendUniversalPacket( | ||
channelIdBytes, | ||
timeoutSeconds, | ||
optionalArgs // add optional args here depending on the contract | ||
) | ||
console.log("Sending packet"); | ||
|
||
// Active waiting for the packet to be received and acknowledged | ||
// @dev You'll need to implement this based on the contract's logic | ||
let acked = false; | ||
let counter = 0; | ||
do { | ||
const acked = await ibcAppSrc.findAck(sequence); | ||
if (!acked) { | ||
console.log("ack not received. waiting..."); | ||
await new Promise((r) => setTimeout(r, 2000)); | ||
counter++; | ||
} | ||
} while (!acked && counter<100); | ||
|
||
console.log("Packet lifecycle was concluded successfully: " + acked); | ||
} | ||
|
||
// We recommend this pattern to be able to use async/await everywhere | ||
// and properly handle errors. | ||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |