-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathindex.js
48 lines (36 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const {
utils: { deployContract },
} = require('@axelar-network/axelar-local-dev');
const CallContract = rootRequire('./artifacts/examples/evm/call-contract/CallContract.sol/CallContract.json');
async function deploy(chain, wallet) {
console.log(`Deploying CallContract for ${chain.name}.`);
chain.contract = await deployContract(wallet, CallContract, [chain.gateway, chain.gasService]);
chain.wallet = wallet;
console.log(`Deployed CallContract for ${chain.name} at ${chain.contract.address}.`);
}
async function execute(chains, wallet, options) {
const args = options.args || [];
const { source, destination, calculateBridgeFee } = options;
const message = args[2] || `Hello ${destination.name} from ${source.name}, it is ${new Date().toLocaleTimeString()}.`;
async function logValue() {
console.log(`value at ${destination.name} is "${await destination.contract.message()}"`);
}
console.log('--- Initially ---');
await logValue();
const fee = await calculateBridgeFee(source, destination);
const tx = await source.contract.setRemoteValue(destination.name, destination.contract.address, message, {
value: fee,
});
await tx.wait();
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
while ((await destination.contract.message()) !== message) {
await sleep(1000);
}
console.log('--- After ---');
await logValue();
}
module.exports = {
deploy,
execute,
};