h_test_1 0.0.45 → 0.0.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- const e=require(`../../../functions/utils/resolve-sync.utils.cjs`);var t=class{blockchainEventEmitter;eventName;constructor(e,t){this.blockchainEventEmitter=e,this.eventName=t,e.addEventProcessorFunction(this.processEventsPage.bind(this))}get latestBlockNumber(){return this.blockchainEventEmitter.latestBlockNumber}get chainId(){return this.blockchainEventEmitter.chainId}intervalClear(){this.blockchainEventEmitter.intervalClear()}async processEventsPage(t){let n=new Set;t.forEach(({eventName:e,transactionHash:t})=>{e===`BlockedUtxosCreated`&&n.add(t)});let r=[];await e.resolveSync(t.map(e=>async()=>{if(e.eventName!==this.eventName)return;console.log(`NEW EVENT`,{event:e});let{blockNumber:t,transactionHash:i}=e,a=this.mapEvent(e),o=n.has(i);await this.acceptEvent(a,t,i,o)&&r.push(a)}));let i=r.length;return await this.afterEventsAccepted(i),r.length}};exports.AbstractEventService=t;
1
+ const e=require(`../../../functions/utils/resolve-sync.utils.cjs`);var t=class{blockchainEventEmitter;eventName;constructor(e,t){this.blockchainEventEmitter=e,this.eventName=t,e.addEventProcessorFunction(this.processEventsPage.bind(this))}get latestBlockNumber(){return this.blockchainEventEmitter.latestBlockNumber}get chainId(){return this.blockchainEventEmitter.chainId}intervalClear(){this.blockchainEventEmitter.intervalClear()}async processEventsPage(t){let n=new Set;t.forEach(({eventName:e,transactionHash:t})=>{e===`BlockedUtxosCreated`&&n.add(t)});let r=[];await e.resolveSync(t.map(e=>async()=>{if(e.eventName!==this.eventName)return;let{blockNumber:t,transactionHash:i}=e,a=this.mapEvent(e),o=n.has(i);await this.acceptEvent(a,t,i,o)&&r.push(a),console.log(`NEW EVENT`,{event:e})}));let i=r.length;return await this.afterEventsAccepted(i),r.length}};exports.AbstractEventService=t;
@@ -23,9 +23,8 @@ var t = class {
23
23
  let r = [];
24
24
  await e(t.map((e) => async () => {
25
25
  if (e.eventName !== this.eventName) return;
26
- console.log("NEW EVENT", { event: e });
27
26
  let { blockNumber: t, transactionHash: i } = e, a = this.mapEvent(e), o = n.has(i);
28
- await this.acceptEvent(a, t, i, o) && r.push(a);
27
+ await this.acceptEvent(a, t, i, o) && r.push(a), console.log("NEW EVENT", { event: e });
29
28
  }));
30
29
  let i = r.length;
31
30
  return await this.afterEventsAccepted(i), r.length;
@@ -1 +1 @@
1
- require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../utils/addresses.cjs`),r=require(`../../../API/scheduled-transactions-calls.cjs`),i=require(`../../../data-structures/utxo/Utxo.cjs`),a=require(`../../utils/upToDateState.cjs`),o=require(`../../utils/cacheFunctions.cjs`),s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxosEnclave.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t,n,r,i,s,c,l,u)=>d.runExclusive(async()=>{u+=1;let d=s.slice(u),{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n),m=[...c,...p];return await a.checkAddressNotUpdated(e,r),o.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,i),await e.utxoUtils.buildBatchProcess(m,t,n)}),p=async(e,t,n,r)=>{let{utxos:i,encryptedOutputs:a,lastOutput:s}=await l.getInputUtxosEnclave(e,n,t);return o.setHinkalCache({encryptedOutputs:a,lastOutput:s},e,n,r),i},m=async(e,t,n,r,i,a,o,s,c)=>{try{return await p(e,t,n,i)}catch{return f(e,t,n,r,i,a,o,s,c)}},h=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},g=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),_=(e,t,n,r,a,o,s)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new i.Utxo({amount:0n,erc20TokenAddress:a,mintAddress:s,shieldedPrivateKey:r,tokenId:o})),n)for(;e.length>6;)e.splice(e.length-1)},v=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:r=void 0,resetCacheBefore:i=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=r??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey();console.log(`getInputUtxoAndBalance 0 start`,{chainId:t,ethereumAddress:l,shieldedPublicKey:u});let{userKeys:d}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);console.log(`getInputUtxoAndBalance 2 hinkalOutputs`,{hinkalOutputs:_,encryptedOutputs:p,nullifiers:h}),i&&o.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=o.getHinkalCache(e,t,u);console.log(`getInputUtxoAndBalance 1 cachedEncryptedOutputs`,{cachedEncryptedOutputs:v,lastOutput:y}),await a.checkAddressNotUpdated(e,l);let b=y!==``,x=_.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1;console.log(`getInputUtxoAndBalance 3 case1`,S,C,b,x);let w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E;console.log(`getInputUtxoAndBalance 4 forceReadFromCache`,w),console.log(`getInputUtxoAndBalance 5 decryptLocally`,T),console.log(`getInputUtxoAndBalance 6 decryptRemotely`,E),console.log(`getInputUtxoAndBalance 7 useCache`,D);let O=[];T?O=await f(e,d,t,l,u,_,v,y,x):E?O=await m(e,d,t,l,u,_,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),console.log({allUtxos:O}),await a.checkAddressNotUpdated(e,l);let k=await g(e,O,h);console.log(`getInputUtxoAndBalance 8 inputUtxos`,k);let A=c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked);return console.log(`getInputUtxoAndBalance 9 filteredInputUtxos`,A),{inputUtxos:A}},y=async({hinkal:t,chainId:i,passedShieldedPublicKey:a=void 0,ethAddress:o=void 0,resetCacheBefore:s=!1,allowRemoteDecryption:c=!1})=>{let l=o??await t.getEthereumAddressByChain(i),d=n.hashEthereumAddress(e.isTronLike(i)?u.addressToHexFormat(l):l),{inputUtxos:f}=await v({hinkal:t,chainId:i,passedShieldedPublicKey:a,ethAddress:l,resetCacheBefore:s,allowRemoteDecryption:c,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await r.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},b=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:a=!0,chainId:o,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,useBlockedUtxos:m=!1})=>{console.log(`getInputUtxoAndBalancePerToken 0 start`,{tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,ensuredTokensWithId:p,useBlockedUtxos:m});let g=l??n.userKeys.getShieldedPrivateKey();console.log(`getInputUtxoAndBalancePerToken 1 useBlockedUtxos`,m);let{inputUtxos:b}=m?await y({hinkal:n,chainId:o,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f}):await v({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f});console.log(`getInputUtxoAndBalancePerToken 2 inputUtxos`,b);let x=h(r);console.log(`getInputUtxoAndBalancePerToken 3 tokensWithId`,x);let S=new Map;b.forEach(e=>{let n=e.getTokenAddress(o);if(x&&!x.some(r=>t.caseInsensitiveEqual(r.erc20TokenAddress,n)&&r.tokenId===e.tokenId))return;let r=s.encodeTokenWithId(o,{erc20TokenAddress:n,tokenId:e.tokenId}),i=S.get(r)??[];S.set(r,[...i,e])}),console.log(`getInputUtxoAndBalancePerToken 4 inputUtxosPerToken`,S),p?.forEach(e=>{let t=s.encodeTokenWithId(o,{erc20TokenAddress:e.erc20TokenAddress,tokenId:e.tokenId});S.set(t,S.get(t)??[])}),console.log(`getInputUtxoAndBalancePerToken 5 ensuredTokensWithId`,p);for(let[t,n]of S){let r=t.split(`-`)[0],s=Number(t.split(`-`)[1]),l=e.isSolanaLike(o),u=l?r:void 0;_(n,i,a,g,l?c.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),s,u)}return console.log(`getInputUtxoAndBalancePerToken 6 inputUtxosPerToken`,S),S};exports.attemptGetInputUtxosRemotely=m,exports.getInputUtxoAndBalance=v,exports.getInputUtxoAndBalanceOfStuckUtxos=y,exports.getInputUtxoAndBalancePerToken=b,exports.getInputUtxosRemotely=p;
1
+ require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../utils/addresses.cjs`),r=require(`../../../API/scheduled-transactions-calls.cjs`),i=require(`../../../data-structures/utxo/Utxo.cjs`),a=require(`../../utils/upToDateState.cjs`),o=require(`../../utils/cacheFunctions.cjs`),s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxosEnclave.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t,n,r,i,s,c,l,u)=>d.runExclusive(async()=>{u+=1;let d=s.slice(u);console.log(`sending list of outputs for batch processing`,{outputsSlice:d,lastOutput:l});let{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n);console.log(`batch process result`,{lastOutputNew:f,additionalEncryptedOutputs:p});let m=[...c,...p];return await a.checkAddressNotUpdated(e,r),o.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,i),await e.utxoUtils.buildBatchProcess(m,t,n)}),p=async(e,t,n,r)=>{let{utxos:i,encryptedOutputs:a,lastOutput:s}=await l.getInputUtxosEnclave(e,n,t);return o.setHinkalCache({encryptedOutputs:a,lastOutput:s},e,n,r),i},m=async(e,t,n,r,i,a,o,s,c)=>{try{return await p(e,t,n,i)}catch{return f(e,t,n,r,i,a,o,s,c)}},h=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},g=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),_=(e,t,n,r,a,o,s)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new i.Utxo({amount:0n,erc20TokenAddress:a,mintAddress:s,shieldedPrivateKey:r,tokenId:o})),n)for(;e.length>6;)e.splice(e.length-1)},v=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:r=void 0,resetCacheBefore:i=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=r??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey();console.log(`getInputUtxoAndBalance 0 start`,{chainId:t,ethereumAddress:l,shieldedPublicKey:u});let{userKeys:d}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);console.log(`getInputUtxoAndBalance 2 hinkalOutputs`,{hinkalOutputs:_,encryptedOutputs:p,nullifiers:h}),i&&o.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=o.getHinkalCache(e,t,u);console.log(`getInputUtxoAndBalance 1 cachedEncryptedOutputs`,{cachedEncryptedOutputs:v,lastOutput:y}),await a.checkAddressNotUpdated(e,l);let b=y!==``,x=_.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1;console.log(`getInputUtxoAndBalance 3 case1`,S,C,b,x);let w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E;console.log(`getInputUtxoAndBalance 4 forceReadFromCache`,w),console.log(`getInputUtxoAndBalance 5 decryptLocally`,T),console.log(`getInputUtxoAndBalance 6 decryptRemotely`,E),console.log(`getInputUtxoAndBalance 7 useCache`,D);let O=[];T?O=await f(e,d,t,l,u,_,v,y,x):E?O=await m(e,d,t,l,u,_,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),console.log({allUtxos:O}),await a.checkAddressNotUpdated(e,l);let k=await g(e,O,h);console.log(`getInputUtxoAndBalance 8 inputUtxos`,k);let A=c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked);return console.log(`getInputUtxoAndBalance 9 filteredInputUtxos`,A),{inputUtxos:A}},y=async({hinkal:t,chainId:i,passedShieldedPublicKey:a=void 0,ethAddress:o=void 0,resetCacheBefore:s=!1,allowRemoteDecryption:c=!1})=>{let l=o??await t.getEthereumAddressByChain(i),d=n.hashEthereumAddress(e.isTronLike(i)?u.addressToHexFormat(l):l),{inputUtxos:f}=await v({hinkal:t,chainId:i,passedShieldedPublicKey:a,ethAddress:l,resetCacheBefore:s,allowRemoteDecryption:c,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await r.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},b=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:a=!0,chainId:o,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,useBlockedUtxos:m=!1})=>{console.log(`getInputUtxoAndBalancePerToken 0 start`,{tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,ensuredTokensWithId:p,useBlockedUtxos:m});let g=l??n.userKeys.getShieldedPrivateKey();console.log(`getInputUtxoAndBalancePerToken 1 useBlockedUtxos`,m);let{inputUtxos:b}=m?await y({hinkal:n,chainId:o,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f}):await v({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f});console.log(`getInputUtxoAndBalancePerToken 2 inputUtxos`,b);let x=h(r);console.log(`getInputUtxoAndBalancePerToken 3 tokensWithId`,x);let S=new Map;b.forEach(e=>{let n=e.getTokenAddress(o);if(x&&!x.some(r=>t.caseInsensitiveEqual(r.erc20TokenAddress,n)&&r.tokenId===e.tokenId))return;let r=s.encodeTokenWithId(o,{erc20TokenAddress:n,tokenId:e.tokenId}),i=S.get(r)??[];S.set(r,[...i,e])}),console.log(`getInputUtxoAndBalancePerToken 4 inputUtxosPerToken`,S),p?.forEach(e=>{let t=s.encodeTokenWithId(o,{erc20TokenAddress:e.erc20TokenAddress,tokenId:e.tokenId});S.set(t,S.get(t)??[])}),console.log(`getInputUtxoAndBalancePerToken 5 ensuredTokensWithId`,p);for(let[t,n]of S){let r=t.split(`-`)[0],s=Number(t.split(`-`)[1]),l=e.isSolanaLike(o),u=l?r:void 0;_(n,i,a,g,l?c.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),s,u)}return console.log(`getInputUtxoAndBalancePerToken 6 inputUtxosPerToken`,S),S};exports.attemptGetInputUtxosRemotely=m,exports.getInputUtxoAndBalance=v,exports.getInputUtxoAndBalanceOfStuckUtxos=y,exports.getInputUtxoAndBalancePerToken=b,exports.getInputUtxosRemotely=p;
@@ -13,7 +13,17 @@ import { Mutex as m } from "async-mutex";
13
13
  //#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
14
14
  var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async () => {
15
15
  u += 1;
16
- let d = a.slice(u), { lastOutput: f, additionalEncryptedOutputs: p } = await e.utxoUtils.batchProcess(d, c, t, n), m = [...s, ...p];
16
+ let d = a.slice(u);
17
+ console.log("sending list of outputs for batch processing", {
18
+ outputsSlice: d,
19
+ lastOutput: c
20
+ });
21
+ let { lastOutput: f, additionalEncryptedOutputs: p } = await e.utxoUtils.batchProcess(d, c, t, n);
22
+ console.log("batch process result", {
23
+ lastOutputNew: f,
24
+ additionalEncryptedOutputs: p
25
+ });
26
+ let m = [...s, ...p];
17
27
  return await o(e, r), l({
18
28
  lastOutput: f,
19
29
  encryptedOutputs: m
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h_test_1",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"