1import{S as v,K as u,V as B,T as S,P as E,C as R}from"./vendor-solana-CBoAGdEU.js";import{k as K,l as p,m as y,g as w}from"./walletOps-Bsob1piw.js";import{j as T,L as x,x as d}from"./index-gQh_1vMV.js";import{getRpcFailoverService as M}from"./rpcFailoverService-QEotN1CO.js";import{a as I}from"./AuthenticatedTerminal-Dx1xTefe.js";import{logger as l,rpcCall as b}from"./rpcClient-uot0GHb8.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};s.SENTRY_RELEASE={id:"b19af26d6b3b2e41c3d08e2ef62b63e2331ea50d"};var e=new s.Error().stack;e&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[e]="f89e3fac-d64c-4192-b5d3-aaf172ccaae6",s._sentryDebugIdIdentifier="sentry-dbid-f89e3fac-d64c-4192-b5d3-aaf172ccaae6")}catch{}})();const c=T({level:x.INFO,context:{service:"blockhashCacheService"}}),W={ttlMs:45e3,refreshThresholdMs:3e4,backgroundRefreshIntervalMs:3e4};class C{constructor(e={}){this.cache=null,this.backgroundRefreshInterval=null,this.isFetching=!1,this.fetchPromise=null,this.config={...W,...e}}async getBlockhash(){return this.cache&&this.isBlockhashValid()?(c.debug("Blockhash cache hit",{blockhash:this.cache.blockhash.slice(0,8),ageMs:Date.now()-this.cache.fetchedAt}),this.cache):this.fetchBlockhash()}async preWarmBlockhash(){if(this.cache&&!this.shouldRefresh()){c.debug("Blockhash pre-warm skipped (cache fresh)",{ageMs:Date.now()-this.cache.fetchedAt});return}try{await this.fetchBlockhash(),c.info("Blockhash pre-warmed",{blockhash:this.cache?.blockhash.slice(0,8)})}catch(e){c.debug("Blockhash pre-warm failed",{error:e instanceof Error?e.message:String(e)})}}isBlockhashValid(){return this.cache?Date.now()<this.cache.expiresAt:!1}shouldRefresh(){return this.cache?Date.now()-this.cache.fetchedAt>=this.config.refreshThresholdMs:!0}startBackgroundRefresh(){this.backgroundRefreshInterval||(this.backgroundRefreshInterval=setInterval(()=>{this.preWarmBlockhash().catch(()=>{})}
1,this.config.backgroundRefreshIntervalMs),c.info("Background blockhash refresh started",{intervalMs:this.config.backgroundRefreshIntervalMs}))}stopBackgroundRefresh(){this.backgroundRefreshInterval&&(clearInterval(this.backgroundRefreshInterval),this.backgroundRefreshInterval=null,c.info("Background blockhash refresh stopped"))}getCacheState(){if(!this.cache)return{cached:!1,valid:!1,shouldRefresh:!0,ageMs:null,ttlRemainingMs:null};const e=Date.now();return{cached:!0,valid:this.isBlockhashValid(),shouldRefresh:this.shouldRefresh(),ageMs:e-this.cache.fetchedAt,ttlRemainingMs:Math.max(0,this.cache.expiresAt-e)}}clearCache(){this.cache=null,c.debug("Blockhash cache cleared")}destroy(){this.stopBackgroundRefresh(),this.clearCache()}async fetchBlockhash(){if(this.isFetching&&this.fetchPromise)return c.debug("Blockhash fetch coalesced (request already in flight)"),this.fetchPromise;this.isFetching=!0,this.fetchPromise=this.doFetchBlockhash();try{return await this.fetchPromise}finally{this.isFetching=!1,this.fetchPromise=null}}async doFetchBlockhash(){const e=M(),n=e.getConnection(),t=e.getProvider()?.name||"UNKNOWN",r=Date.now();try{const{blockhash:a,lastValidBlockHeight:i}=await n.getLatestBlockhash("finalized"),k=Date.now()-r,m=Date.now();return this.cache={blockhash:a,lastValidBlockHeight:i,fetchedAt:m,expiresAt:m+this.config.ttlMs},e.recordSuccess(t,k),c.debug("Blockhash fetched",{blockhash:a.slice(0,8),lastValidBlockHeight:i,latencyMs:k,provider:t}),this.cache}catch(a){if(e.recordFailure(t,a instanceof Error?a.message:String(a)),c.error("Blockhash fetch failed",{provider:t,latencyMs:Date.now()-r,error:a instanceof Error?a.message:String(a)}),this.cache)return c.warn("Using stale blockhash after fetch failure",{ageMs:Date.now()-this.cache.fetchedAt}),this.cache={...this.cache,expiresAt:Date.now()+1e4},this.cache;throw new Error(`Failed to fetch blockhash: ${a instanceof Error?a.message:String(a)}`)}}}let g=null;const f=s=>(g||(g=new C(s)),g),D=()=>f().getBlockhash(),F=()=>f().preWarmBlockhash(),A=()=>{f().startBackgroundRefresh()},P=()=>{f().stopBackgroundRefresh()};let h=null;const N=async s=>b("getTransaction",[s,{encoding:"json",maxSupportedTransactionVersion:0,commitment:"confirmed"}]),L=async s=>{const e=await b("getAccountInfo",[s,{encoding:"base64"}]);return e?e.value:null},V=async(s=!0)=>{await F();try{const e=await D();K({blockhash:e.blockhash,lastValidBlockHeight:e.lastValidBlockHeight,timestamp:e.fetchedAt})}catch(e){l.debug("Failed to sync legacy blockhash cache",{error:e instanceof Error?e.message:String(e)})}},_=()=>
1{A(),l.info("Background blockhash refresh started")},O=()=>{P(),l.info("Background blockhash refresh stopped")},U=async(s,e)=>{const n=w();if(n?.connected&&n?.publicKey?.toBase58()===e.address){const t=await p(s);return l.info("[transaction] Transaction signed by external wallet",{wallet:n?.wallet?.adapter?.name||"unknown",address:e.address.slice(0,8)}),t}else if(e.privateKey!=null||d(e.id)?.privateKey!=null){const t=e.privateKey??d(e.id)?.privateKey;if(!t)throw new Error("No signing key available â vault may be locked");let r=null,a=null;try{return r=y(t),a=u.fromSecretKey(r),s.sign([a]),l.debug("[transaction] Transaction signed with keypair",{address:e.address.slice(0,8)}),s}catch(i){throw new Error(`Failed to sign with private key: ${i instanceof Error?i.message:String(i)}`)}finally{a?.secretKey&&a.secretKey.fill(0),r&&r.fill(0)}}else if(e.type==="REAL"&&!e.privateKey){const t=window.solana;if(!t)throw new Error("Phantom wallet not installed");if(!t?.isConnected)try{await t.connect()}catch(a){throw new Error(`Failed to connect wallet: ${a instanceof Error?a.message:String(a)}`)}const r=await t?.signTransaction(s);if(!r)throw new Error("Failed to sign transaction with Phantom");return r}else throw new Error("No signing method available for wallet")},j=async(s,e)=>{const n=w();if(n?.connected&&n?.publicKey?.toBase58()===e.address){const t=await p(s);return l.info("[transaction] Legacy transaction signed by external wallet",{wallet:n?.wallet?.adapter?.name||"unknown"}),t}else if(e.privateKey!=null||d(e.id)?.privateKey!=null){const t=e.privateKey??d(e.id)?.privateKey;if(!t)throw new Error("No signing key available â vault may be locked");let r=null,a=null;try{return r=y(t),a=u.fromSecretKey(r),s.sign(a),s}catch(i){throw new Error(`Failed to sign legacy transaction: ${i instanceof Error?i.message:String(i)}`)}finally{a?.secretKey&&a.secretKey.fill(0),r&&r.fill(0)}}else if(e.type==="REAL"&&!e.privateKey){const t=window.solana;if(!t?.isConnected)throw new Error("Phantom not connected");return await t.signTransaction(s)}else throw new Error("No signing method available for wallet")},H=(s,e=!1)=>{h&&h.close();const n=I(),o=e?n.warpNodeWss:n.chainstackWss;if(!o||o.trim()===""||!o.startsWith("wss://")&&!o.startsWith("ws://")){l.warn("Solana WebSocket stream skipped â no valid endpoint configured",{endpoint:o,useWarp:e});return}try{h=new WebSocket(o),h.onopen=()=>{l.info("Connected to Solana WebSocket stream",{endpoint:o,useWarp:e});const t={jsonrpc:"2.0",id:1,method:"logsSubscribe",params:[{mentions:["675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"]},{commitment:"processed"}]};h?.send(JSON.stringify(t))},h.onmessage=t=>{try{const r=JSON.parse(t.data);r.method==="logsNotification"&&s({id:crypto.randomUUID(),hash:r.params.result.value.signature,method:"Unknown",value:"0 SOL",time:Date.now(),from:"Log Stream",slot:r.params.result.context.slot})}catch{}}}catch(t){l.error("WebSocket connection failed",{endpoint:o,useWarp:e,error:t instanceof Error?t.message:String(t)})}},$=()=>{h&&(h.close(),h=null)},z=()=>({Connection:R,PublicKey:E,Transaction:S,VersionedTransaction:B,Keypair:u,SystemProgram:v}),Z=Object.freeze(Object.defineProperty({__proto__:null,connectToStream:H,disconnectStream:$,getAccountInfo:L,getTransaction:N,getWeb3:z,preloadBlockhash:V,signLegacyTransaction:j,signVersionedTransaction:U,startBlockhashBackgroundRefresh:_,stopBlockhashBackgroundRefresh:O},Symbol.toStringTag,{value:"Module"}));export{L as a,z as b,H as c,$ as d,U as e,D as f,N as g,V as p,j as s,Z as t};
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.