h_test_1 0.0.41 → 0.0.43
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
|
-
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(),{userKeys:d}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);i&&o.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=o.getHinkalCache(e,t,u);await a.checkAddressNotUpdated(e,l);let b=y!==``,x=_.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1,w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E,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)),await a.checkAddressNotUpdated(e,l);let k=await g(e,O,h);
|
|
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;
|
|
@@ -42,14 +42,33 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
|
|
|
42
42
|
tokenId: o
|
|
43
43
|
})), n) for (; e.length > 6;) e.splice(e.length - 1);
|
|
44
44
|
}, S = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: i = !1, allowRemoteDecryption: a = !1, useBlockedUtxos: l = !1 }) => {
|
|
45
|
-
let u = r ?? await e.getEthereumAddress(), d = n ?? e.userKeys.getShieldedPublicKey()
|
|
46
|
-
|
|
45
|
+
let u = r ?? await e.getEthereumAddress(), d = n ?? e.userKeys.getShieldedPublicKey();
|
|
46
|
+
console.log("getInputUtxoAndBalance 0 start", {
|
|
47
|
+
chainId: t,
|
|
48
|
+
ethereumAddress: u,
|
|
49
|
+
shieldedPublicKey: d
|
|
50
|
+
});
|
|
51
|
+
let { userKeys: f } = e, p = e.encryptedOutputsByChain[t], m = e.nullifiersByChain[t], h = Array.from(p);
|
|
52
|
+
console.log("getInputUtxoAndBalance 2 hinkalOutputs", {
|
|
53
|
+
hinkalOutputs: h,
|
|
54
|
+
encryptedOutputs: p,
|
|
55
|
+
nullifiers: m
|
|
56
|
+
}), i && c(e, t, d);
|
|
47
57
|
let { encryptedOutputs: _, lastOutput: y } = s(e, t, d);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
console.log("getInputUtxoAndBalance 1 cachedEncryptedOutputs", {
|
|
59
|
+
cachedEncryptedOutputs: _,
|
|
60
|
+
lastOutput: y
|
|
61
|
+
}), await o(e, u);
|
|
62
|
+
let x = y !== "", S = h.findIndex((e) => e.value === y), C = S > -1, w = !x && S === -1;
|
|
63
|
+
console.log("getInputUtxoAndBalance 3 case1", C, w, x, S);
|
|
64
|
+
let T = e.areMerkleTreeUpdatesDisabled(), E = !T && (C || !a && w), D = !T && a && w, O = !E && !D;
|
|
65
|
+
console.log("getInputUtxoAndBalance 4 forceReadFromCache", T), console.log("getInputUtxoAndBalance 5 decryptLocally", E), console.log("getInputUtxoAndBalance 6 decryptRemotely", D), console.log("getInputUtxoAndBalance 7 useCache", O);
|
|
66
|
+
let k = [];
|
|
67
|
+
E ? k = await g(e, f, t, u, d, h, _, y, S) : D ? k = await v(e, f, t, u, d, h, _, y, S) : O && (k = await e.utxoUtils.buildBatchProcess(_, f, t)), console.log({ allUtxos: k }), await o(e, u);
|
|
51
68
|
let A = await b(e, k, m);
|
|
52
|
-
|
|
69
|
+
console.log("getInputUtxoAndBalance 8 inputUtxos", A);
|
|
70
|
+
let j = l ? A.filter((e) => e.isBlocked) : A.filter((e) => !e.isBlocked);
|
|
71
|
+
return console.log("getInputUtxoAndBalance 9 filteredInputUtxos", j), { inputUtxos: j };
|
|
53
72
|
}, C = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: a = void 0, ethAddress: o = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1 }) => {
|
|
54
73
|
let l = o ?? await e.getEthereumAddressByChain(n), u = r(t(n) ? p(l) : l), { inputUtxos: d } = await S({
|
|
55
74
|
hinkal: e,
|
|
@@ -67,7 +86,21 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
|
|
|
67
86
|
});
|
|
68
87
|
return { inputUtxos: f.map((e) => d[e]).filter((e) => !!e) };
|
|
69
88
|
}, w = async ({ hinkal: t, tokenWithId: r, minInput: i = 2, sliceIfMore6: a = !0, chainId: o, passedShieldedPrivateKey: s = void 0, passedShieldedPublicKey: c = void 0, ethAddress: l = void 0, resetCacheBefore: f = !1, ensuredTokensWithId: p, useBlockedUtxos: m = !1 }) => {
|
|
70
|
-
|
|
89
|
+
console.log("getInputUtxoAndBalancePerToken 0 start", {
|
|
90
|
+
tokenWithId: r,
|
|
91
|
+
minInput: i,
|
|
92
|
+
sliceIfMore6: a,
|
|
93
|
+
chainId: o,
|
|
94
|
+
passedShieldedPrivateKey: s,
|
|
95
|
+
passedShieldedPublicKey: c,
|
|
96
|
+
ethAddress: l,
|
|
97
|
+
resetCacheBefore: f,
|
|
98
|
+
ensuredTokensWithId: p,
|
|
99
|
+
useBlockedUtxos: m
|
|
100
|
+
});
|
|
101
|
+
let h = s ?? t.userKeys.getShieldedPrivateKey();
|
|
102
|
+
console.log("getInputUtxoAndBalancePerToken 1 useBlockedUtxos", m);
|
|
103
|
+
let { inputUtxos: g } = m ? await C({
|
|
71
104
|
hinkal: t,
|
|
72
105
|
chainId: o,
|
|
73
106
|
ethAddress: l,
|
|
@@ -83,7 +116,11 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
|
|
|
83
116
|
passedShieldedPublicKey: c,
|
|
84
117
|
ethAddress: l,
|
|
85
118
|
resetCacheBefore: f
|
|
86
|
-
})
|
|
119
|
+
});
|
|
120
|
+
console.log("getInputUtxoAndBalancePerToken 2 inputUtxos", g);
|
|
121
|
+
let _ = y(r);
|
|
122
|
+
console.log("getInputUtxoAndBalancePerToken 3 tokensWithId", _);
|
|
123
|
+
let v = /* @__PURE__ */ new Map();
|
|
87
124
|
g.forEach((e) => {
|
|
88
125
|
let t = e.getTokenAddress(o);
|
|
89
126
|
if (_ && !_.some((r) => n(r.erc20TokenAddress, t) && r.tokenId === e.tokenId)) return;
|
|
@@ -92,18 +129,18 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
|
|
|
92
129
|
tokenId: e.tokenId
|
|
93
130
|
}), i = v.get(r) ?? [];
|
|
94
131
|
v.set(r, [...i, e]);
|
|
95
|
-
}), p?.forEach((e) => {
|
|
132
|
+
}), console.log("getInputUtxoAndBalancePerToken 4 inputUtxosPerToken", v), p?.forEach((e) => {
|
|
96
133
|
let t = u(o, {
|
|
97
134
|
erc20TokenAddress: e.erc20TokenAddress,
|
|
98
135
|
tokenId: e.tokenId
|
|
99
136
|
});
|
|
100
137
|
v.set(t, v.get(t) ?? []);
|
|
101
|
-
});
|
|
138
|
+
}), console.log("getInputUtxoAndBalancePerToken 5 ensuredTokensWithId", p);
|
|
102
139
|
for (let [t, n] of v) {
|
|
103
140
|
let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), l = c ? r : void 0;
|
|
104
141
|
x(n, i, a, h, c ? d(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, l);
|
|
105
142
|
}
|
|
106
|
-
return v;
|
|
143
|
+
return console.log("getInputUtxoAndBalancePerToken 6 inputUtxosPerToken", v), v;
|
|
107
144
|
};
|
|
108
145
|
//#endregion
|
|
109
146
|
export { v as attemptGetInputUtxosRemotely, S as getInputUtxoAndBalance, C as getInputUtxoAndBalanceOfStuckUtxos, w as getInputUtxoAndBalancePerToken, _ as getInputUtxosRemotely };
|