require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`./serialize.utils.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`./getDataFromTransaction.cjs`);let r=require(`idb-keyval`);var i={encryptedOutputs:[],lastOutput:``},a=(e,t)=>({shortPublicKey:e.substring(0,25),shortHinkalAddress:t.substring(0,25)}),o=(e,t,n)=>`hinkalCache-${e}-${t}-${n}`,s=(n,r,s)=>{let{hinkalAddress:c}=t.networkRegistry[r].contractData;if(!r||!s||!c)throw Error(`GetHinkalCache: incorrect arguments`);let{shortPublicKey:l,shortHinkalAddress:u}=a(s,c);return JSON.parse(n.cacheDevice.get(o(r,l,u))??e.safeJsonStringify(i))},c=(n,r,i,s)=>{let{hinkalAddress:c}=t.networkRegistry[i].contractData;if(!i||!s||!c)throw Error(`SetHinkalCache: incorrect arguments`);let{shortPublicKey:l,shortHinkalAddress:u}=a(s,c);r.cacheDevice.set(o(i,l,u),e.safeJsonStringify(n))},l=(e,t,n)=>{c(i,e,t,n)},u=(e,t,n)=>`txsCache-${e}-${t}-${n}`,d=async(t,i,o,s,c,l)=>{if(!i||!o||!s)throw Error(`saveTxsCache: incorrect arguments`);let{shortPublicKey:d,shortHinkalAddress:f}=a(o,s),p=n.serializeDecodedTxs(t),m=u(i,d,f),h=e.safeJsonStringify({serializedTxs:p,lastHash:c});try{await(0,r.set)(m,h)}catch{l.cacheDevice.set(m,h)}},f={serializedTxs:[],lastHash:``},p=async(t,i,o,s)=>{if(!t||!i||!o)throw Error(`loadTxsCache: incorrect arguments`);let{shortPublicKey:c,shortHinkalAddress:l}=a(i,o),d=u(t,c,l),p;try{let e=await(0,r.get)(d);if(!e)throw Error(`Empty indexedDB cache`);p=e}catch{p=s.cacheDevice.get(d)}let{serializedTxs:m,lastHash:h}=JSON.parse(p??e.safeJsonStringify(f));return{decodedTxs:m.map(e=>n.deserializeDecodedTxs(e)),lastHash:h===``?void 0:h}};exports.getFilePath=o,exports.getHinkalCache=s,exports.loadTxsCache=p,exports.resetCache=l,exports.saveTxsCache=d,exports.setHinkalCache=c;