@ocap/indexdb-elasticsearch 1.21.3 → 1.22.1
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 +50 -0
- package/lib/model/token-factory.js +52 -0
- package/lib/model/token.js +1 -0
- package/lib/model/tx.js +1 -0
- package/lib/table/token-factory.js +49 -0
- package/package.json +5 -5
package/lib/db.js
CHANGED
@@ -19,6 +19,7 @@ const Rollup = require('./table/rollup');
|
|
19
19
|
const RollupBlock = require('./table/rollup-block');
|
20
20
|
const RollupValidator = require('./table/rollup-validator');
|
21
21
|
const TokenDistribution = require('./table/token-distribution');
|
22
|
+
const TokenFactory = require('./table/token-factory');
|
22
23
|
|
23
24
|
const { name, version } = require('../package.json');
|
24
25
|
const { formatQueryResult, getAuthHeaders, getTimeCondition } = require('./util');
|
@@ -94,6 +95,7 @@ class ESIndexDB extends BaseIndexDB {
|
|
94
95
|
this.rollupBlock = new RollupBlock(this);
|
95
96
|
this.rollupValidator = new RollupValidator(this);
|
96
97
|
this.tokenDistribution = new TokenDistribution(this);
|
98
|
+
this.tokenFactory = new TokenFactory(this);
|
97
99
|
|
98
100
|
this.attachReadyListeners();
|
99
101
|
}
|
@@ -112,6 +114,7 @@ class ESIndexDB extends BaseIndexDB {
|
|
112
114
|
rollupFilter = {},
|
113
115
|
stakeFilter = {},
|
114
116
|
delegationFilter = {},
|
117
|
+
tokenFactoryFilter = {},
|
115
118
|
} = {}) {
|
116
119
|
const pagination = formatPagination({ paging, defaultSortField: 'time' });
|
117
120
|
|
@@ -125,6 +128,7 @@ class ESIndexDB extends BaseIndexDB {
|
|
125
128
|
const { rollups = [] } = rollupFilter;
|
126
129
|
const { stakes = [] } = stakeFilter;
|
127
130
|
const { delegations = [] } = delegationFilter;
|
131
|
+
const { tokenFactories = [] } = tokenFactoryFilter;
|
128
132
|
|
129
133
|
// OR is spelled should
|
130
134
|
// AND is spelled must
|
@@ -197,6 +201,10 @@ class ESIndexDB extends BaseIndexDB {
|
|
197
201
|
conditions.push({ terms: { delegations } });
|
198
202
|
}
|
199
203
|
|
204
|
+
if (tokenFactories.length) {
|
205
|
+
conditions.push({ terms: { tokenFactories } });
|
206
|
+
}
|
207
|
+
|
200
208
|
const condition = getTimeCondition(timeFilter, ['time'], 'time');
|
201
209
|
if (condition) {
|
202
210
|
conditions.push(condition);
|
@@ -401,6 +409,48 @@ class ESIndexDB extends BaseIndexDB {
|
|
401
409
|
return { tokens: items.map((x) => Token.formatAfterRead(x)), paging: nextPaging };
|
402
410
|
}
|
403
411
|
|
412
|
+
async listTokenFactories({ owner, reserveAddress, tokenAddress, paging, timeFilter = {} } = {}) {
|
413
|
+
debug('listTokenFactories', { owner, reserveAddress, tokenAddress, paging });
|
414
|
+
|
415
|
+
const conditions = [];
|
416
|
+
|
417
|
+
if (owner) {
|
418
|
+
conditions.push({ term: { owner } });
|
419
|
+
}
|
420
|
+
|
421
|
+
if (reserveAddress) {
|
422
|
+
conditions.push({ term: { reserveAddress } });
|
423
|
+
}
|
424
|
+
|
425
|
+
if (tokenAddress) {
|
426
|
+
conditions.push({ term: { tokenAddress } });
|
427
|
+
}
|
428
|
+
|
429
|
+
const condition = getTimeCondition(timeFilter, ['genesisTime', 'renaissanceTime']);
|
430
|
+
if (condition) {
|
431
|
+
conditions.push(condition);
|
432
|
+
}
|
433
|
+
|
434
|
+
const pagination = formatPagination({
|
435
|
+
paging,
|
436
|
+
defaultSortField: 'renaissanceTime',
|
437
|
+
supportedSortFields: ['genesisTime', 'renaissanceTime', 'reserveBalance', 'currentSupply'],
|
438
|
+
});
|
439
|
+
|
440
|
+
const result = await this.tokenFactory.search({
|
441
|
+
from: pagination.cursor,
|
442
|
+
size: pagination.size,
|
443
|
+
body: {
|
444
|
+
track_total_hits: TRACK_TOTAL_HITS,
|
445
|
+
query: conditions.length ? { bool: { must: conditions } } : FALLBACK_QUERY,
|
446
|
+
sort: [{ [pagination.order.field]: { order: pagination.order.type } }],
|
447
|
+
},
|
448
|
+
});
|
449
|
+
|
450
|
+
const { items, paging: nextPaging } = formatQueryResult(result, pagination);
|
451
|
+
return { tokenFactories: items.map((x) => TokenFactory.formatAfterRead(x)), paging: nextPaging };
|
452
|
+
}
|
453
|
+
|
404
454
|
async listFactories({ ownerAddress, addressList, paging, timeFilter = {} } = {}) {
|
405
455
|
debug('listTokens', { ownerAddress, paging });
|
406
456
|
const pagination = formatPagination({
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module.exports = () => ({
|
2
|
+
mappings: {
|
3
|
+
dynamic: false,
|
4
|
+
properties: {
|
5
|
+
address: { type: 'keyword' },
|
6
|
+
owner: { type: 'keyword' },
|
7
|
+
tokenAddress: { type: 'keyword' },
|
8
|
+
reserveAddress: { type: 'keyword' },
|
9
|
+
curve: {
|
10
|
+
type: 'nested',
|
11
|
+
properties: {
|
12
|
+
type: { type: 'keyword' },
|
13
|
+
basePrice: { type: 'keyword' },
|
14
|
+
fixedPrice: { type: 'keyword' },
|
15
|
+
slope: { type: 'keyword' },
|
16
|
+
constant: { type: 'long' },
|
17
|
+
},
|
18
|
+
},
|
19
|
+
feeRate: { type: 'keyword', index: false },
|
20
|
+
currentSupply: { type: 'keyword' },
|
21
|
+
reserveBalance: { type: 'keyword' },
|
22
|
+
status: { type: 'keyword' },
|
23
|
+
data: { type: 'object', enabled: false },
|
24
|
+
genesisTime: { type: 'date' },
|
25
|
+
renaissanceTime: { type: 'date' },
|
26
|
+
token: {
|
27
|
+
type: 'nested',
|
28
|
+
properties: {
|
29
|
+
address: { type: 'keyword' },
|
30
|
+
symbol: { type: 'keyword' },
|
31
|
+
decimal: { type: 'long' },
|
32
|
+
unit: { type: 'keyword' },
|
33
|
+
},
|
34
|
+
},
|
35
|
+
reserveToken: {
|
36
|
+
type: 'nested',
|
37
|
+
properties: {
|
38
|
+
address: { type: 'keyword' },
|
39
|
+
symbol: { type: 'keyword' },
|
40
|
+
decimal: { type: 'long' },
|
41
|
+
unit: { type: 'keyword' },
|
42
|
+
},
|
43
|
+
},
|
44
|
+
},
|
45
|
+
},
|
46
|
+
settings: {
|
47
|
+
index: {
|
48
|
+
number_of_shards: +(process.env.ES_SHARD_COUNT || 1),
|
49
|
+
number_of_replicas: +(process.env.ES_REPLICA_COUNT || 0),
|
50
|
+
},
|
51
|
+
},
|
52
|
+
});
|
package/lib/model/token.js
CHANGED
@@ -10,6 +10,7 @@ module.exports = () => ({
|
|
10
10
|
icon: { type: 'text', index: false },
|
11
11
|
totalSupply: { type: 'keyword' },
|
12
12
|
initialSupply: { type: 'keyword' },
|
13
|
+
tokenFactoryAddress: { type: 'keyword' },
|
13
14
|
genesisTime: { type: 'date' },
|
14
15
|
renaissanceTime: { type: 'date' },
|
15
16
|
data: { type: 'object', enabled: false },
|
package/lib/model/tx.js
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
const ESIndex = require('./base');
|
2
|
+
const getParams = require('../model/token-factory');
|
3
|
+
const { getTableName } = require('../util');
|
4
|
+
|
5
|
+
class TokenFactory extends ESIndex {
|
6
|
+
constructor(db) {
|
7
|
+
super({
|
8
|
+
name: getTableName(db.config.prefix, 'token_factory'),
|
9
|
+
docId: 'address',
|
10
|
+
client: db.client,
|
11
|
+
http: db.http,
|
12
|
+
indexParams: getParams(),
|
13
|
+
});
|
14
|
+
|
15
|
+
this.tokenLength = db.config.tokenLength;
|
16
|
+
}
|
17
|
+
|
18
|
+
static formatBeforeUpdate(data, tokenLength) {
|
19
|
+
data.currentSupply = super.padBalance(data.currentSupply, tokenLength);
|
20
|
+
data.reserveBalance = super.padBalance(data.reserveBalance, tokenLength);
|
21
|
+
|
22
|
+
return data;
|
23
|
+
}
|
24
|
+
|
25
|
+
static formatAfterRead(data) {
|
26
|
+
if (data) {
|
27
|
+
data.currentSupply = super.trimBalance(data.currentSupply);
|
28
|
+
data.reserveBalance = super.trimBalance(data.reserveBalance);
|
29
|
+
}
|
30
|
+
|
31
|
+
return data;
|
32
|
+
}
|
33
|
+
|
34
|
+
batchInsert(rows) {
|
35
|
+
const formatted = rows.map((x) => TokenFactory.formatBeforeUpdate(x, this.tokenLength));
|
36
|
+
return super.batchInsert(formatted);
|
37
|
+
}
|
38
|
+
|
39
|
+
_insert(row) {
|
40
|
+
return super._insert(TokenFactory.formatBeforeUpdate(row, this.tokenLength));
|
41
|
+
}
|
42
|
+
|
43
|
+
async _get(key) {
|
44
|
+
const item = await super._get(key);
|
45
|
+
return TokenFactory.formatAfterRead(item);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
module.exports = TokenFactory;
|
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.
|
4
|
+
"version": "1.22.1",
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
6
6
|
"bugs": {
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
@@ -16,7 +16,7 @@
|
|
16
16
|
"devDependencies": {
|
17
17
|
"dotenv-flow": "^3.2.0",
|
18
18
|
"jest": "^29.7.0",
|
19
|
-
"@ocap/indexdb-test": "1.
|
19
|
+
"@ocap/indexdb-test": "1.22.1"
|
20
20
|
},
|
21
21
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/indexdb/elasticsearch",
|
22
22
|
"keywords": [
|
@@ -40,9 +40,9 @@
|
|
40
40
|
"bn.js": "^5.2.1",
|
41
41
|
"debug": "^4.3.6",
|
42
42
|
"lodash": "^4.17.21",
|
43
|
-
"@arcblock/did": "1.
|
44
|
-
"@ocap/indexdb": "1.
|
45
|
-
"@ocap/util": "1.
|
43
|
+
"@arcblock/did": "1.22.1",
|
44
|
+
"@ocap/indexdb": "1.22.1",
|
45
|
+
"@ocap/util": "1.22.1"
|
46
46
|
},
|
47
47
|
"scripts": {
|
48
48
|
"lint": "eslint tests lib",
|