Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeHowarth committed Mar 24, 2023
1 parent 9f48d1a commit 15558f5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 38 deletions.
25 changes: 25 additions & 0 deletions relayer-engine-v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions relayer-engine-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"license": "ISC",
"dependencies": {
"@certusone/wormhole-sdk": "^0.9.11",
"@types/clone": "^2.1.1",
"@types/koa": "^2.13.5",
"clone": "^2.1.2",
"koa": "^2.14.1",
"wormhole-relayer": "github:gabzim/wormhole-relayer#fcc1b7f05e19f4bfdbc2d44c919ee088b5fe5cf3",
"yargs": "^17.7.1"
Expand Down
70 changes: 38 additions & 32 deletions relayer-engine-v2/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import {
Environment,
Next,
StandardRelayerApp,
StandardRelayerContext,
} from "wormhole-relayer"

import {
EVMChainId,
} from "@certusone/wormhole-sdk"
import { EVMChainId } from "@certusone/wormhole-sdk"
import { rootLogger } from "./log"
import { GRContext, processGenericRelayerVaa } from "./processor"
import { processGenericRelayerVaa } from "./processor"
import { Logger } from "winston"
import { sourceTx } from "wormhole-relayer/lib/middleware/source-tx.middleware"
import * as deepCopy from "clone"

export type GRContext = StandardRelayerContext & {
relayProviders: Record<EVMChainId, string>
wormholeRelayer: Record<EVMChainId, string>
}

type Opts = {
flag: Flag
Expand All @@ -35,28 +38,14 @@ type ContractsJson = {

async function main() {
let opts = yargs(process.argv.slice(2)).argv as unknown as Opts

// Config
const contracts = JSON.parse(
await fs.readFile(`../ethereum/ts-scripts/config/testnet/contracts.json`, {
encoding: "utf-8",
})
) as ContractsJson
const chainIds = new Set(contracts.coreRelayers.map((r) => r.chainId))

const privateKey = process.env["PRIVATE_KEY"]! as string
const privateKeys = {} as Record<EVMChainId, [string]>
for (const chainId of chainIds) {
privateKeys[chainId] = [privateKey]
}
const contracts = await loadContractsJson()

const app = new StandardRelayerApp<GRContext>(flagToEnvironment(opts.flag), {
name: "GenericRelayer",
privateKeys,
privateKeys: privateKeys(contracts),
// redis: {},
// redisCluster: {},
// redisClusterEndpoints: [],
fetchSourceTxhash: true,
})

// Build contract address maps
Expand All @@ -71,14 +60,13 @@ async function main() {

// Set up middleware
app.use(async (ctx: GRContext, next: Next) => {
ctx.relayProviders = relayProviders
ctx.wormholeRelayer = wormholeRelayers
ctx.relayProviders = deepCopy(relayProviders)
ctx.wormholeRelayer = deepCopy(wormholeRelayers)
next()
})
app.use(sourceTx())

// Set up routes
app.multiple(wormholeRelayers, processGenericRelayerVaa)
app.multiple(deepCopy(wormholeRelayers), processGenericRelayerVaa)

app.listen()
runUI(app, opts, rootLogger)
Expand All @@ -97,12 +85,6 @@ function runUI(relayer: any, { port }: any, logger: Logger) {
})
}

main().catch((e) => {
console.error("Encountered unrecoverable error:")
console.error(e)
process.exit(1)
})

function flagToEnvironment(flag: Flag): Environment {
switch (flag) {
case Flag.K8sTestnet:
Expand All @@ -115,3 +97,27 @@ function flagToEnvironment(flag: Flag): Environment {
return Environment.DEVNET
}
}

async function loadContractsJson(): Promise<ContractsJson> {
return JSON.parse(
await fs.readFile(`../ethereum/ts-scripts/config/testnet/contracts.json`, {
encoding: "utf-8",
})
) as ContractsJson
}

function privateKeys(contracts: ContractsJson) {
const chainIds = new Set(contracts.coreRelayers.map((r) => r.chainId))
const privateKey = process.env["PRIVATE_KEY"]! as string
const privateKeys = {} as Record<EVMChainId, [string]>
for (const chainId of chainIds) {
privateKeys[chainId] = [privateKey]
}
return privateKeys
}

main().catch((e) => {
console.error("Encountered unrecoverable error:")
console.error(e)
process.exit(1)
})
8 changes: 2 additions & 6 deletions relayer-engine-v2/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as wh from "@certusone/wormhole-sdk"
import { Next, StandardRelayerContext } from "wormhole-relayer"
import { Next } from "wormhole-relayer"
import {
IDelivery,
parseDeliveryInstructionsContainer,
Expand All @@ -9,11 +9,7 @@ import {
RelayProvider__factory,
} from "../pkgs/sdk/src"
import { EVMChainId } from "@certusone/wormhole-sdk"

export type GRContext = StandardRelayerContext & {
relayProviders: Record<EVMChainId, string>
wormholeRelayer: Record<EVMChainId, string>
}
import { GRContext } from "./app"

export async function processGenericRelayerVaa(ctx: GRContext, next: Next) {
const payloadId = parsePayloadType(ctx.vaa!.payload)
Expand Down

0 comments on commit 15558f5

Please sign in to comment.