Skip to content

Commit

Permalink
syn helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jawndiego committed Jun 24, 2024
1 parent a171d9e commit 593a4c5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
12 changes: 4 additions & 8 deletions apps/site/app/api/post/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import {
generatePostTxnInput,
projectIdPost,
} from '@/config/syndicateClient'
import { ethers } from 'ethers'
import type { NextRequest } from 'next/server'
import { addresses, postGatewayABI } from 'scrypt'
import type { Hex } from 'viem'
import { waitUntilTx, authToken } from '@/lib'
import { waitForHash } from '@syndicateio/syndicate-node/utils'

export const maxDuration = 30 // This function can run for a maximum of 30 seconds

Expand All @@ -33,10 +30,9 @@ export async function POST(req: NextRequest) {
generatePostTxnInput(post),
)

const successfulTxHash = await waitUntilTx({
projectID: projectIdPost as string,
txID: postTx.transactionId,
authToken: authToken as string,
const successfulTxHash = await waitForHash(syndicateClientPost, {
projectId: projectIdPost,
transactionId: postTx.transactionId,
})

return new Response(
Expand Down
11 changes: 6 additions & 5 deletions apps/site/app/api/postBatch/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
generatePostBatchTxnInput,
projectIdPost,
} from '@/config/syndicateClient'
import { waitUntilTx, authToken } from '@/lib'
import { waitForHash } from '@syndicateio/syndicate-node/utils'

export async function POST(req: NextRequest) {
const postsArray = await req.json()
Expand All @@ -29,12 +29,13 @@ export async function POST(req: NextRequest) {
generatePostBatchTxnInput(postsArray),
)

const successfulTxHash = await waitUntilTx({
projectID: projectIdPost as string,
txID: postTx.transactionId,
authToken: authToken as string,
const successfulTxHash = await waitForHash(syndicateClientPost, {
projectId: projectIdPost,
transactionId: postTx.transactionId,
})

console.log({ successfulTxHash })

return new Response(
JSON.stringify({ success: true, hash: successfulTxHash }),
{
Expand Down
23 changes: 15 additions & 8 deletions apps/site/app/api/registerFor/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { optimismPubClient } from '@/config/publicClient'
import type { NextRequest } from 'next/server'
import { type Hex, decodeAbiParameters } from 'viem'
import { decodeAbiParameters } from 'viem'
import {
syndicateClientIdRegistry,
generateIdRegistryInput,
projectIdRegistry,
} from '@/config/syndicateClient'
import { waitUntilTx, authToken } from '@/lib'
import { waitForHash } from '@syndicateio/syndicate-node/utils'
import { optimismPubClient } from '@/config/publicClient'
import type { Hex } from 'viem'

export const maxDuration = 30 // This function can run for a maximum of 30 seconds

Expand Down Expand Up @@ -39,18 +40,24 @@ export async function POST(req: NextRequest) {
generateIdRegistryInput({ to, recovery, deadline, sig }),
)

const successfulTxHash = await waitUntilTx({
projectID: projectIdRegistry as string,
txID: registerTx.transactionId,
authToken: authToken as string,
const successfulTxHash = await waitForHash(syndicateClientIdRegistry, {
projectId: projectIdRegistry,
transactionId: registerTx.transactionId,
})

console.log({ successfulTxHash })

const txnReceipt = await optimismPubClient.waitForTransactionReceipt({
hash: successfulTxHash as Hex,
})

const [rid] = decodeAbiParameters(
[
{ name: 'rid', type: 'uint256' },
{ name: 'recoveryAddress', type: 'address' },
],
successfulTxHash.logs[0].data,

txnReceipt.logs[0].data,
)

console.log('rid: ', rid)
Expand Down

0 comments on commit 593a4c5

Please sign in to comment.