Skip to content

Commit

Permalink
Show acks
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi committed Jan 9, 2024
1 parent b50b133 commit 377b791
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/polymerdao/polymer:v0.1.0-alpha.12
FROM ghcr.io/polymerdao/polymer:v0.1.0-alpha.14-hotfix-4

RUN apk add --update --no-cache nodejs npm git

Expand Down
65 changes: 55 additions & 10 deletions app/api/ibc/[type]/packets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ethers } from "ethers";
// import CachingJsonRpcProvider from "./provider";
// import Abi from "../../contracts/Dispatcher.json";
import { NextRequest, NextResponse } from "next/server";
import { CHAIN, CHAIN_CONFIGS } from "../../../chains";
import CachingJsonRpcProvider from "../../metrics/provider";
Expand All @@ -13,13 +11,21 @@ export interface PacketData {
sequence: string;
sourcePortAddress: string;
sourceChannelId: string;
packet: string;
timeout: string;
fee: string;
id: string;
state: string;
}

interface Channel {
version: string;
ordering: string; // Adjust the type based on your ChannelOrder type
feeEnabled: boolean;
connectionHops: string[];
counterpartyPortId: string;
counterpartyChannelId: string; // Assuming bytes32 is represented as a string
}

export async function getPackets(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const from = searchParams.get('from')
Expand All @@ -37,32 +43,71 @@ export async function getPackets(request: NextRequest) {
const chainFromId = chainFrom as CHAIN
const chainToId = chainTo as CHAIN
const dispatcherFromAddress = dispatcher ?? CHAIN_CONFIGS[chainFromId].dispatcher;
const dispatcherToAddress = CHAIN_CONFIGS[chainToId].dispatcher;

const providerFrom = new CachingJsonRpcProvider(CHAIN_CONFIGS[chainFromId].rpc, CHAIN_CONFIGS[chainFromId].id);
const providerTo = new CachingJsonRpcProvider(CHAIN_CONFIGS[chainToId].rpc, CHAIN_CONFIGS[chainToId].id);
const contractFrom = new ethers.Contract(dispatcherFromAddress, Abi.abi, providerFrom);
const contractTo = new ethers.Contract(dispatcherToAddress, Abi.abi, providerTo);

const ackLogs = (await contractFrom.queryFilter('Acknowledgement', fromBlock, toBlock)) as Array<ethers.EventLog>;
const sendPacketLogs = (await contractFrom.queryFilter('SendPacket', fromBlock, toBlock)) as Array<ethers.EventLog>;
const recvPacketLogs = (await contractFrom.queryFilter('RecvPacket', fromBlock, toBlock)) as Array<ethers.EventLog>;
const recvPacketLogs = (await contractTo.queryFilter('RecvPacket', fromBlock, toBlock)) as Array<ethers.EventLog>;
// const connectChannelLogs = (await contractFrom.queryFilter('ConnectIbcChannel', fromBlock, toBlock)) as Array<ethers.EventLog>;

console.log("ackLogs: ", ackLogs, "sendPacketLogs: ", sendPacketLogs, "recvPacketLogs: ", recvPacketLogs)
// console.log("ackLogs: ", ackLogs, "sendPacketLogs: ", sendPacketLogs, "recvPacketLogs: ", recvPacketLogs)
// console.log("connectChannelLogs: ", connectChannelLogs)

const response: PacketData[] = []
const packets: Record<string, PacketData> = {};
sendPacketLogs.forEach((sendPacketLog) => {
const [sourcePortAddress, sourceChannelId, packet, sequence, timeout, fee] = sendPacketLog.args;
const key = `${sourcePortAddress}-${sourceChannelId}-${sequence}`;
response.push({

packets[key] = {
sourcePortAddress,
sourceChannelId,
packet,
sourceChannelId: ethers.decodeBytes32String(sourceChannelId),
fee,
sequence: sequence.toString(),
timeout: timeout.toString(),
id: key,
state: "SENT"
})
};
});

console.log("packets: ", packets)

// for (const recvPacketLog of recvPacketLogs) {
// const [destPortAddress, destChannelId, sequence] = recvPacketLog.args;
// console.log("destPortAddress: ", destPortAddress, "destChannelId: ", destChannelId, "sequence: ", sequence)
// const channelValue = await contractFrom.portChannelMap(destPortAddress, destChannelId)
// const channel: Channel = {
// version: channelValue.version,
// ordering: channelValue.ordering, // Adjust the field name based on the actual field name in your contract
// feeEnabled: channelValue.feeEnabled,
// connectionHops: channelValue.connectionHops,
// counterpartyPortId: channelValue.counterpartyPortId.split(".")[2],
// counterpartyChannelId: ethers.hexlify(channelValue.counterpartyChannelId), // Convert bytes32 to hex string
// };
// console.log("channel: ", channel)
//
// const key = `${channel.counterpartyPortId}-${channel.counterpartyChannelId}-${sequence}`;
// if (packets[key]) {
// packets[key].state = "RECV";
// }
// }

ackLogs.forEach((log) => {
const [sourcePortAddress, sourceChannelId, sequence] = log.args;
const key = `${sourcePortAddress}-${sourceChannelId}-${sequence}`;
if (packets[key]) {
packets[key].state = "ACK";
}
});


const response: PacketData[] = [];
Object.keys(packets).forEach((key) => {
response.push(packets[key]);
});
return Response.json(response)
}
3 changes: 2 additions & 1 deletion app/ibc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function IbcComponent<T extends ChannelSchema | ConnectionSchema | Client
const [filterValue, setFilterValue] = React.useState("");
const [visibleColumns, setVisibleColumns] = React.useState<Selection>(props.initialVisibleColumns);
const [statusFilter, setStatusFilter] = React.useState<Selection>("all");
const [rowsPerPage, setRowsPerPage] = React.useState(10);
const [rowsPerPage, setRowsPerPage] = React.useState(25);
const [sortDescriptor, setSortDescriptor] = React.useState<SortDescriptor>(props.defaultSortDescriptor);
const [ibcItems, setIbcItems] = React.useState<T[]>([]);
const [page, setPage] = React.useState(1);
Expand Down Expand Up @@ -264,6 +264,7 @@ export function IbcComponent<T extends ChannelSchema | ConnectionSchema | Client

<Table
aria-label="Example table with custom cells, pagination and sorting"
isStriped
isHeaderSticky
bottomContent={bottomContent}
bottomContentPlacement="outside"
Expand Down
2 changes: 1 addition & 1 deletion deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: ibc-explorer
image: ghcr.io/polymerdao/ibc-explorer:v0.0.2-alpha-16
image: ghcr.io/polymerdao/ibc-explorer:v0.0.2-alpha-17
resources:
limits:
cpu: '1'
Expand Down

0 comments on commit 377b791

Please sign in to comment.