1import{s as b,t as x,f as F,A as I,d as C,g as M,a as E,b as D,e as w,c as G,h as A,i as T,I as H,j as m,k as v,l as R,m as k,B as y,n as N,o as P,p as j,q as B,r as U,H as L,u as _}from"./contracts-worker-BYaZ732j.js";function J(e){const{abi:s,data:a}=e,r=b(a,0,4),t=s.find(n=>n.type==="function"&&r===x(F(n)));if(!t)throw new I(r,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:t.name,args:"inputs"in t&&t.inputs&&t.inputs.length>0?C(t.inputs,b(a,4)):void 0}}const p="/docs/contract/encodeErrorResult";function O(e){const{abi:s,errorName:a,args:r}=e;let t=s[0];if(a){const d=M({abi:s,args:r,name:a});if(!d)throw new E(a,{docsPath:p});t=d}if(t.type!=="error")throw new E(void 0,{docsPath:p});const n=F(t),o=x(n);let c="0x";if(r&&r.length>0){if(!t.inputs)throw new D(t.name,{docsPath:p});c=w(t.inputs,r)}return G([o,c])}const h="/docs/contract/encodeFunctionResult";function W(e){const{abi:s,functionName:a,result:r}=e;let t=s[0];if(a){const o=M({abi:s,name:a});if(!o)throw new A(a,{docsPath:h});t=o}if(t.type!=="function")throw new A(void 0,{docsPath:h});if(!t.outputs)throw new T(t.name,{docsPath:h});const n=(()=>{if(t.outputs.length===0)return[];if(t.outputs.length===1)return[r];if(Array.isArray(r))return r;throw new H(r)})();return w(t.outputs,n)}const q="x-batch-gateway:true";async function S(e){const{data:s,ccipRequest:a}=e,{args:[r]}=J({abi:m,data:s}),t=[],n=[];return await Promise.all(r.map(async(o,c)=>{try{n[c]=o.urls.includes(q)?await S({data:o.data,ccipRequest:a}):await a(o),t[c]=!1}catch(d){t[c]=!0,n[c]=z(d)}})),W({abi:m,functionName:"query",result:[t,n]})}function z(e){return e.name==="HttpRequestError"&&e.status?O({abi:m,errorName:"HttpError",args:[e.status,e.shortMessage]}):O({abi:[v],errorName:"Error",args:["shortMessage"in e?e.shortMessage:e.message]})}function K(e,s){if(!R(e,{strict:!1}))throw new k({address:e});if(!R(s,{strict:!1}))throw new k({address:s});return e.toLowerCase()===s.toLowerCase()}class Q extends y{constructor({callbackSelector:s,cause:a,data:r,extraData:t,sender:n,urls:o}){super(a.shortMessage||"An error occurred while fetching for an offchain result.",{cause:a,metaMessages:[...a.metaMessages||[],a.metaMessages?.length?"":[],"Offchain Gateway Call:",o&&[" Gateway URL(s):",...o.map(c=>` ${N(c)}`)],` Sender: ${n}`,` Data: ${r}`,` Callback selector: ${s}`,` Extra data: ${t}`].flat(),name:"OffchainLookupError"})}}class V extends y{constructor({result:s,url:a}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${N(a)}`,`Response: ${P(s)}`],name:"OffchainLookupResponseMalformedError"})}}class X extends y{constructor({sender:s,to:a}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${a}`,`OffchainLookup sender address: ${s}`],name:"OffchainLookupSenderMismatchError"})}}const et="0x556f1830",Y={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function at(e,{blockNumber:s,blockTag:a,data:r,to:t}){const{args:n}=j({data:r,abi:[Y]}),[o,c,d,i,u]=n,{ccipRead:f}=e,g=f&&typeof f?.request=="function"?f.request:Z;try{if(!K(t,o))throw new X({sender:o,to:t});const l=c.includes(q)?await S({data:d,ccipRequest:g}):await g({data:d,sender:o,urls:c}),{data:$}=await B(e,{blockNumber:s,blockTag:a,data:U([i,w([{type:"bytes"},{type:"bytes"}],[l,u])]),to:t});return $}catch(l){throw new Q({callbackSelector:i,cause:l,data:r,extraData:u,sender:o,urls:c})}}async function Z({data:e,sender:s,urls:a}){let r=new Error("An unknown error occurred.");for(let t=0;t<a.length;t++){const n=a[t],o=n.includes("{data}")?"GET":"POST",c=o==="POST"?{data:e,sender:s}:void 0,d=o==="POST"?{"Content-Type":"application/json"}:{};try{const i=await fetch(n.replace("{sender}",s.toLowerCase()).replace("{data}",e),{body:JSON.stringify(c),headers:d,method:o});let u;if(i.headers.get("Content-Type")?.startsWith("application/json")?u=(await i.json()).data:u=await i.text(),!i.ok){r=new L({body:c,details:u?.error?P(u.error):i.statusText,headers:i.headers,status:i.status,url:n});continue}if(!_(u)){r=new V({result:u,url:n});continue}return u}catch(i){r=new L({body:c,details:i.message,url:n})}}throw r}export{Z as ccipRequest,at as offchainLookup,Y as offchainLookupAbiItem,et as offchainLookupSignature};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.