Skip to content

Instantly share code, notes, and snippets.

@oneleo
Last active April 30, 2024 10:23
Show Gist options
  • Save oneleo/9225eb13427e9e10d786da0399cc4e02 to your computer and use it in GitHub Desktop.
Save oneleo/9225eb13427e9e10d786da0399cc4e02 to your computer and use it in GitHub Desktop.
Background Main
const fetchData = async () => {
const fetchUserOpsSent = async () => {
const s = storage.get()
const nm = new NetworkStorageManager(storage)
const bundler = nm.getActive().bundler
const bundlerProvider = new JsonRpcProvider(bundler.url)
console.log(
`[ttt] storage userOp: ${json.stringify(s.userOpPool, null, 2)}`
)
const userOps = Object.values(s.userOpPool)
const chainId = s.network[s.networkActive].chainId
const sentUserOps = userOps.filter((userOp) => userOp.status === "Sent")
sentUserOps.forEach(async (sentUserOp) => {
const id = sentUserOp.id
const userOp = new UserOperation(sentUserOp.userOp)
const userOpHash = userOp.hash(sentUserOp.entryPointAddress, chainId)
const txHash = await bundler.wait(userOpHash)
console.log(`[ttt] txHash: ${txHash}`)
// console.log(`[ttt] userOpHash: ${userOpHash}`)
const userOpReceipt = await bundlerProvider.send<{
success: boolean
reason: string
receipt: {
transactionHash: HexString
blockHash: HexString
blockNumber: BigNumberish
}
}>({
method: BundlerRpcMethod.eth_getUserOperationReceipt,
params: [userOpHash]
})
console.log(`[ttt] userOpReceipt.success: ${userOpReceipt.success}`)
if (userOpReceipt && userOpReceipt.success) {
console.log(`[ttt] into if`)
const succeededUserOp: UserOperationStatement = {
...sentUserOp,
status: UserOperationStatus.Succeeded,
receipt: {
userOpHash: userOpHash,
transactionHash: userOpReceipt.receipt.transactionHash,
blockHash: userOpReceipt.receipt.blockHash,
blockNumber: number.toHex(userOpReceipt.receipt.blockNumber)
}
}
const state = { userOpPool: { [id]: succeededUserOp } }
storage.set(state, { override: false })
}
if (userOpReceipt && !userOpReceipt.success) {
}
})
setTimeout(fetchUserOpsSent, 3000)
}
// First call
await fetchUserOpsSent()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment