Skip to content

Commit

Permalink
Enable packet and channel enrichment
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi committed Apr 12, 2024
1 parent 306cbaf commit 464cfad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function updateInitToTryTime<name extends Virtual.EventNames<config>>(cont

}

export async function updateChannel<name extends Virtual.EventNames<config>>(context: Virtual.Context<config, schema, name>, 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)
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class TmClient {

public static async getStargate(): Promise<StargateClient> {
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;
}
Expand Down
32 changes: 26 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ async function closeIbcChannel<name extends Virtual.EventNames<config>>(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,
Expand All @@ -219,6 +220,7 @@ async function closeIbcChannel<name extends Virtual.EventNames<config>>(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,
Expand Down Expand Up @@ -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");
Expand All @@ -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");
// });
// await writeTimeoutPacket(event, c
1 change: 0 additions & 1 deletion src/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ async function updateSendToAckGas<name extends Virtual.EventNames<config>>(conte
}

export async function updatePacket<name extends Virtual.EventNames<config>>(context: Virtual.Context<config, schema, name>, id: string) {
return;
let packet = await context.db.Packet.findUnique({id})
if (!packet) {
console.warn('No packet found with id', id)
Expand Down

0 comments on commit 464cfad

Please sign in to comment.