@prosopo/provider 0.1.16 → 0.1.18
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/package.json +68 -69
- package/dist/api.d.ts +0 -10
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -136
- package/dist/api.js.map +0 -1
- package/dist/batch/commitments.d.ts +0 -24
- package/dist/batch/commitments.d.ts.map +0 -1
- package/dist/batch/commitments.js +0 -150
- package/dist/batch/commitments.js.map +0 -1
- package/dist/batch/index.d.ts +0 -2
- package/dist/batch/index.d.ts.map +0 -1
- package/dist/batch/index.js +0 -5
- package/dist/batch/index.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- package/dist/scheduler.d.ts +0 -4
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js +0 -34
- package/dist/scheduler.js.map +0 -1
- package/dist/tasks/index.d.ts +0 -2
- package/dist/tasks/index.d.ts.map +0 -1
- package/dist/tasks/index.js +0 -18
- package/dist/tasks/index.js.map +0 -1
- package/dist/tasks/tasks.d.ts +0 -108
- package/dist/tasks/tasks.d.ts.map +0 -1
- package/dist/tasks/tasks.js +0 -405
- package/dist/tasks/tasks.js.map +0 -1
- package/dist/util.d.ts +0 -20
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -92
- package/dist/util.js.map +0 -1
package/dist/util.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateSolutions = exports.calculateNewSolutions = exports.parseBlockNumber = exports.promiseQueue = exports.shuffleArray = exports.encodeStringAddress = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@prosopo/common");
|
|
6
|
-
const common_2 = require("@prosopo/common");
|
|
7
|
-
const keyring_1 = require("@polkadot/keyring");
|
|
8
|
-
const util_1 = require("@polkadot/util");
|
|
9
|
-
const nodejs_polars_1 = tslib_1.__importDefault(require("nodejs-polars"));
|
|
10
|
-
function encodeStringAddress(address) {
|
|
11
|
-
try {
|
|
12
|
-
return (0, keyring_1.encodeAddress)((0, util_1.isHex)(address) ? (0, util_1.hexToU8a)(address) : (0, keyring_1.decodeAddress)(address));
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
throw new common_1.ProsopoEnvError(error, 'CONTRACT.INVALID_ADDRESS', {}, address);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.encodeStringAddress = encodeStringAddress;
|
|
19
|
-
function shuffleArray(array) {
|
|
20
|
-
for (let arrayIndex = array.length - 1; arrayIndex > 0; arrayIndex--) {
|
|
21
|
-
const randIndex = Math.floor(Math.random() * (arrayIndex + 1));
|
|
22
|
-
[array[arrayIndex], array[randIndex]] = [array[randIndex], array[arrayIndex]];
|
|
23
|
-
}
|
|
24
|
-
return array;
|
|
25
|
-
}
|
|
26
|
-
exports.shuffleArray = shuffleArray;
|
|
27
|
-
/**
|
|
28
|
-
* Executes promises in order
|
|
29
|
-
* @param array - array of promises
|
|
30
|
-
* @returns PromiseQueueRes\<T\>
|
|
31
|
-
*/
|
|
32
|
-
async function promiseQueue(array) {
|
|
33
|
-
const ret = [];
|
|
34
|
-
await [...array, () => Promise.resolve(undefined)].reduce((promise, curr, i) => {
|
|
35
|
-
return promise
|
|
36
|
-
.then((res) => {
|
|
37
|
-
// first iteration has no res (initial reduce result)
|
|
38
|
-
if (res) {
|
|
39
|
-
ret.push({ data: res });
|
|
40
|
-
}
|
|
41
|
-
return curr();
|
|
42
|
-
})
|
|
43
|
-
.catch((err) => {
|
|
44
|
-
ret.push({ data: err });
|
|
45
|
-
return curr();
|
|
46
|
-
});
|
|
47
|
-
}, Promise.resolve(undefined));
|
|
48
|
-
return ret;
|
|
49
|
-
}
|
|
50
|
-
exports.promiseQueue = promiseQueue;
|
|
51
|
-
function parseBlockNumber(blockNumberString) {
|
|
52
|
-
return parseInt(blockNumberString.replace(/,/g, ''));
|
|
53
|
-
}
|
|
54
|
-
exports.parseBlockNumber = parseBlockNumber;
|
|
55
|
-
function calculateNewSolutions(solutions, winningNumberOfSolutions) {
|
|
56
|
-
if (solutions.length === 0) {
|
|
57
|
-
return nodejs_polars_1.default.DataFrame([]);
|
|
58
|
-
}
|
|
59
|
-
const solutionsNoEmptyArrays = solutions.map(({ solution, ...otherAttrs }) => {
|
|
60
|
-
return { solutionKey: (0, common_2.arrayJoin)(solution, ','), ...otherAttrs };
|
|
61
|
-
});
|
|
62
|
-
let df = nodejs_polars_1.default.readRecords(solutionsNoEmptyArrays);
|
|
63
|
-
df = df.drop('salt');
|
|
64
|
-
const group = df.groupBy(['captchaId', 'solutionKey']).agg(nodejs_polars_1.default.count('captchaContentId').alias('count'));
|
|
65
|
-
const filtered = group.filter(nodejs_polars_1.default.col('count').gt(winningNumberOfSolutions));
|
|
66
|
-
return filtered.withColumn(filtered['solutionKey'].str.split(',').rename('solution'));
|
|
67
|
-
}
|
|
68
|
-
exports.calculateNewSolutions = calculateNewSolutions;
|
|
69
|
-
function updateSolutions(solutions, captchas, logger) {
|
|
70
|
-
// Note - loading the dataset in nodejs-polars doesn't work because of nested objects, which is why this is done in
|
|
71
|
-
// a map instead of a join
|
|
72
|
-
return captchas.map((captcha) => {
|
|
73
|
-
// try to find the solution in the solutions dataframe
|
|
74
|
-
if (!captcha.solution) {
|
|
75
|
-
try {
|
|
76
|
-
const captchaSolutions = [
|
|
77
|
-
...solutions.filter(nodejs_polars_1.default.col('captchaId').eq(nodejs_polars_1.default.lit(captcha.captchaId)))['solution'].values(),
|
|
78
|
-
];
|
|
79
|
-
if (captchaSolutions.length > 0) {
|
|
80
|
-
captcha.solution = captchaSolutions[0];
|
|
81
|
-
captcha.solved = true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
logger.debug('No solution found for captchaId', captcha.captchaId);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return captcha;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
exports.updateSolutions = updateSolutions;
|
|
92
|
-
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;AAcA,4CAAyD;AACzD,4CAA2C;AAC3C,+CAAgE;AAChE,yCAAgD;AAChD,0EAA8B;AAE9B,SAAgB,mBAAmB,CAAC,OAAe;IAC/C,IAAI;QACA,OAAO,IAAA,uBAAa,EAAC,IAAA,YAAK,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,eAAQ,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,uBAAa,EAAC,OAAO,CAAC,CAAC,CAAA;KACpF;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,IAAI,wBAAe,CAAC,KAAK,EAAE,0BAA0B,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;KAC5E;AACL,CAAC;AAND,kDAMC;AAED,SAAgB,YAAY,CAAI,KAAU;IACtC,KAAK,IAAI,UAAU,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,UAAU,GAAG,CAAC,EAAE,UAAU,EAAE,EAAE;QAClE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAC7D;QAAA,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;KACjF;IACD,OAAO,KAAK,CAAA;AAChB,CAAC;AAND,oCAMC;AAOD;;;;GAIG;AACI,KAAK,UAAU,YAAY,CAAI,KAA2B;IAC7D,MA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