1import{es as b,et as L,eu as x,ev as q,ew as $,ex as F,ey as E,ez as D,dL as w,dN as G,eA as R,eB as I,eC as C,eD as m,eE as T,eF as y,eG as O,eH as M,eI as H,eJ as v,eK as B,eL as U,eM as A,eN as j}from"./index-hZR_pMzJ.js";function J(a){const{abi:r,data:t}=a,s=b(t,0,4),e=r.find(n=>n.type==="function"&&s===L(x(n)));if(!e)throw new q(s,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:e.name,args:"inputs"in e&&e.inputs&&e.inputs.length>0?$(e.inputs,b(t,4)):void 0}}const p="/docs/contract/encodeErrorResult";function k(a){const{abi:r,errorName:t,args:s}=a;let e=r[0];if(t){const d=F({abi:r,args:s,name:t});if(!d)throw new E(t,{docsPath:p});e=d}if(e.type!=="error")throw new E(void 0,{docsPath:p});const n=x(e),o=L(n);let c="0x";if(s&&s.length>0){if(!e.inputs)throw new D(e.name,{docsPath:p});c=w(e.inputs,s)}return G([o,c])}const h="/docs/contract/encodeFunctionResult";function _(a){const{abi:r,functionName:t,result:s}=a;let e=r[0];if(t){const o=F({abi:r,name:t});if(!o)throw new R(t,{docsPath:h});e=o}if(e.type!=="function")throw new R(void 0,{docsPath:h});if(!e.outputs)throw new I(e.name,{docsPath:h});const n=(()=>{if(e.outputs.length===0)return[];if(e.outputs.length===1)return[s];if(Array.isArray(s))return s;throw new C(s)})();return w(e.outputs,n)}const N="x-batch-gateway:true";async function P(a){const{data:r,ccipRequest:t}=a,{args:[s]}=J({abi:m,data:r}),e=[],n=[];return await Promise.all(s.map(async(o,c)=>{try{n[c]=o.urls.includes(N)?await P({data:o.data,ccipRequest:t}):await t(o),e[c]=!1}catch(d){e[c]=!0,n[c]=z(d)}})),_({abi:m,functionName:"query",result:[e,n]})}function z(a){return a.name==="HttpRequestError"&&a.status?k({abi:m,errorName:"HttpError",args:[a.status,a.shortMessage]}):k({abi:[T],errorName:"Error",args:["shortMessage"in a?a.shortMessage:a.message]})}class K extends y{constructor({callbackSelector:r,cause:t,data:s,extraData:e,sender:n,urls:o}){super(t.shortMessage||"An error occurred while fetching for an offchain result.",{cause:t,metaMessages:[...t.metaMessages||[],t.metaMessages?.length?"":[],"Offchain Gateway Call:",o&&[" Gateway URL(s):",...o.map(c=>` ${O(c)}`)],` Sender: ${n}`,` Data: ${s}`,` Callback selector: ${r}`,` Extra data: ${e}`].flat(),name:"OffchainLookupError"})}}class W extends y{constructor({result:r,url:t}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${O(t)}`,`Response: ${M(r)}`],name:"OffchainLookupResponseMalformedError"})}}class Q extends y{constructor({sender:r,to:t}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${t}`,`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 ee(a,{blockNumber:r,blockTag:t,data:s,to:e}){const{args:n}=H({data:s,abi:[V]}),[o,c,d,i,u]=n,{ccipRead:f}=a,g=f&&typeof f?.request=="function"?f.request:X;try{if(!v(e,o))throw new Q({sender:o,to:e});const l=c.includes(N)?await P({data:d,ccipRequest:g}):await g({data:d,sender:o,urls:c}),{data:S}=await B(a,{blockNumber:r,blockTag:t,data:U([i,w([{type:"bytes"},{type:"bytes"}],[l,u])]),to:e});return S}catch(l){throw new K({callbackSelector:i,cause:l,data:s,extraData:u,sender:o,urls:c})}}async function X({data:a,sender:r,urls:t}){let s=new Error("An unknown error occurred.");for(let e=0;e<t.length;e++){const n=t[e],o=n.includes("{data}")?"GET":"POST",c=o==="POST"?{data:a,sender:r}:void 0,d=o==="POST"?{"Content-Type":"application/json"}:{};try{const i=await fetch(n.replace("{sender}",r.toLowerCase()).replace("{data}",a),{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){s=new A({body:c,details:u?.error?M(u.error):i.statusText,headers:i.headers,status:i.status,url:n});continue}if(!j(u)){s=new W({result:u,url:n});continue}return u}catch(i){s=new A({body:c,details:i.message,url:n})}}throw s}export{X as ccipRequest,ee 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.