@ocap/indexdb-elasticsearch 1.13.16 → 1.13.20
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/lib/db.js +48 -6
- package/lib/model/rollup-validator.js +35 -0
- package/lib/model/rollup.js +1 -1
- package/lib/table/rollup-validator.js +58 -0
- package/lib/table/rollup.js +1 -1
- package/package.json +4 -4
package/lib/db.js
CHANGED
|
@@ -17,6 +17,7 @@ const Token = require('./table/token');
|
|
|
17
17
|
const Stake = require('./table/stake');
|
|
18
18
|
const Rollup = require('./table/rollup');
|
|
19
19
|
const RollupBlock = require('./table/rollup-block');
|
|
20
|
+
const RollupValidator = require('./table/rollup-validator');
|
|
20
21
|
|
|
21
22
|
const { name, version } = require('../package.json');
|
|
22
23
|
const { formatQueryResult, getAuthHeaders } = require('./util');
|
|
@@ -82,6 +83,7 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
82
83
|
this.stake = new Stake(this);
|
|
83
84
|
this.rollup = new Rollup(this);
|
|
84
85
|
this.rollupBlock = new RollupBlock(this);
|
|
86
|
+
this.rollupValidator = new RollupValidator(this);
|
|
85
87
|
|
|
86
88
|
this.attachReadyListeners();
|
|
87
89
|
}
|
|
@@ -272,7 +274,13 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
272
274
|
}
|
|
273
275
|
|
|
274
276
|
async listTopAccounts({ tokenAddress, paging } = {}) {
|
|
275
|
-
const
|
|
277
|
+
const filter = { term: { 'tokens.address': tokenAddress } };
|
|
278
|
+
const pagination = formatPagination({
|
|
279
|
+
paging,
|
|
280
|
+
defaultSortField: 'balance',
|
|
281
|
+
supportedSortFields: ['genesisTime', 'renaissanceTime', 'balance'],
|
|
282
|
+
});
|
|
283
|
+
|
|
276
284
|
let sort = null;
|
|
277
285
|
if (pagination.order.field === 'balance') {
|
|
278
286
|
sort = [
|
|
@@ -282,9 +290,7 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
282
290
|
order: pagination.order.type,
|
|
283
291
|
nested: {
|
|
284
292
|
path: 'tokens',
|
|
285
|
-
filter
|
|
286
|
-
term: { 'tokens.address': tokenAddress },
|
|
287
|
-
},
|
|
293
|
+
filter,
|
|
288
294
|
},
|
|
289
295
|
},
|
|
290
296
|
},
|
|
@@ -304,7 +310,15 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
304
310
|
const result = await this.account.search({
|
|
305
311
|
from: pagination.cursor,
|
|
306
312
|
size: pagination.size,
|
|
307
|
-
body: {
|
|
313
|
+
body: {
|
|
314
|
+
query: {
|
|
315
|
+
nested: {
|
|
316
|
+
path: 'tokens',
|
|
317
|
+
query: { bool: { filter } },
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
sort,
|
|
321
|
+
},
|
|
308
322
|
});
|
|
309
323
|
|
|
310
324
|
const { items, paging: nextPaging } = formatQueryResult(result, pagination);
|
|
@@ -455,7 +469,7 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
455
469
|
conditions.push({ term: { tokenAddress } });
|
|
456
470
|
}
|
|
457
471
|
if (erc20TokenAddress) {
|
|
458
|
-
conditions.push({
|
|
472
|
+
conditions.push({ match: { erc20TokenAddress } });
|
|
459
473
|
}
|
|
460
474
|
|
|
461
475
|
debug('listRollups', { paging, pagination, conditions });
|
|
@@ -544,6 +558,34 @@ class ESIndexDB extends BaseIndexDB {
|
|
|
544
558
|
const { items, paging: nextPaging } = formatQueryResult(result, pagination);
|
|
545
559
|
return { blocks: items, paging: nextPaging };
|
|
546
560
|
}
|
|
561
|
+
|
|
562
|
+
async listRollupValidators({ paging = {}, rollupAddress = '' } = {}) {
|
|
563
|
+
const pagination = formatPagination({
|
|
564
|
+
paging,
|
|
565
|
+
defaultSortField: 'genesisTime',
|
|
566
|
+
supportedSortFields: ['joinTime', 'leaveTime', 'genesisTime', 'renaissanceTime'],
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
const conditions = [];
|
|
570
|
+
|
|
571
|
+
if (rollupAddress) {
|
|
572
|
+
conditions.push({ term: { rollup: rollupAddress } });
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
debug('listRollupValidators query conditions', conditions);
|
|
576
|
+
|
|
577
|
+
const result = await this.rollupValidator.search({
|
|
578
|
+
from: pagination.cursor,
|
|
579
|
+
size: pagination.size,
|
|
580
|
+
body: {
|
|
581
|
+
query: conditions.length ? { bool: { must: conditions } } : FALLBACK_QUERY,
|
|
582
|
+
sort: [{ [pagination.order.field]: { order: pagination.order.type } }],
|
|
583
|
+
},
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
const { items, paging: nextPaging } = formatQueryResult(result, pagination);
|
|
587
|
+
return { validators: items.map((x) => RollupValidator.formatAfterRead(x)), paging: nextPaging };
|
|
588
|
+
}
|
|
547
589
|
}
|
|
548
590
|
|
|
549
591
|
module.exports = ESIndexDB;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module.exports = () => ({
|
|
2
|
+
mappings: {
|
|
3
|
+
dynamic: false,
|
|
4
|
+
properties: {
|
|
5
|
+
pk: { type: 'text', index: false },
|
|
6
|
+
address: { type: 'keyword' },
|
|
7
|
+
moniker: { type: 'text' },
|
|
8
|
+
endpoint: { type: 'text' },
|
|
9
|
+
|
|
10
|
+
joinTime: { type: 'date' },
|
|
11
|
+
leaveTime: { type: 'date' },
|
|
12
|
+
genesisTime: { type: 'date' },
|
|
13
|
+
renaissanceTime: { type: 'date' },
|
|
14
|
+
|
|
15
|
+
totalStake: { type: 'keyword' },
|
|
16
|
+
availableStake: { type: 'keyword' },
|
|
17
|
+
|
|
18
|
+
totalGain: { type: 'keyword' },
|
|
19
|
+
|
|
20
|
+
proposedBlockCount: { type: 'integer' },
|
|
21
|
+
verifiedBlockCount: { type: 'integer' },
|
|
22
|
+
|
|
23
|
+
latestBlockHeight: { type: 'integer' },
|
|
24
|
+
latestBlockHash: { type: 'keyword' },
|
|
25
|
+
|
|
26
|
+
rollup: { type: 'keyword' },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
settings: {
|
|
30
|
+
index: {
|
|
31
|
+
number_of_shards: 1,
|
|
32
|
+
number_of_replicas: 0,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
package/lib/model/rollup.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const ESIndex = require('./base');
|
|
2
|
+
const getParams = require('../model/rollup-validator');
|
|
3
|
+
const { getTableName } = require('../util');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_TIME = '2000-01-01T00:00:00.000Z';
|
|
6
|
+
|
|
7
|
+
class RollupValidator extends ESIndex {
|
|
8
|
+
constructor(db) {
|
|
9
|
+
super({
|
|
10
|
+
name: getTableName(db.config.prefix, 'rollup_validator'),
|
|
11
|
+
docId: 'address',
|
|
12
|
+
client: db.client,
|
|
13
|
+
http: db.http,
|
|
14
|
+
indexParams: getParams(),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static formatBeforeUpdate(data, tokenLength) {
|
|
19
|
+
data.totalStake = super.padBalance(data.totalStake, tokenLength);
|
|
20
|
+
data.availableStake = super.padBalance(data.availableStake, tokenLength);
|
|
21
|
+
data.totalGain = super.padBalance(data.totalGain, tokenLength);
|
|
22
|
+
data.joinTime = data.joinTime || DEFAULT_TIME;
|
|
23
|
+
data.leaveTime = data.leaveTime || DEFAULT_TIME;
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static formatAfterRead(data) {
|
|
29
|
+
if (data) {
|
|
30
|
+
data.totalStake = super.trimBalance(data.totalStake);
|
|
31
|
+
data.availableStake = super.trimBalance(data.availableStake);
|
|
32
|
+
data.totalGain = super.trimBalance(data.totalGain);
|
|
33
|
+
data.joinTime = data.joinTime === DEFAULT_TIME ? '' : data.joinTime;
|
|
34
|
+
data.leaveTime = data.leaveTime === DEFAULT_TIME ? '' : data.leaveTime;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
batchInsert(rows) {
|
|
41
|
+
const formatted = rows.map((x) => RollupValidator.formatBeforeUpdate(x, this.tokenLength));
|
|
42
|
+
return super.batchInsert(formatted);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_insert(row) {
|
|
46
|
+
return super._insert(RollupValidator.formatBeforeUpdate(row, this.tokenLength));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
_get(key) {
|
|
50
|
+
return super._get(key).then((doc) => RollupValidator.formatAfterRead(doc));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_update(key, updates) {
|
|
54
|
+
return super._update(key, RollupValidator.formatBeforeUpdate(updates));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = RollupValidator;
|
package/lib/table/rollup.js
CHANGED
|
@@ -5,7 +5,7 @@ const { getTableName } = require('../util');
|
|
|
5
5
|
class Rollup extends ESIndex {
|
|
6
6
|
constructor(db) {
|
|
7
7
|
super({
|
|
8
|
-
name: getTableName(db.config.prefix, '
|
|
8
|
+
name: getTableName(db.config.prefix, 'rollup_v2'),
|
|
9
9
|
docId: 'address',
|
|
10
10
|
client: db.client,
|
|
11
11
|
http: db.http,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/indexdb-elasticsearch",
|
|
3
3
|
"description": "OCAP indexdb adapter that uses elasticsearch as backend",
|
|
4
|
-
"version": "1.13.
|
|
4
|
+
"version": "1.13.20",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/asset-chain/issues",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"test": "node tools/jest.js",
|
|
39
39
|
"coverage": "npm run test -- --coverage"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "fbb1920c30088668db5d015d695fb01416ecefc7",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@elastic/elasticsearch": "^7.10.0",
|
|
44
|
-
"@ocap/indexdb": "1.13.
|
|
45
|
-
"@ocap/util": "1.13.
|
|
44
|
+
"@ocap/indexdb": "1.13.20",
|
|
45
|
+
"@ocap/util": "1.13.20",
|
|
46
46
|
"axios": "^0.21.4",
|
|
47
47
|
"bn.js": "^5.2.0",
|
|
48
48
|
"debug": "^4.3.2",
|