Skip to content

Commit

Permalink
fix: get invoices from blockhain
Browse files Browse the repository at this point in the history
  • Loading branch information
Haypierre committed Dec 24, 2024
1 parent b95be68 commit bc49f23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

import util from "util";
import { invoiceManager } from "./Invoice";
import { getBlockNumber } from "./utils";

const figlet = require("figlet");
const program = new Command();
Expand Down Expand Up @@ -365,10 +366,15 @@ program
throw new Error(`Unsupported chain: ${chain}`);
}
const paymaster = openfortContracts[chain].paymaster;
console.log(parseAbi(["event InvoiceCreated(bytes32 indexed invoiceId)"]));
const publicClient = publicClients[chain];

const currentBlock = await getBlockNumber(chain);

const logs = await publicClient.getLogs({
address: paymaster,
event: parseAbi(["event InvoiceCreated(bytes32 indexed invoiceId)"])[0],
fromBlock: currentBlock - 10000n,
toBlock: currentBlock,
});

console.log(
Expand Down
6 changes: 5 additions & 1 deletion demo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
keccak256,
numberToHex,
pad,
parseAbi,
toHex,
} from "viem";
import { publicClients } from "./viemClients";
Expand All @@ -25,6 +24,11 @@ export async function getBlockTimestamp(chain: supportedChain) {
return block.timestamp;
}

export async function getBlockNumber(chain: supportedChain) {
const block = await publicClients[chain].getBlockNumber();
return block;
}

export function computeHash(
userOp: PackedUserOperation,
chain: supportedChain,
Expand Down

0 comments on commit bc49f23

Please sign in to comment.