@ocap/statedb-sqlite 1.30.26 → 1.31.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/esm/db.d.mts +2 -0
- package/esm/db.mjs +52 -36
- package/esm/index.d.mts +3 -1
- package/esm/index.mjs +3 -1
- package/esm/migrations/003-token-charter-assets.d.mts +14 -0
- package/esm/migrations/003-token-charter-assets.mjs +116 -0
- package/esm/migrations/index.d.mts +2 -1
- package/esm/migrations/index.mjs +6 -3
- package/esm/package.mjs +2 -0
- package/esm/reconcile.d.mts +82 -0
- package/esm/reconcile.mjs +833 -0
- package/esm/table/balance.mjs +35 -16
- package/esm/table/base.mjs +24 -17
- package/esm/tombstone-cleanup.d.mts +59 -0
- package/esm/tombstone-cleanup.mjs +207 -0
- package/lib/db.cjs +52 -36
- package/lib/db.d.cts +2 -0
- package/lib/index.cjs +12 -1
- package/lib/index.d.cts +3 -1
- package/lib/migrations/003-token-charter-assets.cjs +123 -0
- package/lib/migrations/003-token-charter-assets.d.cts +14 -0
- package/lib/migrations/index.cjs +12 -3
- package/lib/migrations/index.d.cts +2 -1
- package/lib/package.cjs +2 -0
- package/lib/reconcile.cjs +836 -0
- package/lib/reconcile.d.cts +82 -0
- package/lib/table/balance.cjs +35 -16
- package/lib/table/base.cjs +24 -17
- package/lib/tombstone-cleanup.cjs +213 -0
- package/lib/tombstone-cleanup.d.cts +59 -0
- package/package.json +8 -6
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let kysely = require("kysely");
|
|
3
|
+
let _arcblock_did = require("@arcblock/did");
|
|
4
|
+
let _ocap_state = require("@ocap/state");
|
|
5
|
+
let _ocap_util = require("@ocap/util");
|
|
6
|
+
|
|
7
|
+
//#region src/migrations/003-token-charter-assets.ts
|
|
8
|
+
var _003_token_charter_assets_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
9
|
+
down: () => down,
|
|
10
|
+
up: () => up
|
|
11
|
+
});
|
|
12
|
+
function parseJsonField(val, fallback) {
|
|
13
|
+
if (val === null || val === void 0 || val === "") return fallback;
|
|
14
|
+
if (typeof val === "object") return val;
|
|
15
|
+
if (typeof val === "string") try {
|
|
16
|
+
return JSON.parse(val);
|
|
17
|
+
} catch {
|
|
18
|
+
return fallback;
|
|
19
|
+
}
|
|
20
|
+
return fallback;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Migration 003: Backfill companion Master Charter `AssetState` rows in `asset`
|
|
24
|
+
* for all existing Fungible Tokens in `token` (Token-as-an-Asset unification).
|
|
25
|
+
*/
|
|
26
|
+
async function up(db) {
|
|
27
|
+
const tokenRows = (await kysely.sql`SELECT * FROM "token"`.execute(db)).rows || [];
|
|
28
|
+
if (tokenRows.length === 0) return;
|
|
29
|
+
const factoryOwnerMap = /* @__PURE__ */ new Map();
|
|
30
|
+
try {
|
|
31
|
+
const factoryRowsResult = await kysely.sql`
|
|
32
|
+
SELECT "address", "owner" FROM "tokenFactory"
|
|
33
|
+
`.execute(db);
|
|
34
|
+
for (const row of factoryRowsResult.rows || []) if (row?.address && row?.owner) factoryOwnerMap.set(row.address, row.owner);
|
|
35
|
+
} catch {}
|
|
36
|
+
for (const row of tokenRows) {
|
|
37
|
+
const rawAddress = String(row.address || "").trim();
|
|
38
|
+
if (!rawAddress) continue;
|
|
39
|
+
const address = (0, _ocap_util.toAddress)(rawAddress);
|
|
40
|
+
if (!(0, _arcblock_did.isValid)(address)) continue;
|
|
41
|
+
const tokenFactoryAddress = String(row.tokenFactoryAddress || "");
|
|
42
|
+
const tokenState = (0, _ocap_state.normalizeLegacyTokenStateForUpdate)({
|
|
43
|
+
address,
|
|
44
|
+
name: String(row.name || row.symbol || "Token"),
|
|
45
|
+
description: String(row.description || "Fungible token charter state"),
|
|
46
|
+
symbol: String(row.symbol || "TKN"),
|
|
47
|
+
unit: String(row.unit || "unit"),
|
|
48
|
+
decimal: Number(row.decimal ?? 18),
|
|
49
|
+
icon: row.icon ? String(row.icon) : "",
|
|
50
|
+
totalSupply: String(row.totalSupply || "0"),
|
|
51
|
+
initialSupply: String(row.initialSupply || "0"),
|
|
52
|
+
maxTotalSupply: row.maxTotalSupply ? String(row.maxTotalSupply) : "",
|
|
53
|
+
foreignToken: parseJsonField(row.foreignToken, null),
|
|
54
|
+
issuer: row.issuer ? String(row.issuer) : "",
|
|
55
|
+
website: row.website ? String(row.website) : "",
|
|
56
|
+
metadata: parseJsonField(row.metadata, null),
|
|
57
|
+
tokenFactoryAddress,
|
|
58
|
+
spenders: parseJsonField(row.spenders, null),
|
|
59
|
+
minters: parseJsonField(row.minters, null),
|
|
60
|
+
type: row.type ? String(row.type) : "Token",
|
|
61
|
+
data: parseJsonField(row.data, null),
|
|
62
|
+
context: parseJsonField(row.context, {
|
|
63
|
+
genesisTime: "2020-01-15T00:00:00.000Z",
|
|
64
|
+
genesisTx: "",
|
|
65
|
+
renaissanceTime: "2020-01-15T00:00:00.000Z",
|
|
66
|
+
renaissanceTx: ""
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
const ownerOverride = tokenFactoryAddress ? factoryOwnerMap.get(tokenFactoryAddress) : void 0;
|
|
70
|
+
let charter;
|
|
71
|
+
try {
|
|
72
|
+
charter = (0, _ocap_state.buildTokenCharterAssetState)(tokenState, void 0, ownerOverride);
|
|
73
|
+
} catch {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
await kysely.sql`
|
|
77
|
+
INSERT OR IGNORE INTO "asset" (
|
|
78
|
+
"address",
|
|
79
|
+
"owner",
|
|
80
|
+
"moniker",
|
|
81
|
+
"readonly",
|
|
82
|
+
"transferrable",
|
|
83
|
+
"ttl",
|
|
84
|
+
"consumedTime",
|
|
85
|
+
"issuer",
|
|
86
|
+
"parent",
|
|
87
|
+
"endpoint",
|
|
88
|
+
"display",
|
|
89
|
+
"tags",
|
|
90
|
+
"data",
|
|
91
|
+
"context"
|
|
92
|
+
) VALUES (
|
|
93
|
+
${charter.address},
|
|
94
|
+
${charter.owner},
|
|
95
|
+
${charter.moniker},
|
|
96
|
+
${charter.readonly ? 1 : 0},
|
|
97
|
+
${charter.transferrable ? 1 : 0},
|
|
98
|
+
${charter.ttl ?? 0},
|
|
99
|
+
${charter.consumedTime || ""},
|
|
100
|
+
${charter.issuer || ""},
|
|
101
|
+
${charter.parent || ""},
|
|
102
|
+
${charter.endpoint ? JSON.stringify(charter.endpoint) : null},
|
|
103
|
+
${charter.display ? JSON.stringify(charter.display) : null},
|
|
104
|
+
${JSON.stringify(charter.tags || [])},
|
|
105
|
+
${JSON.stringify(charter.data ?? null)},
|
|
106
|
+
${JSON.stringify(charter.context ?? null)}
|
|
107
|
+
)
|
|
108
|
+
`.execute(db);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function down(db) {
|
|
112
|
+
await kysely.sql`DELETE FROM "asset" WHERE "tags" LIKE '%"token:charter"%'`.execute(db);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
Object.defineProperty(exports, '_003_token_charter_assets_exports', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return _003_token_charter_assets_exports;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
exports.down = down;
|
|
123
|
+
exports.up = up;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
|
|
3
|
+
//#region src/migrations/003-token-charter-assets.d.ts
|
|
4
|
+
declare namespace _003_token_charter_assets_d_exports {
|
|
5
|
+
export { down, up };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Migration 003: Backfill companion Master Charter `AssetState` rows in `asset`
|
|
9
|
+
* for all existing Fungible Tokens in `token` (Token-as-an-Asset unification).
|
|
10
|
+
*/
|
|
11
|
+
declare function up(db: Kysely<unknown>): Promise<void>;
|
|
12
|
+
declare function down(db: Kysely<unknown>): Promise<void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { _003_token_charter_assets_d_exports, down, up };
|
package/lib/migrations/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_migrations_001_genesis = require('./001-genesis.cjs');
|
|
3
3
|
const require_migrations_002_delegation_extensions = require('./002-delegation-extensions.cjs');
|
|
4
|
+
const require_migrations_003_token_charter_assets = require('./003-token-charter-assets.cjs');
|
|
4
5
|
let kysely = require("kysely");
|
|
5
6
|
|
|
6
7
|
//#region src/migrations/index.ts
|
|
@@ -33,7 +34,8 @@ async function runMigrations(db) {
|
|
|
33
34
|
db,
|
|
34
35
|
provider: new InMemoryMigrationProvider({
|
|
35
36
|
"001-genesis": require_migrations_001_genesis._001_genesis_exports,
|
|
36
|
-
"002-delegation-extensions": require_migrations_002_delegation_extensions._002_delegation_extensions_exports
|
|
37
|
+
"002-delegation-extensions": require_migrations_002_delegation_extensions._002_delegation_extensions_exports,
|
|
38
|
+
"003-token-charter-assets": require_migrations_003_token_charter_assets._003_token_charter_assets_exports
|
|
37
39
|
})
|
|
38
40
|
}).migrateToLatest();
|
|
39
41
|
results?.forEach((it) => {
|
|
@@ -53,7 +55,8 @@ async function rollbackMigrations(db) {
|
|
|
53
55
|
db,
|
|
54
56
|
provider: new InMemoryMigrationProvider({
|
|
55
57
|
"001-genesis": require_migrations_001_genesis._001_genesis_exports,
|
|
56
|
-
"002-delegation-extensions": require_migrations_002_delegation_extensions._002_delegation_extensions_exports
|
|
58
|
+
"002-delegation-extensions": require_migrations_002_delegation_extensions._002_delegation_extensions_exports,
|
|
59
|
+
"003-token-charter-assets": require_migrations_003_token_charter_assets._003_token_charter_assets_exports
|
|
57
60
|
})
|
|
58
61
|
});
|
|
59
62
|
let hasMore = true;
|
|
@@ -66,4 +69,10 @@ async function rollbackMigrations(db) {
|
|
|
66
69
|
|
|
67
70
|
//#endregion
|
|
68
71
|
exports.rollbackMigrations = rollbackMigrations;
|
|
69
|
-
exports.runMigrations = runMigrations;
|
|
72
|
+
exports.runMigrations = runMigrations;
|
|
73
|
+
Object.defineProperty(exports, 'tokenCharterAssets', {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return require_migrations_003_token_charter_assets._003_token_charter_assets_exports;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _003_token_charter_assets_d_exports } from "./003-token-charter-assets.cjs";
|
|
1
2
|
import { Kysely } from "kysely";
|
|
2
3
|
|
|
3
4
|
//#region src/migrations/index.d.ts
|
|
@@ -21,4 +22,4 @@ declare function runMigrations(db: Kysely<unknown>): Promise<void>;
|
|
|
21
22
|
*/
|
|
22
23
|
declare function rollbackMigrations(db: Kysely<unknown>): Promise<void>;
|
|
23
24
|
//#endregion
|
|
24
|
-
export { rollbackMigrations, runMigrations };
|
|
25
|
+
export { rollbackMigrations, runMigrations, _003_token_charter_assets_d_exports as tokenCharterAssets };
|
package/lib/package.cjs
CHANGED