Skip to content

Commit

Permalink
Merge pull request #1 from initia-labs/feat/set-bridge-info
Browse files Browse the repository at this point in the history
feat: set bridge info
  • Loading branch information
Vritra4 authored Apr 18, 2024
2 parents 47f5183 + 843701b commit c8cbbee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/lib/monitor/l1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Monitor } from './monitor'
import { Coin, Msg, MsgFinalizeTokenDeposit } from '@initia/initia.js'
import {
Coin,
Msg,
MsgFinalizeTokenDeposit,
MsgSetBridgeInfo
} from '@initia/initia.js'
import {
ExecutorDepositTxEntity,
ExecutorUnconfirmedTxEntity,
Expand Down Expand Up @@ -30,6 +35,23 @@ export class L1Monitor extends Monitor {
return 'executor_l1_monitor'
}

public async prepareMonitor(): Promise<void> {
const bridgeInfoL1 = await config.l1lcd.ophost.bridgeInfo(config.BRIDGE_ID)
try {
await this.executor.lcd.opchild.bridgeInfo()
} catch (err) {
const errMsg = err.response?.data
? JSON.stringify(err.response?.data)
: err.toString()
if (errMsg.includes('bridge info not found')) {
const l2Msgs = [
new MsgSetBridgeInfo(this.executor.key.accAddress, bridgeInfoL1)
]
this.executor.transaction(l2Msgs)
}
}
}

public async handleInitiateTokenDeposit(
manager: EntityManager,
data: { [key: string]: string }
Expand Down
4 changes: 4 additions & 0 deletions src/lib/monitor/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export abstract class Monitor {
}

public async monitor(): Promise<void> {
await this.prepareMonitor()
while (this.isRunning) {
try {
const latestHeight = this.socket.latestHeight
Expand Down Expand Up @@ -127,6 +128,9 @@ export abstract class Monitor {
// eslint-disable-next-line
public async handleBlock(manager: EntityManager): Promise<void> {}

// eslint-disable-next-line
public async prepareMonitor(): Promise<void> {}

// eslint-disable-next-line
public name(): string {
return ''
Expand Down

0 comments on commit c8cbbee

Please sign in to comment.