"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[286],{8286:function(t,e,r){r.d(e,{LK:function(){return d},RD:function(){return v},kh:function(){return l}});var o=r(7066),n=r(2790),a=r(9613),c=(r(6966),r(1280)),s=(r(7032),r(8764).lW);const i=c.$.mainnet;function l(t,e,r){const o=new n.vU(r),a=o.getFunction(t);if(!a)throw new Error("Function ABI for ".concat(t," could not be found."));const c="0x"+s.from(e).toString("hex");return o.decodeFunctionResult(a,c)}const u=t=>{const e=t.accountId.shard.low,r=t.accountId.realm.low,o=t.accountId.num.low,n=t.validStart.seconds.low,a=t.validStart.nanos.low;return"".concat(e,".").concat(r,".").concat(o,"-").concat(n,"-").concat(a)},d=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:15,r=0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5e3;for(;r<e;){try{const e=await f(t);if(e)return e}catch(n){console.error("Error retrieving transaction receipt:",n),console.log("Retry attempt ".concat(r+1,", waiting for ").concat(o/1e3," seconds..."))}await new Promise((t=>setTimeout(t,o))),0!==r&&(o=3e3),r++}throw new Error("Max retries reached. Unable to retrieve transaction receipt.")},v=async function(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:15,o=0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5e3;for(;o<r;){try{const r=await p(t,e);if(r)return r}catch(a){console.error("Error retrieving transaction receipt:",a),console.log("Retry attempt ".concat(o+1,", waiting for ").concat(n/1e3," seconds..."))}await new Promise((t=>setTimeout(t,n))),0!==o&&(n=2500),o++}throw new Error("Max retries reached. Unable to retrieve transaction receipt.")},f=async t=>{let e;if("object"===typeof t)e=u(t);else if(/\d+\.\d+\.\d+@\d+\.\d+/.test(t)){const r=t.split("@"),o=r[0],n=r[1].split(".");e="".concat(o,"-").concat(n[0],"-").concat(n[1])}else e=t;const r="".concat(i.mirrorNodeUrl,"/api/v1/transactions/").concat(e);try{var n;const t=await o.Z.get(r);if((null===t||void 0===t?void 0:t.data)&&(null===t||void 0===t||null===(n=t.data)||void 0===n?void 0:n.transactions[0])){const e=t.data.transactions[0];return"SUCCESS"===(null===e||void 0===e?void 0:e.result)?{success:!0,isHex:!1,result:"Transaction executed successfully!",call_result:null===e||void 0===e?void 0:e.name,error:void 0}:{success:!1,isHex:!1,result:null===e||void 0===e?void 0:e.result,call_result:null===e||void 0===e?void 0:e.name,error:null===e||void 0===e?void 0:e.result}}return{success:!1,error:"No result found"}}catch(s){var a,c;if(o.Z.isAxiosError(s)&&(null===s||void 0===s?void 0:s.response)&&(null===s||void 0===s||null===(a=s.response)||void 0===a?void 0:a.status)>=400)throw new Error("Transaction receipt not found 400s error: "+(null===s||void 0===s||null===(c=s.response)||void 0===c?void 0:c.status));return{success:!1,error:"Failed to query the mirror node"}}},p=async(t,e)=>{let r;if("object"===typeof t)r=u(t);else if(/\d+\.\d+\.\d+@\d+\.\d+/.test(t)){const e=t.split("@"),o=e[0],n=e[1].split(".");r="".concat(o,"-").concat(n[0],"-").concat(n[1])}else r=t;const n="".concat(i.mirrorNodeUrl,"/api/v1/contracts/results/").concat(r);try{var a;const t=await o.Z.get(n);if(console.log("Response:",t.data),(null===t||void 0===t?void 0:t.data)&&(null===t||void 0===t||null===(a=t.data)||void 0===a?void 0:a.result)){if("SUCCESS"===t.data.result){const r=e.parseTransaction({data:t.data.function_parameters}),o=null===r||void 0===r?void 0:r.name;let n;return n=o?e.decodeFunctionResult(o,t.data.call_result):t.data.call_result,{success:!0,isHex:!1,result:"Transaction executed successfully!",call_result:n,error:void 0}}var c,s,l,d;return{success:!1,isHex:!1,result:t.data.result,call_result:t.data.call_result||null,error:null!==(d=null!==(l=h(e,null===t||void 0===t||null===(c=t.data)||void 0===c?void 0:c.error_message))&&void 0!==l?l:null===t||void 0===t||null===(s=t.data)||void 0===s?void 0:s.error_message)&&void 0!==d?d:"Unknown error"}}return{success:!1,error:"No result found"}}catch(v){if(o.Z.isAxiosError(v)&&v.response&&v.response.status>=400)throw new Error("Transaction receipt not found (404)");return{success:!1,error:"Failed to query the mirror node"}}};function h(t,e){if(null===e||void 0===e?void 0:e.startsWith("0x08c379a0")){const t="0x".concat(e.substring(10));return"REVERT: ".concat(a.R.defaultAbiCoder().decode(["string"],t))}if(null===e||void 0===e?void 0:e.startsWith("0x4e487b71")){const t="0x".concat(e.substring(10)),r=a.R.defaultAbiCoder().decode(["uint"],t);let o;switch(Number(r[0])){case 0:o="Generic compiler inserted panic";break;case 1:o="Assert with an argument that evaluates to false";break;case 17:o="Arithmetic operation results in underflow or overflow outside of an unchecked { ... } block";break;case 18:o="Divide or modulo by zero (e.g. 5 / 0 or 23 % 0)";break;case 33:o="Convert a value that is too big or negative into an enum type";break;case 34:o="Access a storage byte array that is incorrectly encoded";break;case 49:o="Call .pop() on an empty array";break;case 50:o="Access an array, bytesN or an array slice at an out-of-bounds or negative index (i.e. x[i] where i >= x.length or i < 0)";break;case 65:o="Allocate too much memory or create an array that is too large";break;case 81:o="Call a zero-initialized variable of internal function type";break;default:o="Unknown"}return"Panic code: ".concat(r[0]," : ").concat(o)}try{const n=t.parseError(e);var r,o;return"".concat(null!==(r=null===n||void 0===n?void 0:n.name)&&void 0!==r?r:"Unknown error",": ").concat(null!==(o=null===n||void 0===n?void 0:n.args)&&void 0!==o?o:"Unknown args")}catch(n){console.error(e,n)}return"Unknown error occured"}},7032:function(t,e,r){r.d(e,{Q:function(){return n}});var o=r(6966);class n{addParam(t){return this.params.push(t),this}buildAbiFunctionParams(){return this.params.map((t=>"".concat(t.type," ").concat(t.name))).join(", ")}buildEthersParams(){return this.params.map((t=>t.value.toString()))}buildHAPIParams(){const t=new o.PR;for(const e of this.params){const r=/^[a-zA-Z][a-zA-Z0-9]*$/;if(!e.type.match(r))throw new Error("Invalid type: ".concat(e.type,". Type must only contain alphanumeric characters."));const o=e.type.charAt(0).toUpperCase()+e.type.slice(1),n="add".concat(o);if(!(n in t))throw new Error("Invalid type: ".concat(e.type,". Could not find function ").concat(n," in ContractFunctionParameters class."));t[n](e.value)}return t}constructor(){this.params=[]}}}}]);