@ocap/statedb-memory 1.29.3 → 1.29.5
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/esm/db.d.mts +8 -0
- package/esm/db.mjs +10 -0
- package/esm/package.mjs +4 -1
- package/esm/table/account.d.mts +1 -0
- package/esm/table/account.mjs +18 -5
- package/lib/db.cjs +10 -0
- package/lib/db.d.cts +10 -2
- package/lib/package.cjs +4 -1
- package/lib/table/account.cjs +18 -5
- package/lib/table/account.d.cts +1 -0
- package/lib/table/base.d.cts +2 -2
- package/package.json +6 -5
package/esm/db.d.mts
CHANGED
|
@@ -26,6 +26,14 @@ declare class MemoryStateDB extends StateDB {
|
|
|
26
26
|
evidence: IStateTable<IEvidenceState>;
|
|
27
27
|
tokenFactory: IStateTable<ITokenFactoryState>;
|
|
28
28
|
constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Execute function - Memory adapter has no real transaction support
|
|
31
|
+
* This is a no-op wrapper that simply executes the callback
|
|
32
|
+
*
|
|
33
|
+
* @param fn - Function to execute (txn parameter will be null)
|
|
34
|
+
* @returns Result of the function
|
|
35
|
+
*/
|
|
36
|
+
runAsLambda<T>(fn: (txn: null) => T | Promise<T>): Promise<T>;
|
|
29
37
|
}
|
|
30
38
|
//#endregion
|
|
31
39
|
export { MemoryStateDB as default };
|
package/esm/db.mjs
CHANGED
|
@@ -94,6 +94,16 @@ var MemoryStateDB = class extends StateDB {
|
|
|
94
94
|
});
|
|
95
95
|
this.attachReadyListeners();
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Execute function - Memory adapter has no real transaction support
|
|
99
|
+
* This is a no-op wrapper that simply executes the callback
|
|
100
|
+
*
|
|
101
|
+
* @param fn - Function to execute (txn parameter will be null)
|
|
102
|
+
* @returns Result of the function
|
|
103
|
+
*/
|
|
104
|
+
async runAsLambda(fn) {
|
|
105
|
+
return fn(null);
|
|
106
|
+
}
|
|
97
107
|
};
|
|
98
108
|
var db_default = MemoryStateDB;
|
|
99
109
|
|
package/esm/package.mjs
CHANGED
|
@@ -11,7 +11,10 @@ var package_default = {
|
|
|
11
11
|
},
|
|
12
12
|
publishConfig: { "access": "public" },
|
|
13
13
|
contributors: ["wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"],
|
|
14
|
-
devDependencies: {
|
|
14
|
+
devDependencies: {
|
|
15
|
+
"@ocap/statedb-test": "workspace:*",
|
|
16
|
+
"@types/lokijs": "^1.5.14"
|
|
17
|
+
},
|
|
15
18
|
homepage: "https://github.com/ArcBlock/blockchain/tree/master/statedb/memory",
|
|
16
19
|
keywords: [
|
|
17
20
|
"ocap",
|
package/esm/table/account.d.mts
CHANGED
|
@@ -12,6 +12,7 @@ interface AccountOperationContext extends IOperationContext {
|
|
|
12
12
|
declare class AccountStateDB extends MemoryTable<IAccountState> {
|
|
13
13
|
_get(address: string, context?: AccountOperationContext): Promise<IAccountState | null>;
|
|
14
14
|
_create(key: string, attrs?: Partial<IAccountState>, context?: IOperationContext): Promise<IAccountState>;
|
|
15
|
+
_update(key: string, updates: Partial<IAccountState>, context?: IOperationContext): Promise<IAccountState>;
|
|
15
16
|
}
|
|
16
17
|
//#endregion
|
|
17
18
|
export { AccountStateDB as default };
|
package/esm/table/account.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import base_default from "./base.mjs";
|
|
2
|
+
import { followMigrationChain, wouldCreateMigrationCycle } from "@ocap/statedb";
|
|
2
3
|
import { ensureChecksumAddress } from "@ocap/state/lib/states/account";
|
|
3
4
|
|
|
4
5
|
//#region src/table/account.ts
|
|
@@ -8,18 +9,30 @@ import { ensureChecksumAddress } from "@ocap/state/lib/states/account";
|
|
|
8
9
|
*/
|
|
9
10
|
var AccountStateDB = class extends base_default {
|
|
10
11
|
async _get(address, context = {}) {
|
|
11
|
-
const { traceMigration = true
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
12
|
+
const { traceMigration = true } = context;
|
|
13
|
+
const normalizedAddress = ensureChecksumAddress(address);
|
|
14
|
+
if (!traceMigration) return super._get(normalizedAddress, context);
|
|
15
|
+
return followMigrationChain(normalizedAddress, (addr) => super._get(addr, context), ensureChecksumAddress);
|
|
15
16
|
}
|
|
16
|
-
_create(key, attrs = {}, context) {
|
|
17
|
+
async _create(key, attrs = {}, context) {
|
|
17
18
|
const address = ensureChecksumAddress(key);
|
|
19
|
+
const { migratedTo } = attrs;
|
|
20
|
+
if (migratedTo?.length) {
|
|
21
|
+
if (await wouldCreateMigrationCycle(address, migratedTo, (addr) => super._get(addr, context), ensureChecksumAddress)) throw new Error(`Circular migration detected: ${address} -> ${migratedTo.join(", ")}`);
|
|
22
|
+
}
|
|
18
23
|
return super._create(address, {
|
|
19
24
|
...attrs,
|
|
20
25
|
[this.uniqIndex]: address
|
|
21
26
|
}, context);
|
|
22
27
|
}
|
|
28
|
+
async _update(key, updates, context) {
|
|
29
|
+
const address = ensureChecksumAddress(key);
|
|
30
|
+
const { migratedTo } = updates;
|
|
31
|
+
if (migratedTo?.length) {
|
|
32
|
+
if (await wouldCreateMigrationCycle(address, migratedTo, (addr) => super._get(addr, context), ensureChecksumAddress)) throw new Error(`Circular migration detected: ${address} -> ${migratedTo.join(", ")}`);
|
|
33
|
+
}
|
|
34
|
+
return super._update(address, updates, context);
|
|
35
|
+
}
|
|
23
36
|
};
|
|
24
37
|
var account_default = AccountStateDB;
|
|
25
38
|
|
package/lib/db.cjs
CHANGED
|
@@ -97,6 +97,16 @@ var MemoryStateDB = class extends _ocap_statedb.StateDB {
|
|
|
97
97
|
});
|
|
98
98
|
this.attachReadyListeners();
|
|
99
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Execute function - Memory adapter has no real transaction support
|
|
102
|
+
* This is a no-op wrapper that simply executes the callback
|
|
103
|
+
*
|
|
104
|
+
* @param fn - Function to execute (txn parameter will be null)
|
|
105
|
+
* @returns Result of the function
|
|
106
|
+
*/
|
|
107
|
+
async runAsLambda(fn) {
|
|
108
|
+
return fn(null);
|
|
109
|
+
}
|
|
100
110
|
};
|
|
101
111
|
var db_default = MemoryStateDB;
|
|
102
112
|
|
package/lib/db.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StateDB } from "@ocap/statedb";
|
|
2
2
|
import { IAccountState, IAssetFactoryState, IAssetState, IBalanceTable, IChainState, IDelegateState, IEvidenceState, IRollupBlock, IRollupTable, IStakeState, IStateTable, ITokenFactoryState, ITokenTable, ITxState } from "@ocap/types";
|
|
3
|
-
import
|
|
3
|
+
import Lokijs from "lokijs";
|
|
4
4
|
|
|
5
5
|
//#region src/db.d.ts
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ import Loki from "lokijs";
|
|
|
11
11
|
declare class MemoryStateDB extends StateDB {
|
|
12
12
|
name: string;
|
|
13
13
|
version: string;
|
|
14
|
-
db:
|
|
14
|
+
db: Lokijs;
|
|
15
15
|
balance: IBalanceTable;
|
|
16
16
|
account: IStateTable<IAccountState>;
|
|
17
17
|
factory: IStateTable<IAssetFactoryState>;
|
|
@@ -26,6 +26,14 @@ declare class MemoryStateDB extends StateDB {
|
|
|
26
26
|
evidence: IStateTable<IEvidenceState>;
|
|
27
27
|
tokenFactory: IStateTable<ITokenFactoryState>;
|
|
28
28
|
constructor();
|
|
29
|
+
/**
|
|
30
|
+
* Execute function - Memory adapter has no real transaction support
|
|
31
|
+
* This is a no-op wrapper that simply executes the callback
|
|
32
|
+
*
|
|
33
|
+
* @param fn - Function to execute (txn parameter will be null)
|
|
34
|
+
* @returns Result of the function
|
|
35
|
+
*/
|
|
36
|
+
runAsLambda<T>(fn: (txn: null) => T | Promise<T>): Promise<T>;
|
|
29
37
|
}
|
|
30
38
|
//#endregion
|
|
31
39
|
export { MemoryStateDB as default };
|
package/lib/package.cjs
CHANGED
|
@@ -12,7 +12,10 @@ var package_default = {
|
|
|
12
12
|
},
|
|
13
13
|
publishConfig: { "access": "public" },
|
|
14
14
|
contributors: ["wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"],
|
|
15
|
-
devDependencies: {
|
|
15
|
+
devDependencies: {
|
|
16
|
+
"@ocap/statedb-test": "workspace:*",
|
|
17
|
+
"@types/lokijs": "^1.5.14"
|
|
18
|
+
},
|
|
16
19
|
homepage: "https://github.com/ArcBlock/blockchain/tree/master/statedb/memory",
|
|
17
20
|
keywords: [
|
|
18
21
|
"ocap",
|
package/lib/table/account.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
3
|
const require_table_base = require('./base.cjs');
|
|
4
|
+
let _ocap_statedb = require("@ocap/statedb");
|
|
4
5
|
let _ocap_state_lib_states_account = require("@ocap/state/lib/states/account");
|
|
5
6
|
|
|
6
7
|
//#region src/table/account.ts
|
|
@@ -10,18 +11,30 @@ let _ocap_state_lib_states_account = require("@ocap/state/lib/states/account");
|
|
|
10
11
|
*/
|
|
11
12
|
var AccountStateDB = class extends require_table_base.default {
|
|
12
13
|
async _get(address, context = {}) {
|
|
13
|
-
const { traceMigration = true
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
14
|
+
const { traceMigration = true } = context;
|
|
15
|
+
const normalizedAddress = (0, _ocap_state_lib_states_account.ensureChecksumAddress)(address);
|
|
16
|
+
if (!traceMigration) return super._get(normalizedAddress, context);
|
|
17
|
+
return (0, _ocap_statedb.followMigrationChain)(normalizedAddress, (addr) => super._get(addr, context), _ocap_state_lib_states_account.ensureChecksumAddress);
|
|
17
18
|
}
|
|
18
|
-
_create(key, attrs = {}, context) {
|
|
19
|
+
async _create(key, attrs = {}, context) {
|
|
19
20
|
const address = (0, _ocap_state_lib_states_account.ensureChecksumAddress)(key);
|
|
21
|
+
const { migratedTo } = attrs;
|
|
22
|
+
if (migratedTo?.length) {
|
|
23
|
+
if (await (0, _ocap_statedb.wouldCreateMigrationCycle)(address, migratedTo, (addr) => super._get(addr, context), _ocap_state_lib_states_account.ensureChecksumAddress)) throw new Error(`Circular migration detected: ${address} -> ${migratedTo.join(", ")}`);
|
|
24
|
+
}
|
|
20
25
|
return super._create(address, {
|
|
21
26
|
...attrs,
|
|
22
27
|
[this.uniqIndex]: address
|
|
23
28
|
}, context);
|
|
24
29
|
}
|
|
30
|
+
async _update(key, updates, context) {
|
|
31
|
+
const address = (0, _ocap_state_lib_states_account.ensureChecksumAddress)(key);
|
|
32
|
+
const { migratedTo } = updates;
|
|
33
|
+
if (migratedTo?.length) {
|
|
34
|
+
if (await (0, _ocap_statedb.wouldCreateMigrationCycle)(address, migratedTo, (addr) => super._get(addr, context), _ocap_state_lib_states_account.ensureChecksumAddress)) throw new Error(`Circular migration detected: ${address} -> ${migratedTo.join(", ")}`);
|
|
35
|
+
}
|
|
36
|
+
return super._update(address, updates, context);
|
|
37
|
+
}
|
|
25
38
|
};
|
|
26
39
|
var account_default = AccountStateDB;
|
|
27
40
|
|
package/lib/table/account.d.cts
CHANGED
|
@@ -12,6 +12,7 @@ interface AccountOperationContext extends IOperationContext {
|
|
|
12
12
|
declare class AccountStateDB extends MemoryTable<IAccountState> {
|
|
13
13
|
_get(address: string, context?: AccountOperationContext): Promise<IAccountState | null>;
|
|
14
14
|
_create(key: string, attrs?: Partial<IAccountState>, context?: IOperationContext): Promise<IAccountState>;
|
|
15
|
+
_update(key: string, updates: Partial<IAccountState>, context?: IOperationContext): Promise<IAccountState>;
|
|
15
16
|
}
|
|
16
17
|
//#endregion
|
|
17
18
|
export { AccountStateDB as default };
|
package/lib/table/base.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StateDBTable } from "@ocap/statedb";
|
|
2
2
|
import { IBalanceTable, IOperationContext } from "@ocap/types";
|
|
3
|
-
import
|
|
3
|
+
import Lokijs from "lokijs";
|
|
4
4
|
|
|
5
5
|
//#region src/table/base.d.ts
|
|
6
6
|
interface TableOptions {
|
|
@@ -8,7 +8,7 @@ interface TableOptions {
|
|
|
8
8
|
uniqIndex: string | string[];
|
|
9
9
|
syncBalance?: boolean;
|
|
10
10
|
balanceTable?: IBalanceTable;
|
|
11
|
-
db:
|
|
11
|
+
db: Lokijs;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* 内存表基类
|
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.29.
|
|
4
|
+
"version": "1.29.5",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@ocap/statedb-test": "1.29.5",
|
|
17
18
|
"@types/lokijs": "^1.5.14"
|
|
18
19
|
},
|
|
19
20
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/statedb/memory",
|
|
@@ -62,10 +63,10 @@
|
|
|
62
63
|
},
|
|
63
64
|
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e",
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"@ocap/state": "1.29.
|
|
66
|
-
"@ocap/statedb": "1.29.
|
|
67
|
-
"@ocap/types": "1.29.
|
|
68
|
-
"@ocap/util": "1.29.
|
|
66
|
+
"@ocap/state": "1.29.5",
|
|
67
|
+
"@ocap/statedb": "1.29.5",
|
|
68
|
+
"@ocap/types": "1.29.5",
|
|
69
|
+
"@ocap/util": "1.29.5",
|
|
69
70
|
"debug": "^4.4.3",
|
|
70
71
|
"lodash": "^4.17.23",
|
|
71
72
|
"lokijs": "^1.5.12"
|