@ocap/resolver 1.28.8 → 1.29.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.
- package/esm/api.d.mts +24 -0
- package/esm/api.mjs +53 -0
- package/esm/hooks.d.mts +153 -0
- package/esm/hooks.mjs +267 -0
- package/esm/index.d.mts +201 -0
- package/esm/index.mjs +1327 -0
- package/esm/migration-chain.d.mts +52 -0
- package/esm/migration-chain.mjs +97 -0
- package/esm/package.mjs +5 -0
- package/esm/token-cache.d.mts +20 -0
- package/esm/token-cache.mjs +26 -0
- package/esm/token-distribution.d.mts +166 -0
- package/esm/token-distribution.mjs +241 -0
- package/esm/token-flow.d.mts +139 -0
- package/esm/token-flow.mjs +330 -0
- package/esm/types.d.mts +115 -0
- package/esm/types.mjs +1 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/api.cjs +54 -0
- package/lib/api.d.cts +24 -0
- package/lib/hooks.cjs +274 -0
- package/lib/hooks.d.cts +153 -0
- package/lib/index.cjs +1343 -0
- package/lib/index.d.cts +201 -0
- package/lib/migration-chain.cjs +99 -0
- package/lib/migration-chain.d.cts +52 -0
- package/lib/package.cjs +11 -0
- package/lib/token-cache.cjs +27 -0
- package/lib/token-cache.d.cts +20 -0
- package/lib/token-distribution.cjs +243 -0
- package/lib/token-distribution.d.cts +166 -0
- package/lib/token-flow.cjs +336 -0
- package/lib/token-flow.d.cts +139 -0
- package/lib/types.cjs +0 -0
- package/lib/types.d.cts +115 -0
- package/package.json +49 -21
- package/lib/api.js +0 -71
- package/lib/hooks.js +0 -339
- package/lib/index.js +0 -1486
- package/lib/migration-chain.js +0 -144
- package/lib/token-cache.js +0 -40
- package/lib/token-distribution.js +0 -358
- package/lib/token-flow.js +0 -445
package/lib/api.d.cts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TIndexedTokenState } from "./types.cjs";
|
|
2
|
+
import { Router } from "express";
|
|
3
|
+
|
|
4
|
+
//#region src/api.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resolver interface for API handler
|
|
8
|
+
*/
|
|
9
|
+
interface IAPIResolver {
|
|
10
|
+
getTokenState(params: {
|
|
11
|
+
address: string;
|
|
12
|
+
}): Promise<TIndexedTokenState | null>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parameters for createAPIHandler
|
|
16
|
+
*/
|
|
17
|
+
interface ICreateAPIHandlerParams {
|
|
18
|
+
resolver: IAPIResolver;
|
|
19
|
+
}
|
|
20
|
+
declare function createAPIHandler({
|
|
21
|
+
resolver
|
|
22
|
+
}: ICreateAPIHandlerParams): Router;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { createAPIHandler };
|
package/lib/hooks.cjs
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_package = require('./package.cjs');
|
|
3
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
4
|
+
let _ocap_util = require("@ocap/util");
|
|
5
|
+
let debug = require("debug");
|
|
6
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
7
|
+
let lodash_merge = require("lodash/merge");
|
|
8
|
+
lodash_merge = require_rolldown_runtime.__toESM(lodash_merge);
|
|
9
|
+
let lodash_pick = require("lodash/pick");
|
|
10
|
+
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
11
|
+
|
|
12
|
+
//#region src/hooks.ts
|
|
13
|
+
const debug$1 = (0, debug.default)(require_package.name);
|
|
14
|
+
const onCreateRollup = (rollup, _ctx, indexdb) => {
|
|
15
|
+
rollup.seedValidators.forEach(async (x) => {
|
|
16
|
+
const { pk, address, endpoint } = x;
|
|
17
|
+
try {
|
|
18
|
+
const account = await indexdb.account.get(address);
|
|
19
|
+
if (!account) return;
|
|
20
|
+
await indexdb.rollupValidator.insert({
|
|
21
|
+
rollup: rollup.address,
|
|
22
|
+
pk,
|
|
23
|
+
address,
|
|
24
|
+
endpoint,
|
|
25
|
+
moniker: account.moniker,
|
|
26
|
+
joinTime: rollup.genesisTime,
|
|
27
|
+
leaveTime: "",
|
|
28
|
+
genesisTime: account.genesisTime,
|
|
29
|
+
renaissanceTime: account.renaissanceTime,
|
|
30
|
+
totalStake: "0",
|
|
31
|
+
revokedStake: "0",
|
|
32
|
+
availableStake: "0",
|
|
33
|
+
totalGain: "0",
|
|
34
|
+
proposedBlockCount: 0,
|
|
35
|
+
verifiedBlockCount: 0,
|
|
36
|
+
latestBlockHeight: 0,
|
|
37
|
+
latestBlockHash: ""
|
|
38
|
+
});
|
|
39
|
+
debug$1("create rollup validator", address);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.error("create rollup validator error", err);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const ensureRollupValidator = async (address, rollupAddress, ctx, indexdb, upsert = true) => {
|
|
46
|
+
const doc = await indexdb.rollupValidator.get(address);
|
|
47
|
+
if (doc) {
|
|
48
|
+
doc.rollup = rollupAddress;
|
|
49
|
+
if (!doc.pk || !doc.endpoint) {
|
|
50
|
+
const validator$1 = (await indexdb.rollup.get(rollupAddress)).validators.find((v) => v.address === address);
|
|
51
|
+
doc.pk = validator$1.pk;
|
|
52
|
+
doc.endpoint = validator$1.endpoint;
|
|
53
|
+
await indexdb.rollupValidator.update(address, doc);
|
|
54
|
+
return doc;
|
|
55
|
+
}
|
|
56
|
+
return doc;
|
|
57
|
+
}
|
|
58
|
+
if (upsert === false) throw new Error("Rollup validator not found and upsert is disabled");
|
|
59
|
+
const stakeAddress = (0, _arcblock_did_util.toStakeAddress)(address, rollupAddress);
|
|
60
|
+
const [rollup, stake, account] = await Promise.all([
|
|
61
|
+
indexdb.rollup.get(rollupAddress),
|
|
62
|
+
indexdb.stake.get(stakeAddress),
|
|
63
|
+
indexdb.account.get(address)
|
|
64
|
+
]);
|
|
65
|
+
if (!stake || !account || !rollup) throw new Error("Required state not found for rollup validator");
|
|
66
|
+
const token = stake.tokens.find((t) => t.address === rollup.tokenAddress);
|
|
67
|
+
const validator = rollup.validators.find((v) => v.address === address);
|
|
68
|
+
debug$1("ensure rollup validator", {
|
|
69
|
+
txType: ctx.txType,
|
|
70
|
+
address,
|
|
71
|
+
rollupAddress,
|
|
72
|
+
validator,
|
|
73
|
+
token
|
|
74
|
+
});
|
|
75
|
+
return indexdb.rollupValidator.insert({
|
|
76
|
+
rollup: rollup.address,
|
|
77
|
+
address,
|
|
78
|
+
pk: validator ? validator.pk : "",
|
|
79
|
+
endpoint: validator ? validator.endpoint : "",
|
|
80
|
+
moniker: account.moniker,
|
|
81
|
+
joinTime: "",
|
|
82
|
+
leaveTime: "",
|
|
83
|
+
genesisTime: ctx.txState.time,
|
|
84
|
+
renaissanceTime: ctx.txState.time,
|
|
85
|
+
totalStake: token.balance,
|
|
86
|
+
revokedStake: "0",
|
|
87
|
+
availableStake: "0",
|
|
88
|
+
totalGain: "0",
|
|
89
|
+
proposedBlockCount: 0,
|
|
90
|
+
verifiedBlockCount: 0,
|
|
91
|
+
latestBlockHeight: 0,
|
|
92
|
+
latestBlockHash: ""
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const onCreateRollupBlock = (block, ctx, indexdb) => {
|
|
96
|
+
const { validators, proposer } = block;
|
|
97
|
+
const { rollupState, txStates } = ctx;
|
|
98
|
+
validators.forEach(async (address) => {
|
|
99
|
+
try {
|
|
100
|
+
const doc = await ensureRollupValidator(address, rollupState.address, ctx, indexdb);
|
|
101
|
+
doc.rollup = rollupState.address;
|
|
102
|
+
doc.renaissanceTime = block.genesisTime;
|
|
103
|
+
doc.verifiedBlockCount += 1;
|
|
104
|
+
if (address === proposer) {
|
|
105
|
+
doc.latestBlockHeight = block.height;
|
|
106
|
+
doc.latestBlockHash = block.hash;
|
|
107
|
+
doc.proposedBlockCount += 1;
|
|
108
|
+
}
|
|
109
|
+
await indexdb.rollupValidator.update(address, doc);
|
|
110
|
+
debug$1("update rollup validator on new block", address);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.error("update rollup validator error", err);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
if (Array.isArray(txStates)) txStates.filter((x) => x.type === "withdraw_token_v2").forEach(async (x) => {
|
|
116
|
+
try {
|
|
117
|
+
const updates = (0, lodash_merge.default)(await indexdb.tx.get(x.hash), (0, lodash_pick.default)(x, ["tx.itxJson.actualFee"]));
|
|
118
|
+
await indexdb.tx.update(x.hash, updates);
|
|
119
|
+
debug$1("update tx on new block", x.hash);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
console.error("update tx on new block error", err);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const updateRollupStats = async (address, value, key, indexdb) => {
|
|
126
|
+
try {
|
|
127
|
+
const doc = await indexdb.rollup.get(address);
|
|
128
|
+
if (!doc) return;
|
|
129
|
+
const rollupDoc = doc;
|
|
130
|
+
rollupDoc[key] = new _ocap_util.BN(rollupDoc[key] || "0").add(new _ocap_util.BN(value)).toString(10);
|
|
131
|
+
await indexdb.rollup.update(address, doc);
|
|
132
|
+
debug$1("update rollup", address);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
console.error("update rollup error", err);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const onDepositTokenV2 = async (tx, ctx, indexdb) => {
|
|
138
|
+
const { signatures } = tx.tx;
|
|
139
|
+
const { rollupState } = ctx;
|
|
140
|
+
signatures.forEach(async ({ signer: address }) => {
|
|
141
|
+
try {
|
|
142
|
+
const doc = await ensureRollupValidator(address, rollupState.address, ctx, indexdb);
|
|
143
|
+
doc.renaissanceTime = tx.time;
|
|
144
|
+
await indexdb.rollupValidator.update(address, doc);
|
|
145
|
+
debug$1("update rollup validator on deposit", address);
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.error("update rollup validator error", err);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const amount = new _ocap_util.BN(tx.tx.itxJson.token.value).add(new _ocap_util.BN(tx.tx.itxJson.actualFee));
|
|
151
|
+
await updateRollupStats(ctx.rollupState.address, amount.toString(), "totalDepositAmount", indexdb);
|
|
152
|
+
};
|
|
153
|
+
const onClaimBlockReward = async (tx, ctx, indexdb) => {
|
|
154
|
+
const { rollupState, blockState } = ctx;
|
|
155
|
+
const { signatures } = blockState;
|
|
156
|
+
await Promise.all(signatures.map(async ({ signer }) => {
|
|
157
|
+
try {
|
|
158
|
+
const doc = await ensureRollupValidator(signer, rollupState.address, ctx, indexdb);
|
|
159
|
+
const receipt = tx.receipts.find((x) => x.address === signer);
|
|
160
|
+
if (receipt) {
|
|
161
|
+
const change = receipt.changes.find((x) => x.target === rollupState.tokenAddress && new _ocap_util.BN(x.value).isNeg() === false);
|
|
162
|
+
doc.totalGain = new _ocap_util.BN(doc.totalGain).add(new _ocap_util.BN(change.value).abs()).toString(10);
|
|
163
|
+
await indexdb.rollupValidator.update(signer, doc);
|
|
164
|
+
debug$1("update rollup validator on claim reward", signer);
|
|
165
|
+
}
|
|
166
|
+
} catch (err) {
|
|
167
|
+
console.error("update rollup validator on claim reward error", err);
|
|
168
|
+
}
|
|
169
|
+
}));
|
|
170
|
+
};
|
|
171
|
+
const onJoinRollup = async (tx, ctx, indexdb) => {
|
|
172
|
+
try {
|
|
173
|
+
const address = tx.tx.from;
|
|
174
|
+
const doc = await ensureRollupValidator(address, tx.tx.itxJson.rollup, ctx, indexdb);
|
|
175
|
+
doc.endpoint = tx.tx.itxJson.endpoint;
|
|
176
|
+
doc.joinTime = tx.time;
|
|
177
|
+
doc.renaissanceTime = tx.time;
|
|
178
|
+
doc.leaveTime = "";
|
|
179
|
+
await indexdb.rollupValidator.update(address, doc);
|
|
180
|
+
debug$1("join rollup validator", address);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
console.error("join rollup validator error", err);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const onLeaveRollup = async (tx, ctx, indexdb) => {
|
|
186
|
+
try {
|
|
187
|
+
const address = tx.tx.from;
|
|
188
|
+
const doc = await ensureRollupValidator(address, tx.tx.itxJson.rollup, ctx, indexdb);
|
|
189
|
+
doc.leaveTime = tx.time;
|
|
190
|
+
doc.renaissanceTime = tx.time;
|
|
191
|
+
doc.rollup = "";
|
|
192
|
+
await indexdb.rollupValidator.update(address, doc);
|
|
193
|
+
debug$1("leave rollup validator", address);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
console.error("leave rollup validator error", err);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const onStake = async (tx, ctx, indexdb) => {
|
|
199
|
+
try {
|
|
200
|
+
const rollup = await indexdb.rollup.get(tx.tx.itxJson.receiver);
|
|
201
|
+
if (!rollup) return;
|
|
202
|
+
const address = tx.tx.from;
|
|
203
|
+
if (rollup.validators.find((x) => x.address === address) === void 0) return;
|
|
204
|
+
const stakeAddress = (0, _arcblock_did_util.toStakeAddress)(address, rollup.address);
|
|
205
|
+
const doc = await ensureRollupValidator(address, rollup.address, ctx, indexdb);
|
|
206
|
+
const change = ctx.txState.receipts.find((x) => x.address === stakeAddress).changes.find((x) => x.target === rollup.tokenAddress);
|
|
207
|
+
doc.totalStake = new _ocap_util.BN(doc.totalStake).add(new _ocap_util.BN(change.value).abs()).toString(10);
|
|
208
|
+
doc.renaissanceTime = tx.time;
|
|
209
|
+
await indexdb.rollupValidator.update(address, doc);
|
|
210
|
+
debug$1("stake rollup validator", address);
|
|
211
|
+
} catch (err) {
|
|
212
|
+
console.error("stake rollup validator error", err);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const onClaimStake = async (tx, ctx, indexdb) => {
|
|
216
|
+
try {
|
|
217
|
+
const stake = await indexdb.stake.get(tx.tx.itxJson.address);
|
|
218
|
+
if (!stake) return;
|
|
219
|
+
const rollup = await indexdb.rollup.get(stake.receiver);
|
|
220
|
+
if (!rollup) return;
|
|
221
|
+
const address = tx.tx.from;
|
|
222
|
+
const doc = await ensureRollupValidator(address, rollup.address, ctx, indexdb, false);
|
|
223
|
+
const change = ctx.txState.receipts.find((x) => x.address === stake.address).changes.find((x) => x.target === rollup.tokenAddress);
|
|
224
|
+
doc.renaissanceTime = tx.time;
|
|
225
|
+
doc.totalStake = new _ocap_util.BN(doc.totalStake).sub(new _ocap_util.BN(change.value).abs()).toString(10);
|
|
226
|
+
doc.revokedStake = new _ocap_util.BN(doc.revokedStake).add(new _ocap_util.BN(change.value).abs()).toString(10);
|
|
227
|
+
await indexdb.rollupValidator.update(address, doc);
|
|
228
|
+
debug$1("claim-stake rollup validator", address);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
console.error("claim-stake rollup validator error", err);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const onAccountMigrate = async (_tx, resolver) => {
|
|
234
|
+
try {
|
|
235
|
+
await resolver.buildMigrationChain();
|
|
236
|
+
} catch (e) {
|
|
237
|
+
console.error("build migration chain error", e);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const onUpdateToken = (tokenDoc, _ctx, _indexdb, resolver) => {
|
|
241
|
+
if (resolver.tokenCache) resolver.tokenCache.set(tokenDoc.address, tokenDoc);
|
|
242
|
+
};
|
|
243
|
+
const onCreateTx = async (tx, ctx, resolver) => {
|
|
244
|
+
try {
|
|
245
|
+
await resolver.tokenDistribution.updateByTx(tx, ctx);
|
|
246
|
+
} catch (e) {
|
|
247
|
+
resolver.logger.error("Failed to update token distribution", {
|
|
248
|
+
error: e,
|
|
249
|
+
tx,
|
|
250
|
+
ctx
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (tx.code !== "OK") return;
|
|
254
|
+
const { indexdb } = resolver;
|
|
255
|
+
switch (tx.tx.itxJson.type_url) {
|
|
256
|
+
case "fg:t:stake": return onStake(tx, ctx, indexdb);
|
|
257
|
+
case "fg:t:claim_stake": return onClaimStake(tx, ctx, indexdb);
|
|
258
|
+
case "fg:t:join_rollup": return onJoinRollup(tx, ctx, indexdb);
|
|
259
|
+
case "fg:t:leave_rollup": return onLeaveRollup(tx, ctx, indexdb);
|
|
260
|
+
case "fg:t:deposit_token_v2": return onDepositTokenV2(tx, ctx, indexdb);
|
|
261
|
+
case "fg:t:claim_block_reward":
|
|
262
|
+
await onClaimBlockReward(tx, ctx, indexdb);
|
|
263
|
+
return;
|
|
264
|
+
case "fg:t:withdraw_token_v2": return updateRollupStats(ctx.rollupState.address, tx.tx.itxJson.token.value, "totalWithdrawAmount", indexdb);
|
|
265
|
+
case "fg:t:account_migrate": return onAccountMigrate(tx, resolver);
|
|
266
|
+
default:
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
//#endregion
|
|
271
|
+
exports.onCreateRollup = onCreateRollup;
|
|
272
|
+
exports.onCreateRollupBlock = onCreateRollupBlock;
|
|
273
|
+
exports.onCreateTx = onCreateTx;
|
|
274
|
+
exports.onUpdateToken = onUpdateToken;
|
package/lib/hooks.d.cts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { IIndexDB, IIndexTable, IPipelineLogger, IRollupValidator, ITokenCache, TIndexedAccountState, TIndexedRollupState, TIndexedRollupValidator, TIndexedStakeState, TIndexedTransaction, TTransactionReceipt } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Rollup state for hooks (subset of TIndexedRollupState)
|
|
7
|
+
*/
|
|
8
|
+
interface IHooksRollupState {
|
|
9
|
+
address: string;
|
|
10
|
+
tokenAddress: string;
|
|
11
|
+
genesisTime: string;
|
|
12
|
+
seedValidators: IRollupValidator[];
|
|
13
|
+
validators: IRollupValidator[];
|
|
14
|
+
totalDepositAmount?: string;
|
|
15
|
+
totalWithdrawAmount?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Token balance in array format
|
|
19
|
+
*/
|
|
20
|
+
interface ITokenBalance {
|
|
21
|
+
address: string;
|
|
22
|
+
balance: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Stake state for hooks (with array-format tokens)
|
|
26
|
+
*/
|
|
27
|
+
interface IHooksStakeState {
|
|
28
|
+
address: string;
|
|
29
|
+
receiver: string;
|
|
30
|
+
tokens: ITokenBalance[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Transaction state in context
|
|
34
|
+
*/
|
|
35
|
+
interface ITxState {
|
|
36
|
+
time: string;
|
|
37
|
+
receipts: TTransactionReceipt[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hook context passed to handlers
|
|
41
|
+
*/
|
|
42
|
+
interface IHooksContext {
|
|
43
|
+
txType?: string;
|
|
44
|
+
txState?: ITxState;
|
|
45
|
+
rollupState?: {
|
|
46
|
+
address: string;
|
|
47
|
+
tokenAddress?: string;
|
|
48
|
+
};
|
|
49
|
+
blockState?: {
|
|
50
|
+
signatures: Array<{
|
|
51
|
+
signer: string;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
stateSnapshot?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Transaction for hooks
|
|
58
|
+
*/
|
|
59
|
+
interface IHooksTx {
|
|
60
|
+
code: string;
|
|
61
|
+
hash: string;
|
|
62
|
+
time: string;
|
|
63
|
+
receipts?: TTransactionReceipt[];
|
|
64
|
+
tx: {
|
|
65
|
+
from: string;
|
|
66
|
+
signatures?: Array<{
|
|
67
|
+
signer: string;
|
|
68
|
+
}>;
|
|
69
|
+
itxJson: {
|
|
70
|
+
type_url: string;
|
|
71
|
+
address?: string;
|
|
72
|
+
receiver?: string;
|
|
73
|
+
rollup?: string;
|
|
74
|
+
endpoint?: string;
|
|
75
|
+
token?: {
|
|
76
|
+
value: string;
|
|
77
|
+
};
|
|
78
|
+
actualFee?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Block for rollup block hooks
|
|
84
|
+
*/
|
|
85
|
+
interface IHooksBlock {
|
|
86
|
+
hash: string;
|
|
87
|
+
height: number;
|
|
88
|
+
genesisTime: string;
|
|
89
|
+
validators: string[];
|
|
90
|
+
proposer: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Block context for rollup block hooks
|
|
94
|
+
*/
|
|
95
|
+
interface IHooksBlockContext {
|
|
96
|
+
rollupState: {
|
|
97
|
+
address: string;
|
|
98
|
+
};
|
|
99
|
+
txStates: Array<{
|
|
100
|
+
type: string;
|
|
101
|
+
hash: string;
|
|
102
|
+
tx: {
|
|
103
|
+
itxJson: {
|
|
104
|
+
actualFee: string;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
}>;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* IndexDB interface for hooks (specialized tables)
|
|
111
|
+
*/
|
|
112
|
+
interface IHooksIndexDB extends IIndexDB {
|
|
113
|
+
account: IIndexTable<TIndexedAccountState> & {
|
|
114
|
+
get(address: string): Promise<TIndexedAccountState>;
|
|
115
|
+
};
|
|
116
|
+
rollup: IIndexTable<TIndexedRollupState> & {
|
|
117
|
+
get(address: string): Promise<IHooksRollupState | null>;
|
|
118
|
+
update(address: string, doc: unknown): Promise<void>;
|
|
119
|
+
};
|
|
120
|
+
rollupValidator: IIndexTable<TIndexedRollupValidator> & {
|
|
121
|
+
get(address: string): Promise<TIndexedRollupValidator | null>;
|
|
122
|
+
insert(doc: TIndexedRollupValidator): Promise<TIndexedRollupValidator>;
|
|
123
|
+
update(address: string, doc: TIndexedRollupValidator): Promise<void>;
|
|
124
|
+
};
|
|
125
|
+
stake: IIndexTable<TIndexedStakeState> & {
|
|
126
|
+
get(address: string): Promise<IHooksStakeState>;
|
|
127
|
+
};
|
|
128
|
+
tx: IIndexTable<TIndexedTransaction> & {
|
|
129
|
+
get(hash: string): Promise<unknown>;
|
|
130
|
+
update(hash: string, updates: unknown): Promise<void>;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Resolver interface for hooks
|
|
135
|
+
*/
|
|
136
|
+
interface IHooksResolver {
|
|
137
|
+
indexdb: IHooksIndexDB;
|
|
138
|
+
logger: IPipelineLogger;
|
|
139
|
+
tokenDistribution: {
|
|
140
|
+
updateByTx: (tx: IHooksTx, ctx: IHooksContext) => Promise<void>;
|
|
141
|
+
};
|
|
142
|
+
buildMigrationChain: () => Promise<void>;
|
|
143
|
+
tokenCache?: ITokenCache;
|
|
144
|
+
}
|
|
145
|
+
declare const onCreateRollup: (rollup: IHooksRollupState, _ctx: unknown, indexdb: IHooksIndexDB) => void;
|
|
146
|
+
declare const onCreateRollupBlock: (block: IHooksBlock, ctx: IHooksBlockContext, indexdb: IHooksIndexDB) => void;
|
|
147
|
+
declare const onUpdateToken: (tokenDoc: {
|
|
148
|
+
address: string;
|
|
149
|
+
[key: string]: unknown;
|
|
150
|
+
}, _ctx: unknown, _indexdb: unknown, resolver: IHooksResolver) => void;
|
|
151
|
+
declare const onCreateTx: (tx: IHooksTx, ctx: IHooksContext, resolver: IHooksResolver) => Promise<void>;
|
|
152
|
+
//#endregion
|
|
153
|
+
export { onCreateRollup, onCreateRollupBlock, onCreateTx, onUpdateToken };
|