@ocap/statedb-sqlite 1.31.1 → 1.31.3
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 +11 -0
- package/esm/db.mjs +45 -9
- package/esm/index.d.mts +4 -1
- package/esm/index.mjs +4 -1
- package/esm/migrations/002-delegation-extensions.mjs +9 -2
- package/esm/migrations/004-rollup-reserves.d.mts +20 -0
- package/esm/migrations/004-rollup-reserves.mjs +39 -0
- package/esm/migrations/index.mjs +30 -15
- package/esm/table/account.d.mts +4 -3
- package/esm/table/account.mjs +31 -7
- package/esm/table/balance.mjs +31 -4
- package/esm/table/base.d.mts +8 -1
- package/esm/table/base.mjs +72 -28
- package/esm/table/rollup.d.mts +5 -2
- package/esm/table/rollup.mjs +38 -5
- package/esm/table/token.d.mts +9 -0
- package/esm/table/token.mjs +14 -0
- package/esm/tombstone-cleanup.mjs +1 -1
- package/esm/write-set.d.mts +66 -0
- package/esm/write-set.mjs +339 -0
- package/lib/db.cjs +45 -10
- package/lib/db.d.cts +11 -0
- package/lib/index.cjs +19 -0
- package/lib/index.d.cts +4 -1
- package/lib/migrations/002-delegation-extensions.cjs +9 -2
- package/lib/migrations/004-rollup-reserves.cjs +47 -0
- package/lib/migrations/004-rollup-reserves.d.cts +20 -0
- package/lib/migrations/index.cjs +30 -15
- package/lib/table/account.cjs +31 -7
- package/lib/table/account.d.cts +4 -3
- package/lib/table/balance.cjs +31 -4
- package/lib/table/base.cjs +72 -28
- package/lib/table/base.d.cts +8 -1
- package/lib/table/rollup.cjs +38 -5
- package/lib/table/rollup.d.cts +5 -2
- package/lib/table/token.cjs +14 -0
- package/lib/table/token.d.cts +9 -0
- package/lib/tombstone-cleanup.cjs +1 -1
- package/lib/write-set.cjs +351 -0
- package/lib/write-set.d.cts +66 -0
- package/package.json +8 -8
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_crypto = require("node:crypto");
|
|
3
|
+
node_crypto = require_rolldown_runtime.__toESM(node_crypto);
|
|
4
|
+
|
|
5
|
+
//#region src/write-set.ts
|
|
6
|
+
const STATE_COMMIT_DOMAIN_V2 = "ocap:state-commit:v2:";
|
|
7
|
+
function codeUnitCompare(a, b) {
|
|
8
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
9
|
+
}
|
|
10
|
+
function sha256Hex(utf8Input) {
|
|
11
|
+
return node_crypto.default.createHash("sha256").update(utf8Input, "utf8").digest("hex");
|
|
12
|
+
}
|
|
13
|
+
function bytesToHexLower(bytes) {
|
|
14
|
+
let out = "";
|
|
15
|
+
for (let i = 0; i < bytes.length; i++) out += bytes[i].toString(16).padStart(2, "0");
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Recursively normalize an arbitrary JS value into a deterministic JSON-serializable structure
|
|
20
|
+
* with lexicographically sorted object keys (code-unit order).
|
|
21
|
+
* Bit-for-bit identical to `@arcblock/ledger-core` `canonicalizeStateValue`.
|
|
22
|
+
*/
|
|
23
|
+
function canonicalizeStateValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
24
|
+
if (value === null || value === void 0) return null;
|
|
25
|
+
if (typeof value === "boolean" || typeof value === "string") return value;
|
|
26
|
+
if (typeof value === "number") {
|
|
27
|
+
if (!Number.isFinite(value)) return null;
|
|
28
|
+
return Object.is(value, -0) ? 0 : value;
|
|
29
|
+
}
|
|
30
|
+
if (typeof value === "bigint") return { $bigint: value.toString(10) };
|
|
31
|
+
if (value instanceof ArrayBuffer) return { $bytes: bytesToHexLower(new Uint8Array(value)) };
|
|
32
|
+
if (ArrayBuffer.isView(value)) return { $bytes: bytesToHexLower(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)) };
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
if (seen.has(value)) throw new TypeError("Cannot canonicalize circular state array");
|
|
35
|
+
seen.add(value);
|
|
36
|
+
try {
|
|
37
|
+
return value.map((item) => canonicalizeStateValue(item, seen));
|
|
38
|
+
} finally {
|
|
39
|
+
seen.delete(value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (typeof value === "object") {
|
|
43
|
+
if (seen.has(value)) throw new TypeError("Cannot canonicalize circular state object");
|
|
44
|
+
seen.add(value);
|
|
45
|
+
try {
|
|
46
|
+
const proto = Object.getPrototypeOf(value);
|
|
47
|
+
if (!(proto === Object.prototype || proto === null) && typeof value.toJSON === "function") return canonicalizeStateValue(value.toJSON(), seen);
|
|
48
|
+
const record = value;
|
|
49
|
+
const sortedKeys = Object.keys(record).sort(codeUnitCompare);
|
|
50
|
+
const normalized = Object.create(null);
|
|
51
|
+
for (const k of sortedKeys) {
|
|
52
|
+
const v = record[k];
|
|
53
|
+
if (v !== void 0) Object.defineProperty(normalized, k, {
|
|
54
|
+
value: canonicalizeStateValue(v, seen),
|
|
55
|
+
enumerable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
configurable: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return normalized;
|
|
61
|
+
} finally {
|
|
62
|
+
seen.delete(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return String(value);
|
|
66
|
+
}
|
|
67
|
+
function canonicalizeStateJson(value) {
|
|
68
|
+
return JSON.stringify(canonicalizeStateValue(value));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Collapse an ordered sequence of intra-transaction state writes into a canonical, deterministic tuple array
|
|
72
|
+
* and hash it with SHA-256 (64 lowercase hex chars).
|
|
73
|
+
* Bit-for-bit identical to `@arcblock/ledger-core` `computeStateWriteSetDigest`.
|
|
74
|
+
*/
|
|
75
|
+
function computeStateWriteSetDigest(writes) {
|
|
76
|
+
const tables = /* @__PURE__ */ new Map();
|
|
77
|
+
const rawOps = [];
|
|
78
|
+
const ensureTable = (table) => {
|
|
79
|
+
let entry = tables.get(table);
|
|
80
|
+
if (!entry) {
|
|
81
|
+
entry = {
|
|
82
|
+
reset: false,
|
|
83
|
+
rows: /* @__PURE__ */ new Map()
|
|
84
|
+
};
|
|
85
|
+
tables.set(table, entry);
|
|
86
|
+
}
|
|
87
|
+
return entry;
|
|
88
|
+
};
|
|
89
|
+
for (const w of writes) {
|
|
90
|
+
if (!w || typeof w !== "object") continue;
|
|
91
|
+
if (w.op === "reset") {
|
|
92
|
+
const t = ensureTable(String(w.table));
|
|
93
|
+
t.reset = true;
|
|
94
|
+
t.rows.clear();
|
|
95
|
+
} else if (w.op === "put") ensureTable(String(w.table)).rows.set(String(w.key), {
|
|
96
|
+
op: "put",
|
|
97
|
+
value: canonicalizeStateValue(w.value)
|
|
98
|
+
});
|
|
99
|
+
else if (w.op === "delete") ensureTable(String(w.table)).rows.set(String(w.key), { op: "delete" });
|
|
100
|
+
else if (w.op === "raw") rawOps.push({
|
|
101
|
+
sql: String(w.sql),
|
|
102
|
+
parameters: Array.isArray(w.parameters) ? w.parameters.map((p) => canonicalizeStateValue(p)) : []
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const normalizedEntries = [];
|
|
106
|
+
const sortedTables = Array.from(tables.keys()).sort(codeUnitCompare);
|
|
107
|
+
for (const table of sortedTables) {
|
|
108
|
+
const t = tables.get(table);
|
|
109
|
+
if (t.reset) normalizedEntries.push(["reset", table]);
|
|
110
|
+
const sortedKeys = Array.from(t.rows.keys()).sort(codeUnitCompare);
|
|
111
|
+
for (const key of sortedKeys) {
|
|
112
|
+
const row = t.rows.get(key);
|
|
113
|
+
if (row.op === "delete") normalizedEntries.push([
|
|
114
|
+
"delete",
|
|
115
|
+
table,
|
|
116
|
+
key
|
|
117
|
+
]);
|
|
118
|
+
else normalizedEntries.push([
|
|
119
|
+
"put",
|
|
120
|
+
table,
|
|
121
|
+
key,
|
|
122
|
+
row.value
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const raw of rawOps) normalizedEntries.push([
|
|
127
|
+
"raw",
|
|
128
|
+
raw.sql,
|
|
129
|
+
raw.parameters
|
|
130
|
+
]);
|
|
131
|
+
return sha256Hex(JSON.stringify(normalizedEntries));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Compute v2 state commit hash binding `(prevHash, seq, msg, writeSetDigest)` with unambiguous JSON framing.
|
|
135
|
+
* Bit-for-bit identical to `@arcblock/ledger-core` `computeStateCommitHash`.
|
|
136
|
+
*/
|
|
137
|
+
function computeStateCommitHash(params) {
|
|
138
|
+
const { prevHash, seq, msg, writeSetDigest } = params;
|
|
139
|
+
if (!Number.isSafeInteger(seq) || seq < 1) throw new Error(`Invalid state commit sequence: ${seq}`);
|
|
140
|
+
if (typeof writeSetDigest !== "string" || !/^[0-9a-f]{64}$/i.test(writeSetDigest)) throw new Error("Invalid writeSetDigest: expected 64-char hex SHA-256");
|
|
141
|
+
return sha256Hex(`${STATE_COMMIT_DOMAIN_V2}${JSON.stringify([
|
|
142
|
+
String(prevHash),
|
|
143
|
+
seq,
|
|
144
|
+
String(msg),
|
|
145
|
+
writeSetDigest.toLowerCase()
|
|
146
|
+
])}`);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Format a table's primary key into an unambiguous canonical string key.
|
|
150
|
+
* Single-column PKs serialize as `String(val)`; composite PKs serialize as a JSON string tuple.
|
|
151
|
+
*/
|
|
152
|
+
function formatCanonicalPrimaryKey(uniqIndex, keyOrDoc) {
|
|
153
|
+
if (Array.isArray(uniqIndex)) {
|
|
154
|
+
const obj = keyOrDoc || {};
|
|
155
|
+
return JSON.stringify(uniqIndex.map((col) => obj[col]));
|
|
156
|
+
}
|
|
157
|
+
if (typeof keyOrDoc === "object" && keyOrDoc !== null) return String(keyOrDoc[uniqIndex]);
|
|
158
|
+
return String(keyOrDoc);
|
|
159
|
+
}
|
|
160
|
+
const TOP_LEVEL_MUTATING_STMT_RE = /^(?:INSERT|UPDATE|DELETE|REPLACE|ALTER|DROP|CREATE|ATTACH|DETACH|VACUUM|REINDEX|ANALYZE|PRAGMA)\b/i;
|
|
161
|
+
const CTE_MUTATING_TAIL_RE = /^WITH\b[\s\S]*?\b(?:INSERT|UPDATE|DELETE|REPLACE)\b/i;
|
|
162
|
+
function scanTopLevelSqlStatements(sqlText) {
|
|
163
|
+
const statements = [];
|
|
164
|
+
let current = "";
|
|
165
|
+
let depth = 0;
|
|
166
|
+
const len = sqlText.length;
|
|
167
|
+
let i = 0;
|
|
168
|
+
while (i < len) {
|
|
169
|
+
const ch = sqlText[i];
|
|
170
|
+
const next = i + 1 < len ? sqlText[i + 1] : "";
|
|
171
|
+
if (ch === "-" && next === "-") {
|
|
172
|
+
i += 2;
|
|
173
|
+
while (i < len && sqlText[i] !== "\n" && sqlText[i] !== "\r") i++;
|
|
174
|
+
if (depth === 0) current += " ";
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (ch === "/" && next === "*") {
|
|
178
|
+
i += 2;
|
|
179
|
+
while (i < len && !(sqlText[i] === "*" && sqlText[i + 1] === "/")) i++;
|
|
180
|
+
i = i < len ? i + 2 : len;
|
|
181
|
+
if (depth === 0) current += " ";
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (ch === "'" || ch === "\"" || ch === "`") {
|
|
185
|
+
const quote = ch;
|
|
186
|
+
i++;
|
|
187
|
+
while (i < len) {
|
|
188
|
+
if (sqlText[i] === quote) {
|
|
189
|
+
if (sqlText[i + 1] === quote) {
|
|
190
|
+
i += 2;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
i++;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
i++;
|
|
197
|
+
}
|
|
198
|
+
if (depth === 0) current += " ";
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (ch === "[") {
|
|
202
|
+
i++;
|
|
203
|
+
while (i < len && sqlText[i] !== "]") i++;
|
|
204
|
+
if (i < len) i++;
|
|
205
|
+
if (depth === 0) current += " ";
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (ch === "(") {
|
|
209
|
+
if (depth === 0) current += " ";
|
|
210
|
+
depth++;
|
|
211
|
+
i++;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (ch === ")") {
|
|
215
|
+
if (depth > 0) depth--;
|
|
216
|
+
if (depth === 0) current += " ";
|
|
217
|
+
i++;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (ch === ";" && depth === 0) {
|
|
221
|
+
const trimmed = current.trim();
|
|
222
|
+
if (trimmed.length > 0) statements.push(trimmed);
|
|
223
|
+
current = "";
|
|
224
|
+
i++;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (depth === 0) current += ch;
|
|
228
|
+
i++;
|
|
229
|
+
}
|
|
230
|
+
const tail = current.trim();
|
|
231
|
+
if (tail.length > 0) statements.push(tail);
|
|
232
|
+
return statements;
|
|
233
|
+
}
|
|
234
|
+
function isTrackedRawMutatingSql(sqlText) {
|
|
235
|
+
for (const stmt of scanTopLevelSqlStatements(sqlText)) if (TOP_LEVEL_MUTATING_STMT_RE.test(stmt) || CTE_MUTATING_TAIL_RE.test(stmt)) return true;
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
var WriteSetTracker = class {
|
|
239
|
+
constructor() {
|
|
240
|
+
this.writes = [];
|
|
241
|
+
}
|
|
242
|
+
recordPut(table, key, value) {
|
|
243
|
+
this.writes.push({
|
|
244
|
+
op: "put",
|
|
245
|
+
table,
|
|
246
|
+
key,
|
|
247
|
+
value
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
recordDelete(table, key) {
|
|
251
|
+
this.writes.push({
|
|
252
|
+
op: "delete",
|
|
253
|
+
table,
|
|
254
|
+
key
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
recordReset(table) {
|
|
258
|
+
this.writes.push({
|
|
259
|
+
op: "reset",
|
|
260
|
+
table
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
recordRaw(sqlText, parameters) {
|
|
264
|
+
this.writes.push({
|
|
265
|
+
op: "raw",
|
|
266
|
+
sql: sqlText,
|
|
267
|
+
parameters
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
getWrites() {
|
|
271
|
+
return this.writes;
|
|
272
|
+
}
|
|
273
|
+
computeDigest() {
|
|
274
|
+
return computeStateWriteSetDigest(this.writes);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var WriteSetRawDmlPlugin = class {
|
|
278
|
+
constructor(rawTxn, tracker, basePlugins) {
|
|
279
|
+
this.pendingByQueryId = /* @__PURE__ */ new WeakMap();
|
|
280
|
+
this.rawTxn = rawTxn;
|
|
281
|
+
this.tracker = tracker;
|
|
282
|
+
this.basePlugins = basePlugins;
|
|
283
|
+
}
|
|
284
|
+
transformQuery(args) {
|
|
285
|
+
try {
|
|
286
|
+
const compiled = this.rawTxn.getExecutor().compileQuery(args.node, args.queryId);
|
|
287
|
+
if (isTrackedRawMutatingSql(compiled.sql)) this.pendingByQueryId.set(args.queryId, {
|
|
288
|
+
sql: compiled.sql,
|
|
289
|
+
parameters: compiled.parameters
|
|
290
|
+
});
|
|
291
|
+
} catch {}
|
|
292
|
+
return args.node;
|
|
293
|
+
}
|
|
294
|
+
async transformResult(args) {
|
|
295
|
+
const key = args.queryId;
|
|
296
|
+
const pending = this.pendingByQueryId.get(key);
|
|
297
|
+
if (pending) {
|
|
298
|
+
this.pendingByQueryId.delete(key);
|
|
299
|
+
this.tracker.recordRaw(pending.sql, pending.parameters);
|
|
300
|
+
}
|
|
301
|
+
return args.result;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const TXN_TRACKER_MAP = /* @__PURE__ */ new WeakMap();
|
|
305
|
+
const RAW_TXN_MAP = /* @__PURE__ */ new WeakMap();
|
|
306
|
+
function attachWriteSetTracker(rawTxn, tracker) {
|
|
307
|
+
const basePlugins = rawTxn.getExecutor().plugins;
|
|
308
|
+
const plugin = new WriteSetRawDmlPlugin(rawTxn, tracker, basePlugins);
|
|
309
|
+
const wrappedTxn = rawTxn.withPlugin(plugin);
|
|
310
|
+
TXN_TRACKER_MAP.set(rawTxn, tracker);
|
|
311
|
+
TXN_TRACKER_MAP.set(wrappedTxn, tracker);
|
|
312
|
+
RAW_TXN_MAP.set(wrappedTxn, rawTxn);
|
|
313
|
+
return wrappedTxn;
|
|
314
|
+
}
|
|
315
|
+
function getWriteSetTracker(txn) {
|
|
316
|
+
if (!txn || typeof txn !== "object") return void 0;
|
|
317
|
+
const direct = TXN_TRACKER_MAP.get(txn);
|
|
318
|
+
if (direct) return direct;
|
|
319
|
+
const plugins = txn.getExecutor?.()?.plugins;
|
|
320
|
+
if (Array.isArray(plugins)) {
|
|
321
|
+
for (const p of plugins) if (p instanceof WriteSetRawDmlPlugin) return p.tracker;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function unwrapTableTransaction(txn) {
|
|
325
|
+
const direct = RAW_TXN_MAP.get(txn);
|
|
326
|
+
if (direct) return direct;
|
|
327
|
+
const plugins = txn.getExecutor?.()?.plugins;
|
|
328
|
+
if (Array.isArray(plugins)) {
|
|
329
|
+
const found = plugins.find((p) => p instanceof WriteSetRawDmlPlugin);
|
|
330
|
+
if (found) {
|
|
331
|
+
let stripped = txn.withoutPlugins();
|
|
332
|
+
for (const bp of found.basePlugins) stripped = stripped.withPlugin(bp);
|
|
333
|
+
RAW_TXN_MAP.set(txn, stripped);
|
|
334
|
+
return stripped;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return txn;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
//#endregion
|
|
341
|
+
exports.STATE_COMMIT_DOMAIN_V2 = STATE_COMMIT_DOMAIN_V2;
|
|
342
|
+
exports.WriteSetTracker = WriteSetTracker;
|
|
343
|
+
exports.attachWriteSetTracker = attachWriteSetTracker;
|
|
344
|
+
exports.canonicalizeStateJson = canonicalizeStateJson;
|
|
345
|
+
exports.canonicalizeStateValue = canonicalizeStateValue;
|
|
346
|
+
exports.computeStateCommitHash = computeStateCommitHash;
|
|
347
|
+
exports.computeStateWriteSetDigest = computeStateWriteSetDigest;
|
|
348
|
+
exports.formatCanonicalPrimaryKey = formatCanonicalPrimaryKey;
|
|
349
|
+
exports.getWriteSetTracker = getWriteSetTracker;
|
|
350
|
+
exports.isTrackedRawMutatingSql = isTrackedRawMutatingSql;
|
|
351
|
+
exports.unwrapTableTransaction = unwrapTableTransaction;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Database } from "./interfaces.cjs";
|
|
2
|
+
import { Transaction } from "kysely";
|
|
3
|
+
|
|
4
|
+
//#region src/write-set.d.ts
|
|
5
|
+
declare const STATE_COMMIT_DOMAIN_V2 = "ocap:state-commit:v2:";
|
|
6
|
+
type IStateWriteRecord = {
|
|
7
|
+
op: 'put';
|
|
8
|
+
table: string;
|
|
9
|
+
key: string;
|
|
10
|
+
value: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
op: 'delete';
|
|
13
|
+
table: string;
|
|
14
|
+
key: string;
|
|
15
|
+
} | {
|
|
16
|
+
op: 'reset';
|
|
17
|
+
table: string;
|
|
18
|
+
} | {
|
|
19
|
+
op: 'raw';
|
|
20
|
+
sql: string;
|
|
21
|
+
parameters?: readonly unknown[];
|
|
22
|
+
};
|
|
23
|
+
interface IStateCommitStepInput {
|
|
24
|
+
prevHash: string;
|
|
25
|
+
seq: number;
|
|
26
|
+
msg: string;
|
|
27
|
+
writeSetDigest: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Recursively normalize an arbitrary JS value into a deterministic JSON-serializable structure
|
|
31
|
+
* with lexicographically sorted object keys (code-unit order).
|
|
32
|
+
* Bit-for-bit identical to `@arcblock/ledger-core` `canonicalizeStateValue`.
|
|
33
|
+
*/
|
|
34
|
+
declare function canonicalizeStateValue(value: unknown, seen?: WeakSet<object>): unknown;
|
|
35
|
+
declare function canonicalizeStateJson(value: unknown): string;
|
|
36
|
+
/**
|
|
37
|
+
* Collapse an ordered sequence of intra-transaction state writes into a canonical, deterministic tuple array
|
|
38
|
+
* and hash it with SHA-256 (64 lowercase hex chars).
|
|
39
|
+
* Bit-for-bit identical to `@arcblock/ledger-core` `computeStateWriteSetDigest`.
|
|
40
|
+
*/
|
|
41
|
+
declare function computeStateWriteSetDigest(writes: Iterable<IStateWriteRecord>): string;
|
|
42
|
+
/**
|
|
43
|
+
* Compute v2 state commit hash binding `(prevHash, seq, msg, writeSetDigest)` with unambiguous JSON framing.
|
|
44
|
+
* Bit-for-bit identical to `@arcblock/ledger-core` `computeStateCommitHash`.
|
|
45
|
+
*/
|
|
46
|
+
declare function computeStateCommitHash(params: IStateCommitStepInput): string;
|
|
47
|
+
/**
|
|
48
|
+
* Format a table's primary key into an unambiguous canonical string key.
|
|
49
|
+
* Single-column PKs serialize as `String(val)`; composite PKs serialize as a JSON string tuple.
|
|
50
|
+
*/
|
|
51
|
+
declare function formatCanonicalPrimaryKey(uniqIndex: string | string[], keyOrDoc: unknown): string;
|
|
52
|
+
declare function isTrackedRawMutatingSql(sqlText: string): boolean;
|
|
53
|
+
declare class WriteSetTracker {
|
|
54
|
+
private readonly writes;
|
|
55
|
+
recordPut(table: string, key: string, value: unknown): void;
|
|
56
|
+
recordDelete(table: string, key: string): void;
|
|
57
|
+
recordReset(table: string): void;
|
|
58
|
+
recordRaw(sqlText: string, parameters?: readonly unknown[]): void;
|
|
59
|
+
getWrites(): readonly IStateWriteRecord[];
|
|
60
|
+
computeDigest(): string;
|
|
61
|
+
}
|
|
62
|
+
declare function attachWriteSetTracker(rawTxn: Transaction<Database>, tracker: WriteSetTracker): Transaction<Database>;
|
|
63
|
+
declare function getWriteSetTracker(txn: Transaction<Database> | undefined): WriteSetTracker | undefined;
|
|
64
|
+
declare function unwrapTableTransaction(txn: Transaction<Database>): Transaction<Database>;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { IStateCommitStepInput, IStateWriteRecord, STATE_COMMIT_DOMAIN_V2, WriteSetTracker, attachWriteSetTracker, canonicalizeStateJson, canonicalizeStateValue, computeStateCommitHash, computeStateWriteSetDigest, formatCanonicalPrimaryKey, getWriteSetTracker, isTrackedRawMutatingSql, unwrapTableTransaction };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/statedb-sqlite",
|
|
3
3
|
"description": "OCAP statedb adapter that uses SQLite as backend",
|
|
4
|
-
"version": "1.31.
|
|
4
|
+
"version": "1.31.3",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@ocap/statedb-test": "1.31.
|
|
17
|
+
"@ocap/statedb-test": "1.31.3"
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/statedb/sqlite",
|
|
20
20
|
"keywords": [
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"clean": "rm -rf lib esm"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@arcblock/did": "1.31.
|
|
67
|
-
"@arcblock/did-util": "1.31.
|
|
68
|
-
"@ocap/state": "1.31.
|
|
69
|
-
"@ocap/statedb": "1.31.
|
|
70
|
-
"@ocap/types": "1.31.
|
|
71
|
-
"@ocap/util": "1.31.
|
|
66
|
+
"@arcblock/did": "1.31.3",
|
|
67
|
+
"@arcblock/did-util": "1.31.3",
|
|
68
|
+
"@ocap/state": "1.31.3",
|
|
69
|
+
"@ocap/statedb": "1.31.3",
|
|
70
|
+
"@ocap/types": "1.31.3",
|
|
71
|
+
"@ocap/util": "1.31.3",
|
|
72
72
|
"better-sqlite3": "^11.8.1",
|
|
73
73
|
"kysely": "^0.28.14",
|
|
74
74
|
"kysely-bun-sqlite": "^0.4.0",
|