diff --git a/web/packages/api/src/history_v2.ts b/web/packages/api/src/history_v2.ts index b1ca251b6b..1f4d278575 100644 --- a/web/packages/api/src/history_v2.ts +++ b/web/packages/api/src/history_v2.ts @@ -245,8 +245,8 @@ const buildToEthereumTransferResult = (transfer: any): ToEthereumTransferResult return result } -export const toPolkadotHistory = async (): Promise => { - const allTransfers = await fetchToPolkadotTransfers() +export const toPolkadotHistory = async (graphqlApiUrl: string, graphqlQuerySize: number): Promise => { + const allTransfers = await fetchToPolkadotTransfers(graphqlApiUrl, graphqlQuerySize) const results: ToPolkadotTransferResult[] = [] for (const transfer of allTransfers) { let result = buildToPolkadotTransferResult(transfer) @@ -255,8 +255,8 @@ export const toPolkadotHistory = async (): Promise = return results } -export const toEthereumHistory = async (): Promise => { - const allTransfers = await fetchToEthereumTransfers() +export const toEthereumHistory = async (graphqlApiUrl: string, graphqlQuerySize: number): Promise => { + const allTransfers = await fetchToEthereumTransfers(graphqlApiUrl, graphqlQuerySize) const results: ToEthereumTransferResult[] = [] for (const transfer of allTransfers) { let result = buildToEthereumTransferResult(transfer) @@ -266,9 +266,10 @@ export const toEthereumHistory = async (): Promise = } export const toPolkadotTransferById = async ( + graphqlApiUrl: string, id: string ): Promise => { - const transfers = await fetchToPolkadotTransferById(id) + const transfers = await fetchToPolkadotTransferById(graphqlApiUrl, id) if (transfers?.length > 0) { let result = buildToPolkadotTransferResult(transfers[0]) return result @@ -277,9 +278,10 @@ export const toPolkadotTransferById = async ( } export const toEthereumTransferById = async ( + graphqlApiUrl: string, id: string ): Promise => { - const transfers = await fetchToEthereumTransferById(id) + const transfers = await fetchToEthereumTransferById(graphqlApiUrl, id) if (transfers?.length > 0) { let result = buildToEthereumTransferResult(transfers[0]) return result diff --git a/web/packages/api/src/status.ts b/web/packages/api/src/status.ts index 837cf9f7e7..dc5f6a6abc 100644 --- a/web/packages/api/src/status.ts +++ b/web/packages/api/src/status.ts @@ -260,7 +260,7 @@ export const channelStatusInfo = async ( "0xc173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539" ) { try { - estimatedDeliveryTime = await fetchEstimatedDeliveryTime(channelId) + estimatedDeliveryTime = await fetchEstimatedDeliveryTime(context.config.graphqlApiUrl, channelId) } catch (e: any) { console.error("estimate api error:" + e.message) } diff --git a/web/packages/api/src/subsquid.ts b/web/packages/api/src/subsquid.ts index 706bebc116..37215af66e 100644 --- a/web/packages/api/src/subsquid.ts +++ b/web/packages/api/src/subsquid.ts @@ -1,9 +1,3 @@ -const graphqlApiUrl = - process.env["GRAPHQL_API_URL"] || - process.env["NEXT_PUBLIC_GRAPHQL_API_URL"] || - "https://snowbridge.squids.live/snowbridge-subsquid-polkadot@v1/api/graphql" -const graphqlQuerySize = process.env["GRAPHQL_QUERY_SIZE"] || "100" - /** * Query the recent transfers from Ethereum to Polkadot @@ -41,7 +35,7 @@ $graphqlApiUrl --no-progress-meter | jq "." ... ] **/ -export const fetchToPolkadotTransfers = async () => { +export const fetchToPolkadotTransfers = async (graphqlApiUrl: string, graphqlQuerySize: number) => { let query = `query { transferStatusToPolkadots(limit: ${graphqlQuerySize}, orderBy: timestamp_DESC) { id status @@ -80,7 +74,7 @@ export const fetchToPolkadotTransfers = async () => { } } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.transferStatusToPolkadots } @@ -122,7 +116,7 @@ $graphqlApiUrl --no-progress-meter | jq "." ... ] **/ -export const fetchToEthereumTransfers = async () => { +export const fetchToEthereumTransfers = async (graphqlApiUrl: string, graphqlQuerySize: number) => { let query = `query { transferStatusToEthereums(limit: ${graphqlQuerySize}, orderBy: timestamp_DESC) { id status @@ -163,11 +157,11 @@ export const fetchToEthereumTransfers = async () => { } } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.transferStatusToEthereums } -const fetchBridgeHubOutboundMessageAccepted = async (messageID: string) => { +const fetchBridgeHubOutboundMessageAccepted = async (graphqlApiUrl: string, messageID: string) => { let query = `query { outboundMessageAcceptedOnBridgeHubs(where: {messageId_eq:"${messageID}"}) { id nonce @@ -175,11 +169,11 @@ const fetchBridgeHubOutboundMessageAccepted = async (messageID: string) => { timestamp } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.outboundMessageAcceptedOnBridgeHubs[0] } -const fetchEthereumInboundMessageDispatched = async (messageID: string) => { +const fetchEthereumInboundMessageDispatched = async (graphqlApiUrl: string, messageID: string) => { let query = `query {inboundMessageDispatchedOnEthereums(where: {messageId_eq: "${messageID}"}) { id channelId @@ -191,11 +185,11 @@ const fetchEthereumInboundMessageDispatched = async (messageID: string) => { txHash } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.inboundMessageDispatchedOnEthereums[0] } -const fetchBridgeHubInboundMessageReceived = async (messageID: string) => { +const fetchBridgeHubInboundMessageReceived = async (graphqlApiUrl: string, messageID: string) => { let query = `query { inboundMessageReceivedOnBridgeHubs(where: {messageId_eq:"${messageID}"}) { id channelId @@ -205,11 +199,11 @@ const fetchBridgeHubInboundMessageReceived = async (messageID: string) => { timestamp } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.inboundMessageReceivedOnBridgeHubs[0] } -const fetchMessageProcessedOnPolkadot = async (messageID: string) => { +const fetchMessageProcessedOnPolkadot = async (graphqlApiUrl: string, messageID: string) => { let query = `query { messageProcessedOnPolkadots(where: {messageId_eq:"${messageID}"}) { id blockNumber @@ -219,7 +213,7 @@ const fetchMessageProcessedOnPolkadot = async (messageID: string) => { success } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.messageProcessedOnPolkadots[0] } @@ -244,16 +238,16 @@ $graphqlApiUrl --no-progress-meter | jq "." } } **/ -export const fetchEstimatedDeliveryTime = async (channelId: string) => { +export const fetchEstimatedDeliveryTime = async (graphqlApiUrl: string, channelId: string) => { let query = `query { toEthereumElapse(channelId:"${channelId}") { elapse } toPolkadotElapse(channelId:"${channelId}") { elapse } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result } /** * Query with a raw graphql **/ -export const queryByGraphQL = async (query: string) => { +export const queryByGraphQL = async (graphqlApiUrl: string, query: string) => { let response = await fetch(graphqlApiUrl, { method: "POST", headers: { @@ -303,7 +297,7 @@ $graphqlApiUrl --no-progress-meter | jq "." } ] **/ -export const fetchToPolkadotTransferById = async (id: string) => { +export const fetchToPolkadotTransferById = async (graphqlApiUrl: string, id: string) => { let query = `query { transferStatusToPolkadots(where: {messageId_eq: "${id}", OR: {txHash_eq: "${id}"}}) { id status @@ -342,7 +336,7 @@ export const fetchToPolkadotTransferById = async (id: string) => { } } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.transferStatusToPolkadots } @@ -383,7 +377,7 @@ $graphqlApiUrl --no-progress-meter | jq "." } ] **/ -export const fetchToEthereumTransferById = async (id: string) => { +export const fetchToEthereumTransferById = async (graphqlApiUrl: string, id: string) => { let query = `query { transferStatusToEthereums(where: {messageId_eq: "${id}", OR: {txHash_eq: "${id}"}}) { id status @@ -424,7 +418,7 @@ export const fetchToEthereumTransferById = async (id: string) => { } } }` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result?.transferStatusToEthereums } @@ -455,11 +449,11 @@ $graphqlApiUrl --no-progress-meter | jq "." } } **/ -export const fetchLatestBlocksSynced = async () => { +export const fetchLatestBlocksSynced = async (graphqlApiUrl: string) => { let query = `query { latestBlocks { height name }}` - let result = await queryByGraphQL(query) + let result = await queryByGraphQL(graphqlApiUrl, query) return result } diff --git a/web/packages/operations/src/global_transfer_history_v2.ts b/web/packages/operations/src/global_transfer_history_v2.ts index b3aed3dc3d..6269bfe0ef 100644 --- a/web/packages/operations/src/global_transfer_history_v2.ts +++ b/web/packages/operations/src/global_transfer_history_v2.ts @@ -2,12 +2,17 @@ import "dotenv/config" import { historyV2 } from "@snowbridge/api" const monitor = async () => { + const graphqlApiUrl = + process.env["GRAPHQL_API_URL"] || + "https://snowbridge.squids.live/snowbridge-subsquid-polkadot@v1/api/graphql" +const graphqlQuerySize = process.env["GRAPHQL_QUERY_SIZE"] || "100" + console.log("To Ethereum transfers:") - const toEthereums = await historyV2.toEthereumHistory() + const toEthereums = await historyV2.toEthereumHistory(graphqlApiUrl, Number(graphqlQuerySize)) console.log(JSON.stringify(toEthereums, null, 2)) console.log("To Polkadot transfers:") - const toPolkadots = await historyV2.toPolkadotHistory() + const toPolkadots = await historyV2.toPolkadotHistory(graphqlApiUrl, Number(graphqlQuerySize)) console.log(JSON.stringify(toPolkadots, null, 2)) console.log("All transfers order by time:") @@ -17,12 +22,14 @@ const monitor = async () => { console.log("To Polkadot transfer by id:") const toPolkadot = await historyV2.toPolkadotTransferById( + graphqlApiUrl, "0xb56662848712da9769a2122ca0d24d199ef7af7c8aedee43778dadbe1c42ebc6" ) console.log(JSON.stringify(toPolkadot, null, 2)) console.log("To Ethereum transfer by id:") const toEthereum = await historyV2.toEthereumTransferById( + graphqlApiUrl, "0x04b7a6c7552d2890094dfe43e037cb5f5495fec2419f33b0072439a9ee7629a0" ) console.log(JSON.stringify(toEthereum, null, 2)) diff --git a/web/packages/operations/src/monitor.ts b/web/packages/operations/src/monitor.ts index 8dbaa02fac..0b0c835427 100644 --- a/web/packages/operations/src/monitor.ts +++ b/web/packages/operations/src/monitor.ts @@ -171,7 +171,7 @@ export const monitor = async (): Promise => { const latestBlockOfBH = (await bridgeHub.query.system.number()).toPrimitive() as number const latestBlockOfEth = await ethereum.getBlockNumber() - const chains = await subsquid.fetchLatestBlocksSynced() + const chains = await subsquid.fetchLatestBlocksSynced(context.config.graphqlApiUrl ?? snowbridgeEnv.config.GRAPHQL_API_URL!) for (let chain of chains?.latestBlocks) { let info: status.IndexerServiceStatusInfo = { chain: chain.name,