@ocap/statedb-fs 1.14.23 → 1.15.0

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.
@@ -1,15 +1,30 @@
1
- /* eslint-disable no-underscore-dangle */
1
+ const { ensureChecksumAddress } = require('@ocap/state/lib/states/account');
2
+ const debug = require('debug')(require('../../package.json').name);
2
3
  const FsTable = require('./base');
3
4
 
4
5
  class AccountTable extends FsTable {
5
6
  async _get(address, { final = true } = {}) {
6
- const current = await this.collection.by(this.uniqIndex, address);
7
+ const current = await this.collection.by(this.uniqIndex, ensureChecksumAddress(address));
7
8
  if (current && final && Array.isArray(current.migratedTo) && current.migratedTo.length) {
8
9
  return this.collection.by(this.uniqIndex, current.migratedTo[0]);
9
10
  }
10
11
 
11
12
  return current;
12
13
  }
14
+
15
+ async _create(key, attrs) {
16
+ const doc = await this._get(key);
17
+ if (doc) {
18
+ throw new Error(`${this.name} already exists: ${key}`);
19
+ }
20
+
21
+ debug(`insert ${this.name}`, attrs);
22
+ const newDoc = { [this.uniqIndex]: key, ...attrs };
23
+ newDoc[this.uniqIndex] = ensureChecksumAddress(newDoc[this.uniqIndex]);
24
+ const result = await this.collection.insert(newDoc);
25
+
26
+ return result;
27
+ }
13
28
  }
14
29
 
15
30
  module.exports = AccountTable;
package/lib/table/base.js CHANGED
@@ -53,7 +53,7 @@ class FsTable extends StateDBTable {
53
53
  }
54
54
 
55
55
  async _update(key, updates) {
56
- const doc = await this._get(key);
56
+ const doc = await this.collection.by(this.uniqIndex, key);
57
57
  if (!doc) {
58
58
  throw new Error(`${this.name} does not exists: ${key}`);
59
59
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocap/statedb-fs",
3
3
  "description": "OCAP statedb adapter that uses fs as backend",
4
- "version": "1.14.23",
4
+ "version": "1.15.0",
5
5
  "author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ArcBlock/asset-chain/issues",
@@ -37,9 +37,10 @@
37
37
  "test": "jest --forceExit --detectOpenHandles",
38
38
  "coverage": "npm run test -- --coverage & exit 0"
39
39
  },
40
- "gitHead": "1ed9c9d99862d035f9a5cc639f411e92ab88f3df",
40
+ "gitHead": "200364b55e5906688e2cad5fa0631735336cc423",
41
41
  "dependencies": {
42
- "@ocap/statedb": "1.14.23",
42
+ "@ocap/state": "1.15.0",
43
+ "@ocap/statedb": "1.15.0",
43
44
  "debug": "^4.3.3",
44
45
  "lodash": "^4.17.21",
45
46
  "lokijs": "^1.5.11"