@ocap/statedb-memory 1.28.6 → 1.28.8
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/README.md +1 -1
- package/lib/db.js +32 -12
- package/lib/table/balance.js +0 -1
- package/lib/table/base.js +6 -5
- package/lib/table/rollup.js +0 -1
- package/lib/table/token.js +0 -1
- package/package.json +13 -15
package/README.md
CHANGED
package/lib/db.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { StateDB } = require('@ocap/statedb');
|
|
2
|
+
const Lokijs = require('lokijs');
|
|
2
3
|
const Table = require('./table/base');
|
|
3
4
|
const Account = require('./table/account');
|
|
4
5
|
const Token = require('./table/token');
|
|
@@ -7,6 +8,8 @@ const Balance = require('./table/balance');
|
|
|
7
8
|
|
|
8
9
|
const { name, version } = require('../package.json');
|
|
9
10
|
|
|
11
|
+
let instanceCounter = 0;
|
|
12
|
+
|
|
10
13
|
class MemoryStateDB extends StateDB {
|
|
11
14
|
constructor() {
|
|
12
15
|
super();
|
|
@@ -14,24 +17,41 @@ class MemoryStateDB extends StateDB {
|
|
|
14
17
|
this.name = name;
|
|
15
18
|
this.version = version;
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
// Each instance has its own LokiJS database to ensure test isolation
|
|
21
|
+
instanceCounter += 1;
|
|
22
|
+
this.db = new Lokijs(`ocap-memory-statedb-${instanceCounter}.db`);
|
|
23
|
+
|
|
24
|
+
this.balance = new Balance({ name: 'balance', uniqIndex: ['address', 'tokenAddress'], db: this.db });
|
|
18
25
|
this.account = new Account({
|
|
19
26
|
name: 'account',
|
|
20
27
|
uniqIndex: 'address',
|
|
21
28
|
balanceTable: this.balance,
|
|
22
29
|
syncBalance: true,
|
|
30
|
+
db: this.db,
|
|
31
|
+
});
|
|
32
|
+
this.factory = new Table({
|
|
33
|
+
name: 'factory',
|
|
34
|
+
uniqIndex: 'address',
|
|
35
|
+
syncBalance: true,
|
|
36
|
+
balanceTable: this.balance,
|
|
37
|
+
db: this.db,
|
|
38
|
+
});
|
|
39
|
+
this.stake = new Table({
|
|
40
|
+
name: 'stake',
|
|
41
|
+
uniqIndex: 'address',
|
|
42
|
+
syncBalance: true,
|
|
43
|
+
balanceTable: this.balance,
|
|
44
|
+
db: this.db,
|
|
23
45
|
});
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.evidence = new Table({ name: 'evidence', uniqIndex: 'hash' });
|
|
34
|
-
this.tokenFactory = new Table({ name: 'tokenFactory', uniqIndex: 'address' });
|
|
46
|
+
this.asset = new Table({ name: 'asset', uniqIndex: 'address', db: this.db });
|
|
47
|
+
this.delegation = new Table({ name: 'delegation', uniqIndex: 'address', db: this.db });
|
|
48
|
+
this.tx = new Table({ name: 'tx', uniqIndex: 'hash', db: this.db });
|
|
49
|
+
this.token = new Token({ name: 'token', uniqIndex: 'address', db: this.db });
|
|
50
|
+
this.chain = new Table({ name: 'chain', uniqIndex: 'address', db: this.db });
|
|
51
|
+
this.rollup = new Rollup({ name: 'rollup', uniqIndex: 'address', db: this.db });
|
|
52
|
+
this.rollupBlock = new Table({ name: 'rollupBlock', uniqIndex: 'hash', db: this.db });
|
|
53
|
+
this.evidence = new Table({ name: 'evidence', uniqIndex: 'hash', db: this.db });
|
|
54
|
+
this.tokenFactory = new Table({ name: 'tokenFactory', uniqIndex: 'address', db: this.db });
|
|
35
55
|
|
|
36
56
|
this.attachReadyListeners();
|
|
37
57
|
}
|
package/lib/table/balance.js
CHANGED
|
@@ -20,7 +20,6 @@ class BalanceTable extends MemoryStateDB {
|
|
|
20
20
|
)
|
|
21
21
|
.filter((token) => tokenBalances[token] !== tokens[token]);
|
|
22
22
|
|
|
23
|
-
// eslint-disable-next-line array-callback-return
|
|
24
23
|
await Promise.all(
|
|
25
24
|
updatedTokens.map(async (token) => {
|
|
26
25
|
const key = { address, tokenAddress: token };
|
package/lib/table/base.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
1
|
const { StateDBTable } = require('@ocap/statedb');
|
|
3
2
|
const omit = require('lodash/omit');
|
|
4
|
-
const Lokijs = require('lokijs');
|
|
5
|
-
|
|
6
|
-
const db = new Lokijs('ocap-memory-statedb.db');
|
|
7
3
|
|
|
8
4
|
const debug = require('debug')(require('../../package.json').name);
|
|
9
5
|
|
|
@@ -14,8 +10,9 @@ class MemoryTable extends StateDBTable {
|
|
|
14
10
|
* @param {string|string[]} param.uniqIndex primary keys
|
|
15
11
|
* @param {boolean} param.syncBalance sync balance table when create / update / get
|
|
16
12
|
* @param {BalanceTable} param.balanceTable balance table
|
|
13
|
+
* @param {import('lokijs')} param.db LokiJS database instance
|
|
17
14
|
*/
|
|
18
|
-
constructor({ name, uniqIndex, balanceTable, syncBalance = false }) {
|
|
15
|
+
constructor({ name, uniqIndex, balanceTable, syncBalance = false, db }) {
|
|
19
16
|
super(uniqIndex);
|
|
20
17
|
|
|
21
18
|
this.name = name;
|
|
@@ -27,6 +24,10 @@ class MemoryTable extends StateDBTable {
|
|
|
27
24
|
throw new Error('balanceTable is required when syncBalance is true');
|
|
28
25
|
}
|
|
29
26
|
|
|
27
|
+
if (!db) {
|
|
28
|
+
throw new Error('db is required for MemoryTable');
|
|
29
|
+
}
|
|
30
|
+
|
|
30
31
|
this.collection = db.addCollection(name, { unique: [this.primaryKey], clone: true });
|
|
31
32
|
this.markReady();
|
|
32
33
|
}
|
package/lib/table/rollup.js
CHANGED
package/lib/table/token.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/statedb-memory",
|
|
3
3
|
"description": "OCAP statedb adapter that uses memory as backend statedb, just for test purpose",
|
|
4
|
-
"version": "1.28.
|
|
4
|
+
"version": "1.28.8",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
"contributors": [
|
|
14
14
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
15
15
|
],
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"jest": "^29.7.0"
|
|
18
|
-
},
|
|
16
|
+
"devDependencies": {},
|
|
19
17
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/statedb/memory",
|
|
20
18
|
"keywords": [
|
|
21
19
|
"ocap",
|
|
@@ -31,19 +29,19 @@
|
|
|
31
29
|
"type": "git",
|
|
32
30
|
"url": "https://github.com/ArcBlock/blockchain/tree/master/statedb/memory"
|
|
33
31
|
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"lint": "biome check",
|
|
34
|
+
"lint:fix": "biome check --write",
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"coverage": "npm run test -- --coverage"
|
|
37
|
+
},
|
|
34
38
|
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e",
|
|
35
39
|
"dependencies": {
|
|
40
|
+
"@ocap/state": "1.28.8",
|
|
41
|
+
"@ocap/statedb": "1.28.8",
|
|
42
|
+
"@ocap/util": "1.28.8",
|
|
36
43
|
"debug": "^4.3.6",
|
|
37
44
|
"lodash": "^4.17.21",
|
|
38
|
-
"lokijs": "^1.5.12"
|
|
39
|
-
"@ocap/state": "1.28.6",
|
|
40
|
-
"@ocap/statedb": "1.28.6",
|
|
41
|
-
"@ocap/util": "1.28.6"
|
|
42
|
-
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"lint": "eslint tests lib",
|
|
45
|
-
"lint:fix": "eslint --fix tests lib",
|
|
46
|
-
"test": "jest --forceExit --detectOpenHandles",
|
|
47
|
-
"coverage": "npm run test -- --coverage"
|
|
45
|
+
"lokijs": "^1.5.12"
|
|
48
46
|
}
|
|
49
|
-
}
|
|
47
|
+
}
|