register chain works

This commit is contained in:
spacemandev 2022-05-19 03:43:48 -05:00
parent dab5ca286f
commit a350744738
5 changed files with 4072 additions and 13 deletions

1
projects/messenger/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

View File

@ -1,17 +1,22 @@
import { exec } from "child_process";
import fs from "fs";
import { ethers } from 'ethers';
import {
CHAIN_ID_ETH,
getEmitterAddressEth
} from "@certusone/wormhole-sdk";
async function main(){
let config = JSON.parse(fs.readFileSync('./xdapp.config.json').toString());
let network = config.networks[process.argv[2]];
if (!network){
throw new Error("Network not defined in config file.")
}
if(process.argv[2] == "deploy"){
let network = config.networks[process.argv[3]];
if (!network){
throw new Error("Network not defined in config file.")
}
if(process.argv[3] == "deploy"){
if(network.type == "evm"){
console.log(`Deploying EVM network: ${process.argv[3]} to ${network.rpc}`);
console.log(`Deploying EVM network: ${process.argv[2]} to ${network.rpc}`);
exec(
`cd chains/evm && forge build && forge create --legacy --rpc-url ${network.rpc} --private-key ${network.privateKey} src/Messenger.sol:Messenger && exit`,
((err, out, errStr) => {
@ -22,14 +27,36 @@ async function main(){
if(out) {
console.log(out);
network.deployed_address = out.split("Deployed to: ")[1].split('\n')[0].trim();
config.networks[process.argv[3]] = network;
config.networks[process.argv[2]] = network;
fs.writeFileSync('./xdapp.config.json', JSON.stringify(config, null, 4));
}
})
);
}
} else if (process.argv[2] == "register_chain") {
} else if (process.argv[3] == "register_chain") {
if(!network.deployed_address){
throw new Error("Deploy to this network first!");
}
if(network.type == "evm"){
const signer = new ethers.Wallet(network.privateKey)
.connect(new ethers.providers.JsonRpcProvider(network.rpc));
const targetNetwork = config.networks[process.argv[4]];
if(!targetNetwork.deployed_address){
throw new Error("Target Network not deployed yet!");
}
if(targetNetwork.type == "evm"){
const emitter_address = Buffer.from(getEmitterAddressEth(targetNetwork.deployed_address), "hex");
const messenger = new ethers.Contract(
network.deployed_address,
JSON.parse(fs.readFileSync('./chains/evm/out/Messenger.sol/Messenger.json').toString()).abi,
signer
);
const tx = await messenger.registerApplicationContracts(CHAIN_ID_ETH, emitter_address);
console.log("Registered EVM style Emitter: ", tx.hash);
}
}
} else if (process.argv[2] == "send_msg") {
} else if (process.argv[2] == "submit_vaa") {
@ -37,7 +64,7 @@ async function main(){
} else if (process.argv[2] == "get_current_msg") {
} else {
console.error("Unknown command!");
throw new Error("Unkown command!")
}
}

4026
projects/messenger/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -12,5 +12,9 @@
"workspaces": [
"chains/evm"
],
"type": "module"
"type": "module",
"dependencies": {
"@certusone/wormhole-sdk": "^0.3.3",
"ethers": "^5.6.6"
}
}

View File

@ -4,12 +4,13 @@
"type": "evm",
"rpc": "http://147.182.160.210:8545",
"privateKey": "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
"deployed_address": "0x4cfb3f70bf6a80397c2e634e5bdd85bc0bb189ee"
"deployed_address": "0xc0b3b62dd0400e4baa721ddec9b8a384147b23ff"
},
"eth1": {
"type": "evm",
"rpc": "http://147.182.160.210:8546",
"privateKey": "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"
"privateKey": "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
"deployed_address": "0x4339316e04cffb5961d1c41fef8e44bfa2a7fbd1"
}
}
}