import{B as e,u as a,v as t,x as r,y as s,z as n,A as o,D as c,E as u,H as d,F as l}from"./p-3c0f264f.js";class i extends e{constructor({callbackSelector:e,cause:t,data:r,extraData:s,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((e=>`    ${a(e)}`))],`  Sender: ${n}`,`  Data: ${r}`,`  Callback selector: ${e}`,`  Extra data: ${s}`].flat()});Object.defineProperty(this,"name",{enumerable:true,configurable:true,writable:true,value:"OffchainLookupError"})}}class f extends e{constructor({result:e,url:r}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${a(r)}`,`Response: ${t(e)}`]});Object.defineProperty(this,"name",{enumerable:true,configurable:true,writable:true,value:"OffchainLookupResponseMalformedError"})}}class b extends e{constructor({sender:e,to:a}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${a}`,`OffchainLookup sender address: ${e}`]});Object.defineProperty(this,"name",{enumerable:true,configurable:true,writable:true,value:"OffchainLookupSenderMismatchError"})}}function p(e,a){if(!r(e))throw new s({address:e});if(!r(a))throw new s({address:a});return e.toLowerCase()===a.toLowerCase()}const w="0x556f1830";const h={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 m(e,{blockNumber:a,blockTag:t,data:r,to:s}){const{args:d}=n({data:r,abi:[h]});const[l,f,w,m,k]=d;try{if(!p(s,l))throw new b({sender:l,to:s});const r=await y({data:w,sender:l,urls:f});const{data:n}=await o(e,{blockNumber:a,blockTag:t,data:c([m,u([{type:"bytes"},{type:"bytes"}],[r,k])]),to:s});return n}catch(e){throw new i({callbackSelector:m,cause:e,data:r,extraData:k,sender:l,urls:f})}}async function y({data:e,sender:a,urls:r}){let s=new Error("An unknown error occurred.");for(let n=0;n<r.length;n++){const o=r[n];const c=o.includes("{sender}")||o.includes("{data}")?"GET":"POST";const u=c==="POST"?{data:e,sender:a}:undefined;try{const r=await fetch(o.replace("{sender}",a).replace("{data}",e),{body:JSON.stringify(u),method:c});let n;if(r.headers.get("Content-Type")?.startsWith("application/json")){n=(await r.json()).data}else{n=await r.text()}if(!r.ok){s=new d({body:u,details:t(n.error)||r.statusText,headers:r.headers,status:r.status,url:o});continue}if(!l(n)){s=new f({result:n,url:o});continue}return n}catch(e){s=new d({body:u,details:e.message,url:o})}}throw s}export{y as ccipFetch,m as offchainLookup,h as offchainLookupAbiItem,w as offchainLookupSignature};
//# sourceMappingURL=p-9fb3b370.js.map