Skip to content

Commit

Permalink
debug: add console.logs
Browse files Browse the repository at this point in the history
  • Loading branch information
yashdesu committed Jul 9, 2024
1 parent c1f3c46 commit 9af4101
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/pages/api/send-transactions/AchievementsSBT/[contract].ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable functional/no-expression-statements */
import { always } from 'ramda'
import { createClient } from 'redis'
import type { APIRoute, Params } from 'astro'
Expand Down Expand Up @@ -52,7 +53,7 @@ export const POST: APIRoute = async ({
isAddress(_p.contract) ? true : new Error('Bad request data'),
) ?? new Error('Bad request data'),
)

console.log('HERE1')
const data = await whenNotErrorAll(
[isValidAuth, request],
async ([_iVA, _request]) =>
Expand Down Expand Up @@ -80,7 +81,7 @@ export const POST: APIRoute = async ({
.catch((err) => new Error(err))
}) ?? new Error('Invalid metadata'),
)

console.log('HERE2')
const sbtContractAddress = whenNotErrorAll(
[isParamValid, params],
([_iPV, _params]) =>
Expand All @@ -90,17 +91,17 @@ export const POST: APIRoute = async ({
: _p.contract
}) ?? new Error('Invalid sbt contract address'),
)

console.log('HERE3')
const wallet = whenNotErrorAll(
[data],
([{ rpcUrl }]) => createWallet({ rpcUrl }) ?? new Error('Wallet error'),
)

console.log('HERE4')
const contract = whenNotErrorAll(
[sbtContractAddress, wallet],
([addr, wal]) => new Contract(addr, abi, wal),
)

console.log('HERE5')
const redis = await whenNotError(
createClient({
url: REDIS_URL,
Expand All @@ -113,7 +114,7 @@ export const POST: APIRoute = async ({
.then(always(db))
.catch((err) => new Error(err)),
)

console.log('HERE6')
const encodedMetadata = await whenNotErrorAll(
[contract, wallet, data, redis],
async ([contract_, , { metadata }]) => {
Expand All @@ -129,7 +130,7 @@ export const POST: APIRoute = async ({
.catch((err: Error) => err)
},
)

console.log('HERE7')
const tx = await whenNotErrorAll(
[contract, wallet, data, redis, encodedMetadata],
async ([
Expand All @@ -153,7 +154,7 @@ export const POST: APIRoute = async ({
.catch((err: Error) => err)
},
)

console.log('HERE8')
const sbtMintLog = await whenNotErrorAll(
[contract, tx],
async ([contract_, tx_]) => {
Expand All @@ -166,15 +167,15 @@ export const POST: APIRoute = async ({
new Error('SBT Mint log not found')
},
)

console.log('HERE9')
const sbtToBeMinted = whenNotErrorAll(
[tx, sbtMintLog],
([tx_, sbtMintLog_]) =>
whenDefinedAll([tx_, sbtMintLog_], ([, ml]) =>
Number(ml.args.at(0).toString()),
) ?? new Error('SBT minted not found'),
)

console.log('HERE10')
const saved = await whenNotErrorAll(
[tx, redis, data, sbtContractAddress, sbtToBeMinted],
([_tx, db, { reqId }, ,]) =>
Expand All @@ -185,14 +186,14 @@ export const POST: APIRoute = async ({
'Missing TransactionResponse field to save the transaction: .to, .data',
),
)

console.log('HERE11')
const result = await whenNotErrorAll([redis], ([db]) =>
db
.quit()
.then((x) => x)
.catch((err: Error) => err),
)

console.log('HERE12')
return result instanceof Error ||
sbtToBeMinted instanceof Error ||
saved instanceof Error
Expand Down

0 comments on commit 9af4101

Please sign in to comment.