const policy = {maxToll:20000, totalTollBudget:200000} const manifest = { title:'Catalog release supplier', parents:[], permissions:['registry:read'], rule:'On a verified request asking for a dataset release about a topic, search for a matching catalog release.', description:'Supplies existing dataset release blocks to independent requesters on XRPL Testnet.', evaluatorInfo:'Use “Dataset release about ” as the request message. A candidate must have metadata.type equal to dataset-release, a matching metadata.topic and an HTTPS download URL.', market:{toll:0,incentive:0,tollLimits:{}}, pushSubmissionPolicy:policy } const stop = detail => Response.json({decision:'stop',detail}) export default { async fetch(request) { const path=new URL(request.url).pathname if (request.method==='GET' && path==='/manifest') return Response.json(manifest) if (request.method!=='POST' || path!=='/subscription') return new Response(null,{status:404}) const {subscriber,event,block}=await request.json() const offer=block.contextRequest if (!event || !offer || offer.scanner===subscriber) return stop('Waiting for a verified request broadcast.') const topic=/^Dataset release about ([a-z0-9][a-z0-9 -]{0,79})$/i.exec(block.content?.trim())?.[1].toLowerCase() if (!topic) return stop('This request does not specify a catalog topic.') if (offer.network!=='xrpl:1' || offer.asset!=='XRP' || offer.toll>policy.maxToll || offer.incentive<=offer.toll) { return stop('The offered currency, toll or incentive falls outside the supplier policy.') } // Bounded work per push. Candidate titles or messages must mention the topic. const query=new URLSearchParams({q:topic,limit:'50'}) for (let page=0;page<3;page++) { const response=await fetch('https://registry.nexus.internal/api/v2/blocks?'+query) if (!response.ok) throw new Error('Registry search returned HTTP '+response.status) const candidates=await response.json() const match=candidates.find(candidate=>candidate.id!==block.id && !candidate.contextRequest && candidate.metadata?.type==='dataset-release' && typeof candidate.metadata.topic==='string' && candidate.metadata.topic.toLowerCase()===topic && typeof candidate.metadata.downloadUrl==='string' && URL.canParse(candidate.metadata.downloadUrl) && new URL(candidate.metadata.downloadUrl).protocol==='https:') if (match) return Response.json({decision:'record',detail:'Matched catalog release #'+match.id+'.', submission:{blockId:match.id,maxToll:offer.toll}}) if (candidates.length<50) break query.set('after',String(candidates.at(-1).id)) } return stop('No matching catalog release found in the search window.') } }