Skip to content

Commit d34ad6f

Browse files
committed
add relayer wait for receipt endpoint
1 parent 20bf8f9 commit d34ad6f

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Type } from '@sinclair/typebox'
2+
import type { FastifyInstance } from 'fastify'
3+
import { getRelayer } from '~/utils/wallet'
4+
5+
type GetTxReceiptParams = {
6+
chainId: string
7+
metaTxHash: string
8+
}
9+
10+
type GetTxReceiptResponse = {
11+
result?: {
12+
data: {
13+
receipt: unknown
14+
}
15+
error?: string
16+
}
17+
}
18+
19+
const getTxReceiptSchema = {
20+
tags: ['Relayer'],
21+
params: {
22+
type: 'object',
23+
required: ['chainId', 'metaTxHash'],
24+
properties: {
25+
chainId: { type: 'string', description: 'Chain ID' },
26+
metaTxHash: { type: 'string', description: 'Meta transaction hash' }
27+
}
28+
},
29+
response: {
30+
200: Type.Object({
31+
result: Type.Object({
32+
data: Type.Object({
33+
receipt: Type.Any()
34+
}),
35+
error: Type.Optional(Type.String())
36+
})
37+
})
38+
}
39+
}
40+
41+
export async function getTxReceipt(fastify: FastifyInstance) {
42+
fastify.get<{
43+
Params: GetTxReceiptParams
44+
Reply: GetTxReceiptResponse
45+
}>(
46+
'/relayer/receipt/:chainId/:metaTxHash',
47+
{
48+
schema: getTxReceiptSchema
49+
},
50+
async (request, reply) => {
51+
try {
52+
const { chainId, metaTxHash } = request.params
53+
54+
// Get the relayer for the specified chain
55+
const relayer = await getRelayer(chainId)
56+
57+
// Wait for the transaction to be mined and get the receipt
58+
const receipt = await relayer.wait(metaTxHash)
59+
60+
return reply.code(200).send({
61+
result: {
62+
data: {
63+
receipt
64+
}
65+
}
66+
})
67+
} catch (error) {
68+
request.log.error(error)
69+
return reply.code(500).send({
70+
result: {
71+
data: {
72+
receipt: null
73+
},
74+
error:
75+
error instanceof Error
76+
? error.message
77+
: 'Failed to get transaction receipt'
78+
}
79+
})
80+
}
81+
}
82+
)
83+
}

src/routes/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { getAllContracts } from './contract/utils/get/getAllContracts'
3939
import { getContract } from './contract/utils/get/getContract'
4040
import { importContracts } from './contract/utils/importContracts/importContracts'
4141
import { isDeployed } from './contract/utils/isDeployed/isDeployed'
42+
import { getTxReceipt } from './contract/utils/relayer/getTxReceipt'
4243
import { verifyContract } from './contract/utils/verify/verify'
4344
import { writeContract } from './contract/write/write'
4445
import { cleanJobs } from './jobs/cleanJobs'
@@ -150,6 +151,9 @@ export default async function (fastify: FastifyInstance) {
150151
// Register add contract route
151152
addContract(fastify)
152153

154+
// Register relayer routes
155+
getTxReceipt(fastify)
156+
153157
// Webhooks
154158
addWebhook(fastify)
155159
removeWebhook(fastify)

src/utils/wallet.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ export const getProvider = async (chainConfig: NetworkConfig) => {
1515
return provider
1616
}
1717

18+
export const getRelayer = async (chainHandle: string) => {
19+
try {
20+
const chainConfig: NetworkConfig | undefined =
21+
findSupportedNetwork(chainHandle)
22+
23+
if (!chainConfig) {
24+
throw new Error(`Chain config not found for chain handle: ${chainHandle}`)
25+
}
26+
27+
const provider = await getProvider(chainConfig)
28+
29+
const walletEOA = new ethers.Wallet(
30+
process.env.BACKEND_WALLET_PV_KEY || getOrCreateDevKey(),
31+
provider
32+
)
33+
const smartAccount = await Session.singleSigner({
34+
signer: walletEOA,
35+
projectAccessKey: process.env.SEQUENCE_PROJECT_ACCESS_KEY as string
36+
})
37+
38+
return smartAccount.account.relayer(chainConfig.chainId)
39+
} catch (err) {
40+
logger.error(`Error getting local signer: ${err}`)
41+
throw err
42+
}
43+
}
44+
1845
export const getLocalSigner = async (chainHandle: string) => {
1946
try {
2047
const chainConfig: NetworkConfig | undefined =

0 commit comments

Comments
 (0)