1import{aj as b,ak as x,al as F,am as N,an as P,ao as O,ap as E,aq as S,ar as w,as as $,at as A,au as D,av as G,aw as m,ax as C,ay as y,az as L,aA as q,aB as I,aC as T,aD as v,aE as H,aF as R,aG as j}from"./index-DjgNvJ9Y.js";function B(a){const{abi:r,data:e}=a,s=b(e,0,4),t=r.find(o=>o.type==="function"&&s===x(F(o)));if(!t)throw new N(s,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:t.name,args:"inputs"in t&&t.inputs&&t.inputs.length>0?P(t.inputs,b(e,4)):void 0}}const p="/docs/contract/encodeErrorResult";function k(a){const{abi:r,errorName:e,args:s}=a;let t=r[0];if(e){const u=O({abi:r,args:s,name:e});if(!u)throw new E(e,{docsPath:p});t=u}if(t.type!=="error")throw new E(void 0,{docsPath:p});const o=F(t),n=x(o);let c="0x";if(s&&s.length>0){if(!t.inputs)throw new S(t.name,{docsPath:p});c=w(t.inputs,s)}return $([n,c])}const h="/docs/contract/encodeFunctionResult";function U(a){const{abi:r,functionName:e,result:s}=a;let t=r[0];if(e){const n=O({abi:r,name:e});if(!n)throw new A(e,{docsPath:h});t=n}if(t.type!=="function")throw new A(void 0,{docsPath:h});if(!t.outputs)throw new D(t.name,{docsPath:h});const o=(()=>{if(t.outputs.length===0)return[];if(t.outputs.length===1)return[s];if(Array.isArray(s))return s;throw new G(s)})();return w(t.outputs,o)}const _="x-batch-gateway:true";async function z(a){const{data:r,ccipRequest:e}=a,{args:[s]}=B({abi:m,data:r}),t=[],o=[];return await Promise.all(s.map(async(n,c)=>{try{o[c]=await e(n),t[c]=!1}catch(u){t[c]=!0,o[c]=J(u)}})),U({abi:m,functionName:"query",result:[t,o]})}function J(a){return a.name==="HttpRequestError"&&a.status?k({abi:m,errorName:"HttpError",args:[a.status,a.shortMessage]}):k({abi:[C],errorName:"Error",args:["shortMessage"in a?a.shortMessage:a.message]})}class W extends y{constructor({callbackSelector:r,cause:e,data:s,extraData:t,sender:o,urls:n}){var c;super(e.shortMessage||"An error occurred while fetching for an offchain result.",{cause:e,metaMessages:[...e.metaMessages||[],(c=e.metaMessages)!=null&&c.length?"":[],"Offchain Gateway Call:",n&&[" Gateway URL(s):",...n.map(u=>` ${L(u)}`)],` Sender: ${o}`,` Data: ${s}`,` Callback selector: ${r}`,` Extra data: ${t}`].flat(),name:"OffchainLookupError"})}}class K extends y{constructor({result:r,url:e}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${L(e)}`,`Response: ${q(r)}`],name:"OffchainLookupResponseMalformedError"})}}class Q extends y{constructor({sender:r,to:e}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${e}`,`OffchainLookup sender address: ${r}`],name:"OffchainLookupSenderMismatchError"})}}const Z="0x556f1830",V={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 tt(a,{blockNumber:r,blockTag:e,data:s,to:t}){const{args:o}=I({data:s,abi:[V]}),[n,c,u,f,d]=o,{ccipRead:i}=a,g=i&&typeof(i==null?void 0:i.request)=="function"?i.request:X;try{if(!T(t,n))throw new Q({sender:n,to:t});const l=c.includes(_)?await z({data:u,ccipRequest:g}):await g({data:u,sender:n,urls:c}),{data:M}=await v(a,{blockNumber:r,blockTag:e,data:H([f,w([{type:"bytes"},{type:"bytes"}],[l,d])]),to:t});return M}catch(l){throw new W({callbackSelector:f,cause:l,data:s,extraData:d,sender:n,urls:c})}}async function X({data:a,sender:r,urls:e}){var t;let s=new Error("An unknown error occurred.");for(let o=0;o<e.length;o++){const n=e[o],c=n.includes("{data}")?"GET":"POST",u=c==="POST"?{data:a,sender:r}:void 0,f=c==="POST"?{"Content-Type":"application/json"}:{};try{const d=await fetch(n.replace("{sender}",r.toLowerCase()).replace("{data}",a),{body:JSON.stringify(u),headers:f,method:c});let i;if((t=d.headers.get("Content-Type"))!=null&&t.startsWith("application/json")?i=(await d.json()).data:i=await d.text(),!d.ok){s=new R({body:u,details:i!=null&&i.error?q(i.error):d.statusText,headers:d.headers,status:d.status,url:n});continue}if(!j(i)){s=new K({result:i,url:n});continue}return i}catch(d){s=new R({body:u,details:d.message,url:n})}}throw s}export{X as ccipRequest,tt as offchainLookup,V as offchainLookupAbiItem,Z 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.