-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic skeleton for enumerating existing ibc connections + api endpoint
- Loading branch information
Showing
4 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import db from "@/lib/db"; | ||
import { type NextRequest } from "next/server"; | ||
|
||
export async function GET(_req: NextRequest) { | ||
console.log("SUCCESS: GET /api/ibc/connections"); | ||
try { | ||
console.log("Querying indexer for IBC connections"); | ||
|
||
const connectionsQuery = await db.events.findMany({ | ||
select: { | ||
attributes: { | ||
select: { | ||
key: true, | ||
value: true, | ||
}, | ||
where: { | ||
key: { | ||
equals: "connection_id", | ||
}, | ||
}, | ||
}, | ||
}, | ||
where: { | ||
type: { | ||
equals: "connection_open_init", | ||
}, | ||
}, | ||
orderBy: { | ||
rowid: "desc", | ||
}, | ||
}); | ||
|
||
console.log("Successfully queried for IBC connections.", connectionsQuery); | ||
console.log(connectionsQuery[0].attributes); | ||
|
||
const connections = connectionsQuery.map(({ attributes }) => attributes).flat(); | ||
|
||
return new Response(JSON.stringify(connections)); | ||
|
||
} catch (error) { | ||
console.error("GET request failed.", error); | ||
return new Response("Could not query IBC Connections.", { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { columns } from "./columns"; | ||
import { DataTable } from "../../ui/data-table"; | ||
import { type FC } from "react"; | ||
|
||
interface Props { | ||
data: Array<{ | ||
key: string, | ||
value: string | null, | ||
}>, | ||
} | ||
|
||
const ConnectionsTable : FC<Props> = ({ data }) => { | ||
return ( | ||
<div> | ||
<DataTable columns={columns} data={data}/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConnectionsTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use client"; | ||
|
||
import { type ColumnDef } from "@tanstack/react-table"; | ||
import Link from "next/link"; | ||
|
||
export type ConnectionsColumns = Record<number, { | ||
key: string, | ||
value: string, | ||
}>; | ||
|
||
// TODO formating, styling, etc | ||
export const columns : Array<ColumnDef<ConnectionsColumns>> = [ | ||
{ | ||
id: "connectionId", | ||
// accessorFn: (row) => row[0].value, | ||
accessorKey: "value", | ||
header: () => <div className="font-semibold text-gray-800">Channel ID</div>, | ||
cell: ({ getValue }) => { | ||
// Precondition: value should never be null for `connection_id` | ||
const connectionId = getValue() as string; | ||
return <Link href={`/ibc/connection/${connectionId}`} className="underline">{connectionId}</Link>; | ||
}, | ||
}, | ||
]; |