Skip to content

Commit

Permalink
added event log related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
qedric committed May 26, 2024
1 parent a80d148 commit 9df5125
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion frontend/contracts/src/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
custom,
parseAbiItem,
encodeFunctionData,
WalletClient} from 'viem'
WalletClient,
decodeEventLog,
Log} from 'viem'
import { sepolia } from 'viem/chains'

import abi from '../../lib/PoEMarketplace_abi.json'
Expand Down Expand Up @@ -58,6 +60,21 @@ export const unwatchRedeem = publicClient.watchEvent({
onLogs: logs => console.log(logs)
})

// uses the logs emitted from watch functions
export const parseEventLogs = (logs:Log[]) => logs
.filter(log => log.address.toLowerCase() === CONTRACT.toLowerCase())
.map(log => decodeEventLog({
abi: abi,
data: log.data,
topics: log.topics
}))
.find(decodedLog => decodedLog.eventName === 'TokenPurchased' || decodedLog.eventName === 'ExploitRedeemed')

// After a token is purchased, the buyer's address is used by the seller to compute the proofs
export const getBuyerAddressFromTokenPurchasedEvent = (tokenPurchasedLog:Log) => (tokenPurchasedLog as any).args.buyer

// After an Exploit is redeemed, the buyer must obtain a) the seller's public key from the signature of the redeem transaction,
// this is handled off-chain, and b) the shared key cipher from the contract, by calling the retrieveSharedKeyCipher function below.

// A White Hat Hacker can post an exploit to the marketplace
export const postExploit = async (walletClient: WalletClient, description: string, price: bigint, hash: bigint) => await writeContract(walletClient, 'postExploit', [description, price, hash])
Expand Down

0 comments on commit 9df5125

Please sign in to comment.