Skip to content

Commit

Permalink
add loop to search for attestationHash
Browse files Browse the repository at this point in the history
  • Loading branch information
RamRamez committed Sep 1, 2024
1 parent 3973772 commit c70862c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/routes/replyAttestation.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
import neynarClient from "../helpers/neynarClient.js";
import {getProvider} from "../helpers/ethers.js";
import {NETWORK_IDS} from "../helpers/constants.js";
import {JsonRpcProvider} from "ethers";

const baseAttestationScan = 'https://base.easscan.org/attestation/view/';

const wait = async (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

const getAttestationHash = async (txHash: string, provider: JsonRpcProvider) => {
const receipt = await provider.getTransactionReceipt(txHash);
return receipt?.logs[0]?.data
}

const replyAttestation = async (req: Request) => {
if (!process.env.SIGNER_UUID) {
throw new Error("Make sure you set SIGNER_UUID in your .env file");
}
const body = await req.text();
const data = JSON.parse(body);
const { txHash, praiseHash } = data;
if (!txHash || !praiseHash) {
throw new Error("txHash and praiseHash are required");
}
console.log('-----------------');
console.log('txHash', txHash);
console.log('praiseHash', praiseHash);
console.log('-----------------');
const provider = getProvider(NETWORK_IDS.BASE_MAINNET);
const receipt = await provider.getTransactionReceipt(txHash);
const attestationHash = receipt?.logs[0]?.data
if (!attestationHash || !praiseHash) {
throw new Error("attestationHash and praiseHash are required");
let attestationHash;
let loopCount = 0;
while (!attestationHash || loopCount < 10) {
await wait(5000);
attestationHash = await getAttestationHash(txHash, provider);
loopCount++;
if (loopCount === 10 && !attestationHash) {
console.log("Attestation hash not found! Date: " + new Date().toISOString() + " txHash: " + txHash + " praiseHash: " + praiseHash);
throw new Error("Attestation hash not found");
}
}
await neynarClient.publishCast(
process.env.SIGNER_UUID,
Expand Down

0 comments on commit c70862c

Please sign in to comment.