diff --git a/marketplace/scripts/api.ts b/marketplace/scripts/api.ts index 70c6f01..507de5b 100644 --- a/marketplace/scripts/api.ts +++ b/marketplace/scripts/api.ts @@ -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])