Skip to content

Commit

Permalink
added event listener for redeem
Browse files Browse the repository at this point in the history
  • Loading branch information
qedric committed May 25, 2024
1 parent b86790c commit c79660d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions marketplace/scripts/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,28 @@ const writeContract = async (functionName:string, args: any[]) => {

// watches for the TokenPurchased event emitted during the purchaseToken function call.
// This will be used to trigger the redeem function call.
export const unwatch = publicClient.watchEvent({
export const unwatchPurchase = publicClient.watchEvent({
address: CONTRACT as `0x${string}`,
event: parseAbiItem('event TokenPurchased(uint256 indexed id, address indexed buyer)'),
// TO DO - call function with logs to derive public key https://viem.sh/docs/utilities/recoverPublicKey#recoverpublickey
onLogs: logs => console.log(logs)
})

// watches for the TokenPurchased event emitted during the purchaseToken function call.
// This will be used to trigger the redeem function call.
export const unwatchRedeem = publicClient.watchEvent({
address: CONTRACT as `0x${string}`,
event: parseAbiItem('event ExploitRedeemed(uint256 indexed id, address indexed buyer)'),
// TO DO - call function with logs to derive public key https://viem.sh/docs/utilities/recoverPublicKey#recoverpublickey
onLogs: logs => console.log(logs)
})


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

// A vendor can purchase the exploit token from the marketplace
export const purchaseToken = async (tokenId:number, publicKey:bigint[]) => await writeContract('purchaseToken', [tokenId, publicKey])
export const purchaseToken = async (tokenId:number) => await writeContract('purchaseToken', [tokenId])

// The White Hat Hacker uses the vendor's public key derived from the purchaseToken transaction to compute the proofs and receive the payment
export const redeem = async (tokenId:number, key:bigint) => await writeContract('redeemExploit', [tokenId, key])
Expand Down

0 comments on commit c79660d

Please sign in to comment.