diff --git a/ponder.schema.ts b/ponder.schema.ts index ad6a65e..e7a8e84 100644 --- a/ponder.schema.ts +++ b/ponder.schema.ts @@ -27,6 +27,7 @@ export default createSchema((p) => ({ dispatcherType: p.string(), dispatcherClientName: p.string(), portAddress: p.string(), + portId: p.string(), channelId: p.string(), blockNumber: p.bigint(), blockTimestamp: p.bigint(), diff --git a/src/channel.ts b/src/channel.ts index 222a232..01e29b3 100644 --- a/src/channel.ts +++ b/src/channel.ts @@ -114,7 +114,7 @@ async function updateInitToTryTime>(cont } -export async function updateChannel>(context: Virtual.Context, id: string) { +export async function updateChannel(context: Context, id: string) { let channel = await context.db.Channel.findUnique({id}) if (!channel) { console.warn('No channel found with id', id) diff --git a/src/client.ts b/src/client.ts index b9f6fe0..2a8619d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -19,7 +19,7 @@ export class TmClient { public static async getStargate(): Promise { if (!TmClient.stargate) { - TmClient.stargate = StargateClient.connect(process.env.API_URL!); + TmClient.stargate = StargateClient.connect(process.env.API_URL ?? "http://localhost:26657"); } return TmClient.stargate; } diff --git a/src/index.ts b/src/index.ts index 2a0993f..ec14a55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -211,6 +211,7 @@ async function closeIbcChannel>(event: V const {address, dispatcherType} = getAddressAndDispatcherType(contractName, context); let client = DISPATCHER_CLIENT[address!]; const chainId = context.network.chainId as number; + const portId = `polyibc.${client}.${event.args.portAddress.slice(2)}`; await context.db.CloseIbcChannel.create({ id: event.log.id, @@ -219,6 +220,7 @@ async function closeIbcChannel>(event: V dispatcherType: dispatcherType, dispatcherClientName: client!, portAddress: event.args.portAddress, + portId: portId, channelId: ethers.decodeBytes32String(event.args.channelId), blockNumber: event.block.number, blockTimestamp: event.block.timestamp, @@ -616,6 +618,29 @@ ponder.on("DispatcherProof:Acknowledgement", async ({event, context}) => { await acknowledgement(event, context, "DispatcherProof"); }); +ponder.on("DispatcherProof:setup", async ({context}) => { + let databaseConfig = ponderConfig.database!; + let common = {options: ponderConfig.options} + if (process.env.DATABASE_URL) { + let pool = new pg.Pool({ + statement_timeout: 2 * 60 * 1000, // 2 minutes + connectionString: process.env.DATABASE_URL + }); + + let db = new Kysely({ + dialect: new PostgresDialect({pool: pool}), + log(event) { + console.log(event); + }, + }); + + await db.schema + .createIndex('channel') + .on('Channel') + .columns(["portId", "blockTimestamp", "openTryChannelId", "openInitChannelId", "state"]) + .execute(); + } +}); // ponder.on("DispatcherSim:Timeout", async ({event, context}) => { // await timeout(event, context, "DispatcherSim"); @@ -626,9 +651,4 @@ ponder.on("DispatcherProof:Acknowledgement", async ({event, context}) => { // }); // // ponder.on("DispatcherSim:WriteTimeoutPacket", async ({event, context}) => { -// await writeTimeoutPacket(event, context, "DispatcherSim"); -// }); -// -// ponder.on("DispatcherProof:WriteTimeoutPacket", async ({event, context}) => { -// await writeTimeoutPacket(event, context, "DispatcherProof"); -// }); \ No newline at end of file +// await writeTimeoutPacket(event, c \ No newline at end of file diff --git a/src/packet.ts b/src/packet.ts index 4fce5d8..9b99b6a 100644 --- a/src/packet.ts +++ b/src/packet.ts @@ -181,7 +181,6 @@ async function updateSendToAckGas>(conte } export async function updatePacket>(context: Virtual.Context, id: string) { - return; let packet = await context.db.Packet.findUnique({id}) if (!packet) { console.warn('No packet found with id', id)