privacycash 1.0.12 → 1.0.14
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.
- package/dist/getUtxos.js +28 -13
- package/package.json +1 -1
- package/src/getUtxos.ts +28 -13
package/dist/getUtxos.js
CHANGED
|
@@ -32,6 +32,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
32
32
|
getMyUtxosPromise = (async () => {
|
|
33
33
|
let valid_utxos = [];
|
|
34
34
|
let valid_strings = [];
|
|
35
|
+
let history_indexes = [];
|
|
35
36
|
try {
|
|
36
37
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey));
|
|
37
38
|
if (offsetStr) {
|
|
@@ -51,6 +52,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
51
52
|
const nonZeroUtxos = [];
|
|
52
53
|
const nonZeroEncrypted = [];
|
|
53
54
|
for (let [k, utxo] of fetched.utxos.entries()) {
|
|
55
|
+
history_indexes.push(utxo.index);
|
|
54
56
|
if (utxo.amount.toNumber() > 0) {
|
|
55
57
|
nonZeroUtxos.push(utxo);
|
|
56
58
|
nonZeroEncrypted.push(fetched.encryptedOutputs[k]);
|
|
@@ -80,6 +82,21 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
80
82
|
finally {
|
|
81
83
|
getMyUtxosPromise = null;
|
|
82
84
|
}
|
|
85
|
+
// get history index
|
|
86
|
+
let historyKey = 'tradeHistory' + localstorageKey(publicKey);
|
|
87
|
+
let rec = storage.getItem(historyKey);
|
|
88
|
+
let recIndexes = [];
|
|
89
|
+
if (rec?.length) {
|
|
90
|
+
recIndexes = rec.split(',').map(n => Number(n));
|
|
91
|
+
}
|
|
92
|
+
if (recIndexes.length) {
|
|
93
|
+
history_indexes = [...history_indexes, ...recIndexes];
|
|
94
|
+
}
|
|
95
|
+
let unique_history_indexes = Array.from(new Set(history_indexes));
|
|
96
|
+
let top20 = unique_history_indexes.sort((a, b) => b - a).slice(0, 20);
|
|
97
|
+
if (top20.length) {
|
|
98
|
+
storage.setItem(historyKey, top20.join(','));
|
|
99
|
+
}
|
|
83
100
|
// store valid strings
|
|
84
101
|
logger.debug(`valid_strings len before set: ${valid_strings.length}`);
|
|
85
102
|
valid_strings = [...new Set(valid_strings)];
|
|
@@ -148,19 +165,17 @@ async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionS
|
|
|
148
165
|
if (!data.hasMore) {
|
|
149
166
|
if (cachedString) {
|
|
150
167
|
let cachedEncryptedOutputs = JSON.parse(cachedString);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
myEncryptedOutputs.push(dres.encryptedOutput);
|
|
163
|
-
}
|
|
168
|
+
if (decryptionTaskFinished % 100 == 0) {
|
|
169
|
+
logger.info(`(decrypting cached utxo: ${decryptionTaskFinished + 1}/${decryptionTaskTotal}...)`);
|
|
170
|
+
}
|
|
171
|
+
let batchRes = await decrypt_outputs(cachedEncryptedOutputs, encryptionService, utxoKeypair, lightWasm);
|
|
172
|
+
decryptionTaskFinished += cachedEncryptedOutputs.length;
|
|
173
|
+
logger.debug('cachedbatchReslen', batchRes.length, ' source', cachedEncryptedOutputs.length);
|
|
174
|
+
for (let i = 0; i < batchRes.length; i++) {
|
|
175
|
+
let dres = batchRes[i];
|
|
176
|
+
if (dres.status == 'decrypted' && dres.utxo) {
|
|
177
|
+
myUtxos.push(dres.utxo);
|
|
178
|
+
myEncryptedOutputs.push(dres.encryptedOutput);
|
|
164
179
|
}
|
|
165
180
|
}
|
|
166
181
|
}
|
package/package.json
CHANGED
package/src/getUtxos.ts
CHANGED
|
@@ -62,6 +62,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
62
62
|
getMyUtxosPromise = (async () => {
|
|
63
63
|
let valid_utxos: Utxo[] = []
|
|
64
64
|
let valid_strings: string[] = []
|
|
65
|
+
let history_indexes: number[] = []
|
|
65
66
|
try {
|
|
66
67
|
let offsetStr = storage.getItem(LSK_FETCH_OFFSET + localstorageKey(publicKey))
|
|
67
68
|
if (offsetStr) {
|
|
@@ -81,6 +82,7 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
81
82
|
const nonZeroUtxos: Utxo[] = [];
|
|
82
83
|
const nonZeroEncrypted: any[] = [];
|
|
83
84
|
for (let [k, utxo] of fetched.utxos.entries()) {
|
|
85
|
+
history_indexes.push(utxo.index)
|
|
84
86
|
if (utxo.amount.toNumber() > 0) {
|
|
85
87
|
nonZeroUtxos.push(utxo);
|
|
86
88
|
nonZeroEncrypted.push(fetched.encryptedOutputs[k]);
|
|
@@ -108,6 +110,21 @@ export async function getUtxos({ publicKey, connection, encryptionService, stora
|
|
|
108
110
|
} finally {
|
|
109
111
|
getMyUtxosPromise = null
|
|
110
112
|
}
|
|
113
|
+
// get history index
|
|
114
|
+
let historyKey = 'tradeHistory' + localstorageKey(publicKey)
|
|
115
|
+
let rec = storage.getItem(historyKey)
|
|
116
|
+
let recIndexes: number[] = []
|
|
117
|
+
if (rec?.length) {
|
|
118
|
+
recIndexes = rec.split(',').map(n => Number(n))
|
|
119
|
+
}
|
|
120
|
+
if (recIndexes.length) {
|
|
121
|
+
history_indexes = [...history_indexes, ...recIndexes]
|
|
122
|
+
}
|
|
123
|
+
let unique_history_indexes = Array.from(new Set(history_indexes));
|
|
124
|
+
let top20 = unique_history_indexes.sort((a, b) => b - a).slice(0, 20);
|
|
125
|
+
if (top20.length) {
|
|
126
|
+
storage.setItem(historyKey, top20.join(','))
|
|
127
|
+
}
|
|
111
128
|
// store valid strings
|
|
112
129
|
logger.debug(`valid_strings len before set: ${valid_strings.length}`)
|
|
113
130
|
valid_strings = [...new Set(valid_strings)];
|
|
@@ -191,19 +208,17 @@ async function fetchUserUtxos({ publicKey, connection, url, storage, encryptionS
|
|
|
191
208
|
if (!data.hasMore) {
|
|
192
209
|
if (cachedString) {
|
|
193
210
|
let cachedEncryptedOutputs = JSON.parse(cachedString)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
myEncryptedOutputs.push(dres.encryptedOutput!)
|
|
206
|
-
}
|
|
211
|
+
if (decryptionTaskFinished % 100 == 0) {
|
|
212
|
+
logger.info(`(decrypting cached utxo: ${decryptionTaskFinished + 1}/${decryptionTaskTotal}...)`)
|
|
213
|
+
}
|
|
214
|
+
let batchRes = await decrypt_outputs(cachedEncryptedOutputs, encryptionService, utxoKeypair, lightWasm)
|
|
215
|
+
decryptionTaskFinished += cachedEncryptedOutputs.length
|
|
216
|
+
logger.debug('cachedbatchReslen', batchRes.length, ' source', cachedEncryptedOutputs.length)
|
|
217
|
+
for (let i = 0; i < batchRes.length; i++) {
|
|
218
|
+
let dres = batchRes[i]
|
|
219
|
+
if (dres.status == 'decrypted' && dres.utxo) {
|
|
220
|
+
myUtxos.push(dres.utxo)
|
|
221
|
+
myEncryptedOutputs.push(dres.encryptedOutput!)
|
|
207
222
|
}
|
|
208
223
|
}
|
|
209
224
|
}
|