@ocap/types 1.28.9 → 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/index.d.ts +23 -1
- package/interfaces/base.ts +38 -0
- package/interfaces/config.ts +166 -0
- package/interfaces/index.ts +254 -0
- package/interfaces/indexdb.ts +444 -0
- package/interfaces/pipeline.ts +525 -0
- package/interfaces/resolver.ts +503 -0
- package/interfaces/state.ts +327 -0
- package/interfaces/statedb.ts +193 -0
- package/interfaces/testing.ts +122 -0
- package/lib/enum_pb.d.ts +0 -3
- package/lib/rpc_pb.d.ts +0 -1591
- package/lib/service_pb.d.ts +0 -2
- package/lib/state_pb.d.ts +0 -840
- package/lib/trace-type_pb.d.ts +0 -1304
- package/lib/tx_pb.d.ts +0 -1687
- package/lib/type_pb.d.ts +0 -1781
- package/lib/vendor_pb.d.ts +0 -406
- package/package.json +10 -4
- package/tests/interfaces-reexport.spec.ts +76 -0
- package/tests/interfaces.spec.ts +265 -0
- package/tests/pipeline.spec.ts +249 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// core/types/interfaces/state.ts
|
|
2
|
+
// State interfaces that extend Proto T*State types for local storage format
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
TAccountState,
|
|
6
|
+
TAssetFactoryState,
|
|
7
|
+
TAssetState,
|
|
8
|
+
TDelegateState,
|
|
9
|
+
TEvidenceState,
|
|
10
|
+
TRollupBlock,
|
|
11
|
+
TRollupState,
|
|
12
|
+
TStakeState,
|
|
13
|
+
TTokenFactoryState,
|
|
14
|
+
TTokenState,
|
|
15
|
+
} from '../lib/state_pb';
|
|
16
|
+
import type { TCreateAssetTx } from '../lib/tx_pb';
|
|
17
|
+
import type {
|
|
18
|
+
TAssetFactoryHook,
|
|
19
|
+
TIndexedFactoryInput,
|
|
20
|
+
TNFTDisplay,
|
|
21
|
+
TNFTEndpoint,
|
|
22
|
+
TStateContext,
|
|
23
|
+
TVariableInput,
|
|
24
|
+
} from '../lib/type_pb';
|
|
25
|
+
|
|
26
|
+
/** Storage format with ISO 8601 string timestamps */
|
|
27
|
+
export interface IStateContext extends Omit<TStateContext, 'genesisTime' | 'renaissanceTime'> {
|
|
28
|
+
genesisTime: string;
|
|
29
|
+
renaissanceTime: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IStateContextInput {
|
|
33
|
+
txHash?: string;
|
|
34
|
+
txTime?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IState {
|
|
38
|
+
address: string;
|
|
39
|
+
context?: IStateContext;
|
|
40
|
+
/** Protobuf google.protobuf.Any - structure varies by state type */
|
|
41
|
+
data?: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IStateWithOwner extends IState {
|
|
45
|
+
owner: string;
|
|
46
|
+
issuer: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type StateChangeType = 'create' | 'update' | 'delete';
|
|
50
|
+
|
|
51
|
+
/** State kind for change events - named to avoid conflict with StateType enum from enum_pb */
|
|
52
|
+
export type StateKind =
|
|
53
|
+
| 'account'
|
|
54
|
+
| 'asset'
|
|
55
|
+
| 'token'
|
|
56
|
+
| 'token-factory'
|
|
57
|
+
| 'asset-factory'
|
|
58
|
+
| 'stake'
|
|
59
|
+
| 'delegation'
|
|
60
|
+
| 'rollup'
|
|
61
|
+
| 'rollup-block'
|
|
62
|
+
| 'evidence';
|
|
63
|
+
|
|
64
|
+
export interface IStateChangeEvent<T extends IState = IState> {
|
|
65
|
+
type: StateChangeType;
|
|
66
|
+
stateType: StateKind;
|
|
67
|
+
address: string;
|
|
68
|
+
before?: T;
|
|
69
|
+
after?: T;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ============ Extended State Interfaces ============
|
|
73
|
+
|
|
74
|
+
/** Token balance map: tokenAddress -> amount */
|
|
75
|
+
export type TokenBalanceMap = Record<string, string>;
|
|
76
|
+
|
|
77
|
+
/** tokens: Record instead of Array<TIndexedTokenInput>, nonce: number instead of string */
|
|
78
|
+
export interface IAccountState
|
|
79
|
+
extends Omit<
|
|
80
|
+
TAccountState,
|
|
81
|
+
'tokens' | 'nonce' | 'context' | 'balance' | 'gasBalance' | 'type' | 'numTxs' | 'numAssets' | 'data'
|
|
82
|
+
> {
|
|
83
|
+
tokens: TokenBalanceMap;
|
|
84
|
+
nonce: number;
|
|
85
|
+
context: IStateContext;
|
|
86
|
+
/** Protobuf google.protobuf.Any - structure varies by account type */
|
|
87
|
+
data?: unknown;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** consumedTime: string (ISO 8601), endpoint/display with proper types */
|
|
91
|
+
export interface IAssetState extends Omit<TAssetState, 'consumedTime' | 'endpoint' | 'display' | 'context' | 'data'> {
|
|
92
|
+
consumedTime: string;
|
|
93
|
+
/** NFT endpoint - simplified to string (endpoint.id) in storage, or full object */
|
|
94
|
+
endpoint?: string | TNFTEndpoint | null;
|
|
95
|
+
/** NFT display metadata */
|
|
96
|
+
display?: TNFTDisplay | null;
|
|
97
|
+
context: IStateContext;
|
|
98
|
+
/** Protobuf google.protobuf.Any - application-specific asset data */
|
|
99
|
+
data?: unknown;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface IForeignToken {
|
|
103
|
+
contractAddress: string;
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ITokenMetadata {
|
|
108
|
+
type: 'json';
|
|
109
|
+
value?: {
|
|
110
|
+
communityUrl?: string | null;
|
|
111
|
+
issuer: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** foreignToken/metadata simplified, optional fields with null support */
|
|
116
|
+
export interface ITokenState
|
|
117
|
+
extends Omit<
|
|
118
|
+
TTokenState,
|
|
119
|
+
| 'foreignToken'
|
|
120
|
+
| 'metadata'
|
|
121
|
+
| 'context'
|
|
122
|
+
| 'data'
|
|
123
|
+
| 'icon'
|
|
124
|
+
| 'maxTotalSupply'
|
|
125
|
+
| 'issuer'
|
|
126
|
+
| 'website'
|
|
127
|
+
| 'tokenFactoryAddress'
|
|
128
|
+
| 'spenders'
|
|
129
|
+
| 'minters'
|
|
130
|
+
| 'type'
|
|
131
|
+
> {
|
|
132
|
+
foreignToken?: IForeignToken | null;
|
|
133
|
+
metadata?: ITokenMetadata | null;
|
|
134
|
+
icon?: string | null;
|
|
135
|
+
maxTotalSupply?: string | null;
|
|
136
|
+
issuer?: string | null;
|
|
137
|
+
website?: string | null;
|
|
138
|
+
tokenFactoryAddress?: string | null;
|
|
139
|
+
spenders?: string[] | null;
|
|
140
|
+
minters?: string[] | null;
|
|
141
|
+
type?: 'Token' | 'CreditToken' | 'BondingCurveToken' | null;
|
|
142
|
+
context: IStateContext;
|
|
143
|
+
/** Protobuf google.protobuf.Any - structure varies by token type */
|
|
144
|
+
data?: unknown;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Extends TAssetFactoryHook with compiled field for contract hooks */
|
|
148
|
+
export interface IFactoryHook extends TAssetFactoryHook {
|
|
149
|
+
/** Compiled contract calls when type is 'contract' - structure varies by call type */
|
|
150
|
+
compiled?: unknown[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Factory input - extends TIndexedFactoryInput, tokens simplified to address+value */
|
|
154
|
+
export interface IFactoryInput extends Omit<TIndexedFactoryInput, 'tokens' | 'variables'> {
|
|
155
|
+
/** Additional token requirements (without decimal/unit/symbol metadata) */
|
|
156
|
+
tokens?: Array<{ address: string; value: string }>;
|
|
157
|
+
/** Variable definitions (description optional in storage) */
|
|
158
|
+
variables?: Array<Omit<TVariableInput, 'value' | 'description'> & { description?: string }>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** tokens: Record, hooks: IFactoryHook[], lastSettlement: string (ISO 8601) */
|
|
162
|
+
export interface IAssetFactoryState
|
|
163
|
+
extends Omit<
|
|
164
|
+
TAssetFactoryState,
|
|
165
|
+
| 'tokens'
|
|
166
|
+
| 'hooks'
|
|
167
|
+
| 'lastSettlement'
|
|
168
|
+
| 'input'
|
|
169
|
+
| 'output'
|
|
170
|
+
| 'display'
|
|
171
|
+
| 'context'
|
|
172
|
+
| 'data'
|
|
173
|
+
| 'balance'
|
|
174
|
+
| 'settlement'
|
|
175
|
+
| 'limit'
|
|
176
|
+
> {
|
|
177
|
+
tokens: TokenBalanceMap;
|
|
178
|
+
hooks?: IFactoryHook[];
|
|
179
|
+
lastSettlement: string;
|
|
180
|
+
/** Factory input - tokens/assets required to mint */
|
|
181
|
+
input?: IFactoryInput;
|
|
182
|
+
/** Factory output template for minted assets */
|
|
183
|
+
output?: TCreateAssetTx;
|
|
184
|
+
/** Display metadata for the factory itself */
|
|
185
|
+
display?: TNFTDisplay | null;
|
|
186
|
+
/** Settlement mode: 'instant' settles immediately, 'periodic' batches settlements */
|
|
187
|
+
settlement?: 'instant' | 'periodic';
|
|
188
|
+
/** Max number of assets that can be minted, 0 means unlimited */
|
|
189
|
+
limit?: number;
|
|
190
|
+
context: IStateContext;
|
|
191
|
+
/** Protobuf google.protobuf.Any - application-specific data */
|
|
192
|
+
data?: unknown;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** tokens/revokedTokens: Record instead of Array */
|
|
196
|
+
export interface IStakeState extends Omit<TStakeState, 'tokens' | 'revokedTokens' | 'context' | 'data'> {
|
|
197
|
+
tokens: TokenBalanceMap;
|
|
198
|
+
revokedTokens: TokenBalanceMap;
|
|
199
|
+
context: IStateContext;
|
|
200
|
+
/** Protobuf google.protobuf.Any - structure varies by stake type */
|
|
201
|
+
data?: unknown;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Token limit in delegation ops */
|
|
205
|
+
export interface IDelegationTokenLimit {
|
|
206
|
+
address: string;
|
|
207
|
+
toList?: string[];
|
|
208
|
+
txCount?: number;
|
|
209
|
+
txAllowance?: string;
|
|
210
|
+
totalAllowance?: string;
|
|
211
|
+
validUntil?: number;
|
|
212
|
+
rate?: { interval: number; anchor?: number } | null;
|
|
213
|
+
txSent?: number;
|
|
214
|
+
lastTx?: number;
|
|
215
|
+
spentAllowance?: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Asset limit in delegation ops */
|
|
219
|
+
export interface IDelegationAssetLimit {
|
|
220
|
+
address?: string[];
|
|
221
|
+
toList?: string[];
|
|
222
|
+
txCount?: number;
|
|
223
|
+
validUntil?: number;
|
|
224
|
+
rate?: { interval: number; anchor?: number } | null;
|
|
225
|
+
txSent?: number;
|
|
226
|
+
lastTx?: number;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Operation limit in delegation */
|
|
230
|
+
export interface IDelegationOpLimit {
|
|
231
|
+
tokens?: IDelegationTokenLimit[];
|
|
232
|
+
assets?: IDelegationAssetLimit[];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Delegation ops: typeUrl -> operation with limits */
|
|
236
|
+
export type IDelegationOps = Record<string, { limit: IDelegationOpLimit }>;
|
|
237
|
+
|
|
238
|
+
/** ops: IDelegationOps instead of opsMap */
|
|
239
|
+
export interface IDelegateState extends Omit<TDelegateState, 'opsMap' | 'context' | 'data'> {
|
|
240
|
+
ops?: IDelegationOps | null;
|
|
241
|
+
context: IStateContext;
|
|
242
|
+
/** Protobuf google.protobuf.Any - structure varies by delegation type */
|
|
243
|
+
data?: unknown;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface IRollupValidator {
|
|
247
|
+
pk: string;
|
|
248
|
+
address: string;
|
|
249
|
+
endpoint: string;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** validators: IRollupValidator[], optional fields with null support */
|
|
253
|
+
export interface IRollupState
|
|
254
|
+
extends Omit<
|
|
255
|
+
TRollupState,
|
|
256
|
+
| 'seedValidators'
|
|
257
|
+
| 'validators'
|
|
258
|
+
| 'context'
|
|
259
|
+
| 'data'
|
|
260
|
+
| 'vaultAddress'
|
|
261
|
+
| 'blockHash'
|
|
262
|
+
| 'issuer'
|
|
263
|
+
| 'tokenInfo'
|
|
264
|
+
| 'totalDepositAmount'
|
|
265
|
+
| 'totalWithdrawAmount'
|
|
266
|
+
| 'foreignToken'
|
|
267
|
+
> {
|
|
268
|
+
seedValidators: IRollupValidator[];
|
|
269
|
+
validators: IRollupValidator[];
|
|
270
|
+
vaultAddress?: string | null;
|
|
271
|
+
blockHash?: string | null;
|
|
272
|
+
issuer?: string | null;
|
|
273
|
+
context: IStateContext;
|
|
274
|
+
/** Protobuf google.protobuf.Any - structure varies by rollup type */
|
|
275
|
+
data?: unknown;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Signature data for rollup blocks */
|
|
279
|
+
export interface IBlockSignature {
|
|
280
|
+
signer: string;
|
|
281
|
+
pk?: string | Uint8Array;
|
|
282
|
+
signature?: string | Uint8Array;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** address: alias for hash (StateDB key), signatures: IBlockSignature[] */
|
|
286
|
+
export interface IRollupBlock
|
|
287
|
+
extends Omit<
|
|
288
|
+
TRollupBlock,
|
|
289
|
+
'signatures' | 'context' | 'data' | 'previousHash' | 'mintedAmount' | 'burnedAmount' | 'rewardAmount'
|
|
290
|
+
> {
|
|
291
|
+
address: string;
|
|
292
|
+
signatures: IBlockSignature[];
|
|
293
|
+
previousHash?: string | null;
|
|
294
|
+
mintedAmount?: string | null;
|
|
295
|
+
burnedAmount?: string | null;
|
|
296
|
+
rewardAmount?: string | null;
|
|
297
|
+
context: IStateContext;
|
|
298
|
+
/** Protobuf google.protobuf.Any - structure varies by block type */
|
|
299
|
+
data?: unknown;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** address: alias for hash (StateDB key) */
|
|
303
|
+
export interface IEvidenceState extends Omit<TEvidenceState, 'context' | 'data'> {
|
|
304
|
+
address: string;
|
|
305
|
+
context: IStateContext;
|
|
306
|
+
/** Protobuf google.protobuf.Any - structure varies by evidence type */
|
|
307
|
+
data?: unknown;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export interface ITokenFactoryCurve {
|
|
311
|
+
type: 'linear' | 'constant' | 'quadratic';
|
|
312
|
+
basePrice?: string;
|
|
313
|
+
slope?: string;
|
|
314
|
+
fixedPrice?: string;
|
|
315
|
+
constant?: number;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** owner instead of ownerAddress, status: string instead of enum */
|
|
319
|
+
export interface ITokenFactoryState
|
|
320
|
+
extends Omit<TTokenFactoryState, 'ownerAddress' | 'status' | 'curve' | 'context' | 'token' | 'reserveToken'> {
|
|
321
|
+
owner: string;
|
|
322
|
+
status: 'ACTIVE' | 'PAUSED';
|
|
323
|
+
curve?: ITokenFactoryCurve | null;
|
|
324
|
+
context: IStateContext;
|
|
325
|
+
/** Protobuf google.protobuf.Any - structure varies by token factory type */
|
|
326
|
+
data?: unknown;
|
|
327
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// core/types/interfaces/statedb.ts
|
|
2
|
+
|
|
3
|
+
import type { EventEmitter } from 'node:events';
|
|
4
|
+
|
|
5
|
+
import type { TTransactionReceipt } from '../lib/type_pb';
|
|
6
|
+
import type { Promisable } from './base';
|
|
7
|
+
import type {
|
|
8
|
+
IAccountState,
|
|
9
|
+
IAssetFactoryState,
|
|
10
|
+
IAssetState,
|
|
11
|
+
IDelegateState,
|
|
12
|
+
IEvidenceState,
|
|
13
|
+
IRollupBlock,
|
|
14
|
+
IRollupState,
|
|
15
|
+
IStakeState,
|
|
16
|
+
IStateContext,
|
|
17
|
+
ITokenFactoryState,
|
|
18
|
+
ITokenState,
|
|
19
|
+
} from './state';
|
|
20
|
+
|
|
21
|
+
/** Hook function type - args can be any type depending on hook trigger */
|
|
22
|
+
export type HookFunction = (...args: unknown[]) => void;
|
|
23
|
+
|
|
24
|
+
/** Operation context - index signature allows for protocol-specific context data */
|
|
25
|
+
export interface IOperationContext {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Chain token configuration stored in chain state */
|
|
30
|
+
export interface IChainTokenInfo {
|
|
31
|
+
symbol?: string;
|
|
32
|
+
decimal?: number;
|
|
33
|
+
name?: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
unit?: string;
|
|
36
|
+
totalSupply?: string;
|
|
37
|
+
initialSupply?: string;
|
|
38
|
+
address?: string;
|
|
39
|
+
foreignToken?: { contractAddress?: string; chainId?: number } | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IChainState {
|
|
43
|
+
address: string;
|
|
44
|
+
chainId: string;
|
|
45
|
+
version?: string;
|
|
46
|
+
accounts?: Array<{ address: string; pk?: string; balance?: number; moniker?: string }>;
|
|
47
|
+
moderator?: { address: string; pk?: string };
|
|
48
|
+
token?: IChainTokenInfo;
|
|
49
|
+
transaction?: Record<string, unknown>;
|
|
50
|
+
vaults?: { txGas?: string[]; txFee?: string[] };
|
|
51
|
+
context?: IStateContext;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Transaction data stored in tx state */
|
|
55
|
+
export interface ITxData {
|
|
56
|
+
chainId?: string;
|
|
57
|
+
delegator?: string;
|
|
58
|
+
from?: string;
|
|
59
|
+
nonce?: number;
|
|
60
|
+
serviceFee?: string;
|
|
61
|
+
gasFee?: string;
|
|
62
|
+
gasPaid?: string;
|
|
63
|
+
pk?: string;
|
|
64
|
+
signature?: string;
|
|
65
|
+
signatures?: Array<{ signer?: string; delegator?: string; pk?: string; signature?: string }>;
|
|
66
|
+
itx?: { __typename?: string; typeUrl?: string };
|
|
67
|
+
itxJson?: Record<string, unknown>;
|
|
68
|
+
/** Extra transaction data - format varies by transaction source */
|
|
69
|
+
extra?: unknown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ITxState {
|
|
73
|
+
hash: string;
|
|
74
|
+
code?: string;
|
|
75
|
+
height?: number;
|
|
76
|
+
index?: number;
|
|
77
|
+
receipts?: TTransactionReceipt[];
|
|
78
|
+
receiptsVerified?: boolean;
|
|
79
|
+
receiver?: string;
|
|
80
|
+
sender?: string;
|
|
81
|
+
time?: string;
|
|
82
|
+
tx?: ITxData;
|
|
83
|
+
type?: string;
|
|
84
|
+
finalized?: boolean;
|
|
85
|
+
valid?: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface IBalanceState {
|
|
89
|
+
address: string;
|
|
90
|
+
tokenAddress: string;
|
|
91
|
+
balance: string;
|
|
92
|
+
context?: IStateContext;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type StateEventHandler<T> = (state: T, ctx?: IOperationContext) => void | Promise<void>;
|
|
96
|
+
|
|
97
|
+
export interface IStateTable<T = unknown> {
|
|
98
|
+
name: string;
|
|
99
|
+
primaryKey: string;
|
|
100
|
+
uniqIndex?: string | string[];
|
|
101
|
+
|
|
102
|
+
create(id: string, attrs: Partial<T>, context?: IOperationContext): Promisable<T>;
|
|
103
|
+
get(id: string, context?: IOperationContext): Promisable<T | null>;
|
|
104
|
+
update(id: string, updates: Partial<T>, context?: IOperationContext): Promisable<T>;
|
|
105
|
+
updateOrCreate(exist: T | null, state: Partial<T>, context?: IOperationContext): Promisable<T>;
|
|
106
|
+
history(id: string, context?: IOperationContext): Promisable<T[]>;
|
|
107
|
+
reset(context?: IOperationContext): Promisable<void>;
|
|
108
|
+
|
|
109
|
+
pre(name: string, fn: HookFunction): void;
|
|
110
|
+
post(name: string, fn: HookFunction): void;
|
|
111
|
+
on(event: 'create' | 'update', handler: StateEventHandler<T>): void;
|
|
112
|
+
emit(event: 'create' | 'update', state: T, ctx?: IOperationContext): void;
|
|
113
|
+
|
|
114
|
+
generatePrimaryKey(doc: string | Record<string, unknown>): string;
|
|
115
|
+
updateCache(data: Record<string, unknown>, context: IOperationContext | null | undefined): void;
|
|
116
|
+
getCache(key: string | Record<string, unknown>, context: IOperationContext): T | null;
|
|
117
|
+
|
|
118
|
+
markReady(): void;
|
|
119
|
+
onReady(cb: () => void): void;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface IBalanceTable extends IStateTable<IBalanceState> {
|
|
123
|
+
getBalance(address: string, context?: IOperationContext): Promisable<Record<string, string>>;
|
|
124
|
+
updateBalance(
|
|
125
|
+
params: { address: string; tokens: Record<string, string>; context?: IOperationContext },
|
|
126
|
+
context?: IOperationContext
|
|
127
|
+
): Promisable<Record<string, string>>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ITokenTable extends IStateTable<ITokenState> {
|
|
131
|
+
existBySymbol(symbol: string, context?: IOperationContext): Promisable<boolean>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface IRollupTable extends IStateTable<IRollupState> {
|
|
135
|
+
existByToken(token: string, context?: IOperationContext): Promisable<boolean>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface IReady extends EventEmitter {
|
|
139
|
+
ready: boolean;
|
|
140
|
+
readyCallbacks: Array<() => void>;
|
|
141
|
+
readyMarks: Record<string, boolean>;
|
|
142
|
+
markReady(mark?: string): void;
|
|
143
|
+
onReady(cb: () => void): void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Table names available in IStateDB */
|
|
147
|
+
export type StateDBTableName =
|
|
148
|
+
| 'chain'
|
|
149
|
+
| 'account'
|
|
150
|
+
| 'asset'
|
|
151
|
+
| 'token'
|
|
152
|
+
| 'tx'
|
|
153
|
+
| 'factory'
|
|
154
|
+
| 'tokenFactory'
|
|
155
|
+
| 'stake'
|
|
156
|
+
| 'delegation'
|
|
157
|
+
| 'rollup'
|
|
158
|
+
| 'rollupBlock'
|
|
159
|
+
| 'evidence'
|
|
160
|
+
| 'balance';
|
|
161
|
+
|
|
162
|
+
export interface IStateDB extends IReady {
|
|
163
|
+
name: string;
|
|
164
|
+
version?: string;
|
|
165
|
+
tables: readonly string[];
|
|
166
|
+
readyListenersAttached: boolean;
|
|
167
|
+
|
|
168
|
+
attachReadyListeners(): void;
|
|
169
|
+
|
|
170
|
+
chain: IStateTable<IChainState>;
|
|
171
|
+
account: IStateTable<IAccountState>;
|
|
172
|
+
asset: IStateTable<IAssetState>;
|
|
173
|
+
token: ITokenTable;
|
|
174
|
+
tx: IStateTable<ITxState>;
|
|
175
|
+
|
|
176
|
+
factory: IStateTable<IAssetFactoryState>;
|
|
177
|
+
tokenFactory: IStateTable<ITokenFactoryState>;
|
|
178
|
+
|
|
179
|
+
stake: IStateTable<IStakeState>;
|
|
180
|
+
delegation: IStateTable<IDelegateState>;
|
|
181
|
+
|
|
182
|
+
rollup: IRollupTable;
|
|
183
|
+
rollupBlock: IStateTable<IRollupBlock>;
|
|
184
|
+
|
|
185
|
+
evidence: IStateTable<IEvidenceState>;
|
|
186
|
+
balance: IBalanceTable;
|
|
187
|
+
|
|
188
|
+
/** Run function within a database transaction - txn type depends on StateDB implementation (dolt, fs, memory) */
|
|
189
|
+
runAsLambda?<T>(fn: (txn: unknown) => T | Promise<T>, options?: Record<string, unknown>): Promise<T>;
|
|
190
|
+
|
|
191
|
+
/** Get table by name - use this for dynamic table access */
|
|
192
|
+
getTable?(name: StateDBTableName): IStateTable<unknown>;
|
|
193
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// core/types/interfaces/testing.ts
|
|
2
|
+
// Utility types for testing purposes
|
|
3
|
+
|
|
4
|
+
import type { DeepPartial } from './base';
|
|
5
|
+
import type { IChainConfig } from './config';
|
|
6
|
+
import type { IReadyContext } from './pipeline';
|
|
7
|
+
import type { IAccountState, IAssetState, IDelegateState, IStakeState, ITokenState } from './state';
|
|
8
|
+
import type { IStateDB, ITxState } from './statedb';
|
|
9
|
+
|
|
10
|
+
// ============ Error Types ============
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Custom error interface with code property for pipeline errors
|
|
14
|
+
* Compatible with @ocap/util CustomError
|
|
15
|
+
*/
|
|
16
|
+
export interface ITestError extends Error {
|
|
17
|
+
code?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Next callback type for pipe functions
|
|
22
|
+
*/
|
|
23
|
+
export type PipeNextFn = (err?: ITestError) => void;
|
|
24
|
+
|
|
25
|
+
// ============ Context Types ============
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Partial transaction context for test setup
|
|
29
|
+
* Allows creating context objects with only the fields needed for a specific test
|
|
30
|
+
* Uses IReadyContext as the base which includes all phase fields
|
|
31
|
+
*/
|
|
32
|
+
export type PartialTransactionContext<TItx = unknown> = DeepPartial<IReadyContext<TItx>>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Mock StateDB type for testing
|
|
36
|
+
* All methods are optional to allow partial mocking
|
|
37
|
+
*/
|
|
38
|
+
export type MockStateDB = Partial<IStateDB>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Mock ChainConfig for testing
|
|
42
|
+
* All fields are optional
|
|
43
|
+
*/
|
|
44
|
+
export type MockChainConfig = DeepPartial<IChainConfig>;
|
|
45
|
+
|
|
46
|
+
// ============ State Types ============
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Mock account state for testing
|
|
50
|
+
*/
|
|
51
|
+
export type MockAccountState = DeepPartial<IAccountState>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mock asset state for testing
|
|
55
|
+
*/
|
|
56
|
+
export type MockAssetState = DeepPartial<IAssetState>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Mock token state for testing
|
|
60
|
+
*/
|
|
61
|
+
export type MockTokenState = DeepPartial<ITokenState>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Mock stake state for testing
|
|
65
|
+
*/
|
|
66
|
+
export type MockStakeState = DeepPartial<IStakeState>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Mock delegate state for testing
|
|
70
|
+
*/
|
|
71
|
+
export type MockDelegateState = DeepPartial<IDelegateState>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Mock tx state for testing
|
|
75
|
+
*/
|
|
76
|
+
export type MockTxState = DeepPartial<ITxState>;
|
|
77
|
+
|
|
78
|
+
// ============ Full Test Context ============
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Create a type-safe partial context for testing
|
|
82
|
+
* Usage: const ctx = createTestContext<MyItxType>({ senderState: mockState });
|
|
83
|
+
*/
|
|
84
|
+
export type TestContext<TItx = unknown> = PartialTransactionContext<TItx> & {
|
|
85
|
+
// Ensure required base fields are present
|
|
86
|
+
txBase64: string;
|
|
87
|
+
statedb: MockStateDB;
|
|
88
|
+
config: MockChainConfig;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// ============ Pipe Function Types ============
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Helper type for mocking pipe functions in tests
|
|
95
|
+
*/
|
|
96
|
+
export type MockPipeFunction<TContext = unknown> = (context: TContext, next: PipeNextFn) => void | Promise<void>;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Helper type for mocking error pipe functions in tests
|
|
100
|
+
*/
|
|
101
|
+
export type MockErrorPipeFunction<TContext = unknown> = (
|
|
102
|
+
err: ITestError,
|
|
103
|
+
context: TContext,
|
|
104
|
+
next: PipeNextFn
|
|
105
|
+
) => void | Promise<void>;
|
|
106
|
+
|
|
107
|
+
// ============ Test Result Types ============
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Result type for executeTx helper in protocol tests
|
|
111
|
+
*/
|
|
112
|
+
export interface IExecuteResult {
|
|
113
|
+
err?: Error | null;
|
|
114
|
+
txHash?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Pipe test result with optional error
|
|
119
|
+
*/
|
|
120
|
+
export interface IPipeTestResult {
|
|
121
|
+
err?: ITestError;
|
|
122
|
+
}
|
package/lib/enum_pb.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// package: ocap
|
|
2
2
|
// file: enum.proto
|
|
3
3
|
|
|
4
|
-
import * as jspb from "google-protobuf";
|
|
5
|
-
|
|
6
4
|
export interface StatusCodeMap {
|
|
7
5
|
OK: 0;
|
|
8
6
|
INVALID_NONCE: 1;
|
|
@@ -195,4 +193,3 @@ export interface ProtocolStatusMap {
|
|
|
195
193
|
}
|
|
196
194
|
|
|
197
195
|
export const ProtocolStatus: ProtocolStatusMap;
|
|
198
|
-
|