@lukso/transaction-decoder 1.0.1-dev.0f1bea5
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/LICENSE +201 -0
- package/README.md +486 -0
- package/dist/browser.cjs +6912 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +6 -0
- package/dist/browser.d.ts +6 -0
- package/dist/browser.js +131 -0
- package/dist/browser.js.map +1 -0
- package/dist/cdn/transaction-decoder.global.js +296 -0
- package/dist/cdn/transaction-decoder.global.js.map +1 -0
- package/dist/chunk-GGBHTWJL.js +437 -0
- package/dist/chunk-GGBHTWJL.js.map +1 -0
- package/dist/chunk-GXZOF3QY.js +839 -0
- package/dist/chunk-GXZOF3QY.js.map +1 -0
- package/dist/chunk-LJ6ES5XF.js +776 -0
- package/dist/chunk-LJ6ES5XF.js.map +1 -0
- package/dist/chunk-XVHJWV5U.js +4925 -0
- package/dist/chunk-XVHJWV5U.js.map +1 -0
- package/dist/data.cjs +5518 -0
- package/dist/data.cjs.map +1 -0
- package/dist/data.d.cts +43 -0
- package/dist/data.d.ts +43 -0
- package/dist/data.js +55 -0
- package/dist/data.js.map +1 -0
- package/dist/index-BzXh7poJ.d.cts +524 -0
- package/dist/index-BzXh7poJ.d.ts +524 -0
- package/dist/index.cjs +6912 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +756 -0
- package/dist/index.d.ts +756 -0
- package/dist/index.js +131 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +5644 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +217 -0
- package/dist/server.d.ts +217 -0
- package/dist/server.js +644 -0
- package/dist/server.js.map +1 -0
- package/dist/utils-CBAkjQh3.d.cts +108 -0
- package/dist/utils-xT9-km0r.d.ts +108 -0
- package/package.json +101 -0
- package/src/browser.ts +13 -0
- package/src/client/resolveAddresses.ts +157 -0
- package/src/core/addressCollector.ts +153 -0
- package/src/core/addressResolver.ts +135 -0
- package/src/core/dataModel.ts +888 -0
- package/src/core/instance.ts +33 -0
- package/src/core/integrateDecoder.ts +325 -0
- package/src/data.ts +70 -0
- package/src/decoder/GENERATOR_PROPOSAL.md +182 -0
- package/src/decoder/THREE_PHASE_EXAMPLE.md +108 -0
- package/src/decoder/aggregation.ts +218 -0
- package/src/decoder/browserCache.ts +237 -0
- package/src/decoder/cache/README.md +126 -0
- package/src/decoder/cache/index.ts +44 -0
- package/src/decoder/cache.ts +139 -0
- package/src/decoder/constants.ts +125 -0
- package/src/decoder/decodeTransaction.ts +292 -0
- package/src/decoder/errors.ts +95 -0
- package/src/decoder/events.ts +192 -0
- package/src/decoder/functionSignature.ts +344 -0
- package/src/decoder/getDataFromExternalSources.ts +248 -0
- package/src/decoder/graphqlWS.ts +22 -0
- package/src/decoder/interfaces.ts +185 -0
- package/src/decoder/keyValue.ts +5 -0
- package/src/decoder/kvCache.ts +241 -0
- package/src/decoder/lruCache.ts +184 -0
- package/src/decoder/lsp7Mint.test.ts +179 -0
- package/src/decoder/lsp7TransferBatch.test.ts +105 -0
- package/src/decoder/plugins/RegistryAbi.ts +562 -0
- package/src/decoder/plugins/enhanceBurntPix.ts +132 -0
- package/src/decoder/plugins/enhanceGraffiti.ts +70 -0
- package/src/decoder/plugins/enhanceLSP0ERC725Account.ts +179 -0
- package/src/decoder/plugins/enhanceLSP26FollowerSystem.ts +88 -0
- package/src/decoder/plugins/enhanceLSP6KeyManager.ts +231 -0
- package/src/decoder/plugins/enhanceLSP7DigitalAsset.ts +165 -0
- package/src/decoder/plugins/enhanceLSP8IdentifiableDigitalAsset.ts +170 -0
- package/src/decoder/plugins/enhanceLSP9Vault.ts +57 -0
- package/src/decoder/plugins/enhanceRetrieveAbi.ts +85 -0
- package/src/decoder/plugins/enhanceSetData.ts +135 -0
- package/src/decoder/plugins/index.ts +99 -0
- package/src/decoder/plugins/schemaDefault.ts +318 -0
- package/src/decoder/plugins/standardPlugin.ts +202 -0
- package/src/decoder/registry.ts +322 -0
- package/src/decoder/singleGQL.ts +293 -0
- package/src/decoder/transaction.ts +198 -0
- package/src/decoder/types.ts +465 -0
- package/src/decoder/utils.ts +212 -0
- package/src/example/usage.ts +172 -0
- package/src/index.ts +174 -0
- package/src/server/addressResolver.ts +68 -0
- package/src/server/caches.ts +209 -0
- package/src/server/decodeTransactionSync.ts +156 -0
- package/src/server/decodeTransactionsBatch.ts +207 -0
- package/src/server/finishDecoding.ts +116 -0
- package/src/server/index.ts +81 -0
- package/src/server/lsp23Resolver.test.ts +46 -0
- package/src/server/lsp23Resolver.ts +419 -0
- package/src/server/types.ts +168 -0
- package/src/server.ts +22 -0
- package/src/shared/addressResolver.ts +651 -0
- package/src/shared/cache.ts +144 -0
- package/src/shared/constants.ts +21 -0
- package/src/stubs/tty.ts +13 -0
- package/src/stubs/util.ts +42 -0
- package/src/types/index.ts +154 -0
- package/src/types/provider.ts +46 -0
- package/src/umd.ts +13 -0
- package/src/utils/debug.ts +49 -0
- package/src/utils/json-bigint.ts +47 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
import { Signal } from '@preact/signals-core';
|
|
2
|
+
import { Transaction, Hex, AbiParameter, Log, Address, Chain, Abi, DecodeFunctionDataReturnType } from 'viem';
|
|
3
|
+
import { ERC725JSONSchema } from '@erc725/erc725.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Cache interface for decoder with support for different backends
|
|
7
|
+
* (LRU, Cloudflare KV, Redis, etc.)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Cache entry with metadata
|
|
12
|
+
*/
|
|
13
|
+
interface CacheEntry<T> {
|
|
14
|
+
/** The cached value */
|
|
15
|
+
value: T;
|
|
16
|
+
/** Timestamp when the entry expires (ms since epoch) */
|
|
17
|
+
expires?: number;
|
|
18
|
+
/** Timestamp when the entry becomes stale (for stale-while-revalidate) */
|
|
19
|
+
stale?: number;
|
|
20
|
+
/** Whether this entry resulted from an error */
|
|
21
|
+
isError?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Options for cache operations
|
|
25
|
+
*/
|
|
26
|
+
interface CacheOptions {
|
|
27
|
+
/** Time to live in milliseconds */
|
|
28
|
+
ttl?: number;
|
|
29
|
+
/** TTL for error responses (typically shorter) */
|
|
30
|
+
errorTTL?: number;
|
|
31
|
+
/** Time in ms after which the value is stale but still usable */
|
|
32
|
+
staleWhileRevalidate?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generic cache interface that can be implemented by different backends
|
|
36
|
+
*/
|
|
37
|
+
interface DecoderCache {
|
|
38
|
+
/**
|
|
39
|
+
* Get a value from the cache
|
|
40
|
+
*/
|
|
41
|
+
get<T>(key: string): Promise<CacheEntry<T> | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Set a value in the cache
|
|
44
|
+
*/
|
|
45
|
+
set<T>(key: string, value: T, options?: CacheOptions): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Delete a value from the cache
|
|
48
|
+
*/
|
|
49
|
+
delete(key: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Get multiple values at once (for batch operations)
|
|
52
|
+
*/
|
|
53
|
+
getMany?<T>(keys: string[]): Promise<Map<string, CacheEntry<T>>>;
|
|
54
|
+
/**
|
|
55
|
+
* Set multiple values at once (for batch operations)
|
|
56
|
+
*/
|
|
57
|
+
setMany?<T>(entries: Array<{
|
|
58
|
+
key: string;
|
|
59
|
+
value: T;
|
|
60
|
+
options?: CacheOptions;
|
|
61
|
+
}>): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Clear all entries (optional)
|
|
64
|
+
*/
|
|
65
|
+
clear?(): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Get or set with automatic promise deduplication
|
|
68
|
+
* This is the main method for async operations
|
|
69
|
+
*/
|
|
70
|
+
getOrSet<T>(key: string, factory: (signal?: AbortSignal) => Promise<T>, options?: CacheOptions & {
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
}): Promise<T>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Array length item: Represents the length of an ERC725 Array schema item.
|
|
77
|
+
*/
|
|
78
|
+
type ArrayLengthInfo = ERC725JSONSchema & {
|
|
79
|
+
type: 'ArrayLength';
|
|
80
|
+
value: number;
|
|
81
|
+
pretty?: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Array item: Represents the value of an ERC725 Array schema item.
|
|
85
|
+
*/
|
|
86
|
+
type ArrayItemInfo = ERC725JSONSchema & {
|
|
87
|
+
type: 'ArrayItem';
|
|
88
|
+
dynamic: number;
|
|
89
|
+
value: unknown;
|
|
90
|
+
pretty?: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Value item: Represents the value of an ERC725 schema item.
|
|
94
|
+
*/
|
|
95
|
+
type ValueInfo = ERC725JSONSchema & {
|
|
96
|
+
type: 'Value';
|
|
97
|
+
dynamic?: string | string[];
|
|
98
|
+
value: unknown;
|
|
99
|
+
data?: string;
|
|
100
|
+
method?: string;
|
|
101
|
+
url?: string;
|
|
102
|
+
src?: string;
|
|
103
|
+
pretty?: string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Undecoded item: Represents an undecoded ERC725 schema item (unknown, raw data).
|
|
107
|
+
*/
|
|
108
|
+
type UndecodedInfo = {
|
|
109
|
+
type: 'Undecoded';
|
|
110
|
+
key: string;
|
|
111
|
+
name: undefined;
|
|
112
|
+
value: string;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Error item: Error happened during decoding or retrieval (404 or exception due to invalid data)
|
|
116
|
+
*/
|
|
117
|
+
type ErrorInfo = ERC725JSONSchema & {
|
|
118
|
+
type: 'Error';
|
|
119
|
+
key: string;
|
|
120
|
+
value: string | Error;
|
|
121
|
+
data?: string;
|
|
122
|
+
method?: string;
|
|
123
|
+
url?: string;
|
|
124
|
+
src?: string;
|
|
125
|
+
pretty?: string;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Info item: Results of the decoded schema.
|
|
129
|
+
*/
|
|
130
|
+
type Info = ArrayLengthInfo | ArrayItemInfo | ValueInfo | UndecodedInfo | ErrorInfo;
|
|
131
|
+
/**
|
|
132
|
+
* Add address as a property to the record so that obj.address instead of obj['address'] can be used
|
|
133
|
+
*/
|
|
134
|
+
type EnhancedInfo = {
|
|
135
|
+
address: `0x${string}`;
|
|
136
|
+
standard?: string;
|
|
137
|
+
tokenId?: `0x${string}`;
|
|
138
|
+
name?: string;
|
|
139
|
+
__gqltype?: 'Profile' | 'Asset' | 'Token';
|
|
140
|
+
[key: string]: unknown;
|
|
141
|
+
};
|
|
142
|
+
type NamedArgs = Record<string | number, AbiParameter & {
|
|
143
|
+
value?: unknown;
|
|
144
|
+
}>;
|
|
145
|
+
type ArrayArgs = Array<AbiParameter & {
|
|
146
|
+
value?: unknown;
|
|
147
|
+
}>;
|
|
148
|
+
type ResultShared = {
|
|
149
|
+
resultType?: string;
|
|
150
|
+
standard?: string;
|
|
151
|
+
type?: string;
|
|
152
|
+
sig?: `0x${string}` | null;
|
|
153
|
+
graphqlData?: Record<Hex, EnhancedInfo>;
|
|
154
|
+
/**
|
|
155
|
+
* Decoding phase - added by server-side decoder
|
|
156
|
+
*/
|
|
157
|
+
phase?: 'immediate' | 'enhanced';
|
|
158
|
+
/**
|
|
159
|
+
* Whether this result was served from cache - added by server-side decoder
|
|
160
|
+
*/
|
|
161
|
+
cached?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Time taken to decode (milliseconds)
|
|
164
|
+
*/
|
|
165
|
+
timeTaken?: number;
|
|
166
|
+
moduleHint?: string;
|
|
167
|
+
logs?: DecodeEventResult[];
|
|
168
|
+
isDecoded?: boolean;
|
|
169
|
+
error?: {
|
|
170
|
+
code: string;
|
|
171
|
+
message: string;
|
|
172
|
+
details: Error;
|
|
173
|
+
};
|
|
174
|
+
processingError?: {
|
|
175
|
+
message: string;
|
|
176
|
+
code: unknown;
|
|
177
|
+
};
|
|
178
|
+
blockTimestamp?: number;
|
|
179
|
+
/**
|
|
180
|
+
* List of addresses found in the transaction (to, from, args, namedArgs, wrappers)
|
|
181
|
+
*/
|
|
182
|
+
addresses?: DataKey[];
|
|
183
|
+
transactionHash?: Hex;
|
|
184
|
+
/**
|
|
185
|
+
* Custom data for view matching and extensibility.
|
|
186
|
+
* Populated by enhancers to provide additional context for view selection.
|
|
187
|
+
*
|
|
188
|
+
* Common use cases:
|
|
189
|
+
* - tokenType: 0 (token) | 1 (NFT) | 2 (collection)
|
|
190
|
+
* - isToken, isNFT, isCollection: boolean flags
|
|
191
|
+
* - operationType: 'mint' | 'burn' | 'transfer'
|
|
192
|
+
* - hasMetadata: boolean
|
|
193
|
+
* - customFlags: any enhancer-specific data
|
|
194
|
+
*
|
|
195
|
+
* This field is NOT typed to allow for plugin extensibility.
|
|
196
|
+
*/
|
|
197
|
+
custom?: Record<string, unknown>;
|
|
198
|
+
enhancementAttempted?: boolean;
|
|
199
|
+
};
|
|
200
|
+
type ResultError = {
|
|
201
|
+
resultType: 'error';
|
|
202
|
+
functionName?: string;
|
|
203
|
+
errorType: ErrorType;
|
|
204
|
+
sig: `0x${string}`;
|
|
205
|
+
input?: `0x${string}` | null;
|
|
206
|
+
args?: ArrayArgs;
|
|
207
|
+
summary?: string;
|
|
208
|
+
devdocs?: string;
|
|
209
|
+
};
|
|
210
|
+
type ResultAggregate = {
|
|
211
|
+
resultType: 'aggregate';
|
|
212
|
+
aggregate: {
|
|
213
|
+
count: number;
|
|
214
|
+
blockRange: {
|
|
215
|
+
from: number;
|
|
216
|
+
to: number;
|
|
217
|
+
};
|
|
218
|
+
[key: string]: unknown;
|
|
219
|
+
};
|
|
220
|
+
functionName?: string;
|
|
221
|
+
args?: ArrayArgs;
|
|
222
|
+
wrappers?: Array<ResultType>;
|
|
223
|
+
devdocs?: string;
|
|
224
|
+
};
|
|
225
|
+
type ResultExecute = {
|
|
226
|
+
resultType: 'execute';
|
|
227
|
+
functionName?: string;
|
|
228
|
+
args?: ArrayArgs;
|
|
229
|
+
wrappers?: Array<ResultType>;
|
|
230
|
+
devdocs?: string;
|
|
231
|
+
};
|
|
232
|
+
type ResultCreate = {
|
|
233
|
+
resultType: 'create';
|
|
234
|
+
wrappers?: Array<ResultType>;
|
|
235
|
+
args?: ArrayArgs;
|
|
236
|
+
};
|
|
237
|
+
type ResultWrapper = {
|
|
238
|
+
resultType: 'wrapper';
|
|
239
|
+
functionName?: string;
|
|
240
|
+
args?: ArrayArgs;
|
|
241
|
+
devdocs?: string;
|
|
242
|
+
};
|
|
243
|
+
type ResultFollowProfile = {
|
|
244
|
+
resultType: 'followProfile';
|
|
245
|
+
functionName?: string;
|
|
246
|
+
address: Address;
|
|
247
|
+
};
|
|
248
|
+
type ResultExecuteBatch = {
|
|
249
|
+
resultType: 'executeBatch';
|
|
250
|
+
functionName: string;
|
|
251
|
+
args?: ArrayArgs;
|
|
252
|
+
children: Array<ResultType & ResultShared>;
|
|
253
|
+
wrappers?: Array<ResultType & ResultShared>;
|
|
254
|
+
devdocs?: string;
|
|
255
|
+
};
|
|
256
|
+
type ResultSetDataBatch = {
|
|
257
|
+
resultType: 'setDataBatch';
|
|
258
|
+
functionName?: string;
|
|
259
|
+
standard?: string;
|
|
260
|
+
args?: ArrayArgs;
|
|
261
|
+
children: Array<ResultSetData & ResultShared>;
|
|
262
|
+
wrappers?: Array<ResultType & ResultShared>;
|
|
263
|
+
devdocs?: string;
|
|
264
|
+
};
|
|
265
|
+
type ResultGrafitti = {
|
|
266
|
+
resultType: 'grafitti';
|
|
267
|
+
standard?: string;
|
|
268
|
+
graffiti: string;
|
|
269
|
+
devdocs?: string;
|
|
270
|
+
functionName?: string;
|
|
271
|
+
};
|
|
272
|
+
type ResultSetData = {
|
|
273
|
+
resultType: 'setData';
|
|
274
|
+
functionName?: string;
|
|
275
|
+
tokenId?: `0x${string}`;
|
|
276
|
+
args?: ArrayArgs;
|
|
277
|
+
wrappers?: Array<ResultType & ResultShared>;
|
|
278
|
+
info?: Info;
|
|
279
|
+
devdocs?: string;
|
|
280
|
+
};
|
|
281
|
+
type ResultRaw = {
|
|
282
|
+
resultType: 'raw';
|
|
283
|
+
standard?: string;
|
|
284
|
+
input?: `0x${string}`;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* DecodeFunctionDataReturn: Represents the return type of a decodeTransaction function.
|
|
288
|
+
* There are extra properties added to the return type to make it more useful.
|
|
289
|
+
* Internally some of the properties are used to decode the data so in some places
|
|
290
|
+
* we use "any" to avoid type errors during the decoding process.
|
|
291
|
+
* The main offenders here are isDecoded: boolean and __decoder: string and so on.
|
|
292
|
+
* Rather than mixing those into the type, then it would make the types unnecessarily complex.
|
|
293
|
+
*/
|
|
294
|
+
type ResultComponent = ResultExecute | ResultCreate | ResultWrapper | ResultSetDataBatch | ResultExecuteBatch | ResultSetData | ResultGrafitti | ResultRaw | ResultError | ResultAggregate | ResultFollowProfile;
|
|
295
|
+
/**
|
|
296
|
+
* The main result type returned by decodeTransaction.
|
|
297
|
+
*/
|
|
298
|
+
type ResultType = Partial<Omit<Transaction, 'type' | 'logs' | 'blobVersionedHashes'>> & ResultShared & ResultComponent & {
|
|
299
|
+
__decoder?: string;
|
|
300
|
+
__decoderVerifiedContract?: boolean;
|
|
301
|
+
type?: string;
|
|
302
|
+
logs?: DecodeEventResult[];
|
|
303
|
+
blobVersionedHashes?: readonly Hex[];
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* CustomDecodeFunctionDataReturn: Represents the return type of a customDecodeFunctionData function.
|
|
307
|
+
* Basically the normal decodeFunctionData doesn't return the abi entry, so that
|
|
308
|
+
* we can't decode argument names and types.
|
|
309
|
+
*/
|
|
310
|
+
type CustomDecodeFunctionDataReturn<abi extends Abi | readonly unknown[]> = DecodeFunctionDataReturnType<abi> & {
|
|
311
|
+
args?: ArrayArgs;
|
|
312
|
+
};
|
|
313
|
+
declare enum ErrorType {
|
|
314
|
+
EMPTY_REVERT = "EMPTY_REVERT",
|
|
315
|
+
INVALID = "INVALID",
|
|
316
|
+
PANIC = "PANIC",
|
|
317
|
+
ERROR = "ERROR",
|
|
318
|
+
CUSTOM_ERROR = "CUSTOM_ERROR",
|
|
319
|
+
UNKNOWN = "UNKNOWN"
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The output of the enhancer
|
|
323
|
+
*/
|
|
324
|
+
type DecoderResult = ResultType & ResultShared & {
|
|
325
|
+
/** Which aggregations apply (just keys, no plugin prefix) */
|
|
326
|
+
aggregationKeys?: string[];
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* Aggregation configuration for map/reduce operations
|
|
330
|
+
*/
|
|
331
|
+
interface Aggregation<T = any> {
|
|
332
|
+
/** Unique key for this aggregation within the plugin */
|
|
333
|
+
key: string;
|
|
334
|
+
/** Extract/transform data from a single transaction */
|
|
335
|
+
map: (tx: DecoderResult) => T | undefined;
|
|
336
|
+
/** Combine mapped data with existing state */
|
|
337
|
+
reduce: (state: T | undefined, mapped: T) => T;
|
|
338
|
+
/** Transform state for final output */
|
|
339
|
+
finalize: (state: T) => Omit<ResultAggregate, 'resultType'>;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Bitmap enum for controlling which async operations are enabled
|
|
343
|
+
*/
|
|
344
|
+
declare enum AsyncOperations {
|
|
345
|
+
/** No async operations (default) */
|
|
346
|
+
DISABLED = 0,// 0b000
|
|
347
|
+
/** Enable async plugins (ABI fetching, function signatures) */
|
|
348
|
+
ENABLE_PLUGINS = 1,// 0b001
|
|
349
|
+
/** Enable address resolution (profile/address metadata) */
|
|
350
|
+
ENABLE_ADDRESS_RESOLVE = 2,// 0b010
|
|
351
|
+
/** Enable external data fetching (IPFS, external JSON) */
|
|
352
|
+
ENABLE_EXTERNAL_DATA = 4
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Options to modify operations which now also have to be sent down to the enhancer and plugin
|
|
356
|
+
*/
|
|
357
|
+
type DecoderOptions = {
|
|
358
|
+
plugins: ReadonlyArray<DecoderPlugin>;
|
|
359
|
+
schemaPlugins: ReadonlyArray<SchemaPlugin>;
|
|
360
|
+
preferError?: boolean;
|
|
361
|
+
wrappers: Array<ResultType & ResultShared>;
|
|
362
|
+
chain: Chain;
|
|
363
|
+
/**
|
|
364
|
+
* Controls which async operations are enabled.
|
|
365
|
+
* Can be a boolean for backward compatibility (true = all async, false = none)
|
|
366
|
+
* or AsyncOperations enum for fine-grained control
|
|
367
|
+
*/
|
|
368
|
+
async?: boolean | AsyncOperations;
|
|
369
|
+
/** Cache implementation for async operations */
|
|
370
|
+
cache?: DecoderCache;
|
|
371
|
+
/** Timeout for async operations in milliseconds */
|
|
372
|
+
timeout?: number;
|
|
373
|
+
/** AbortSignal for cancelling async operations */
|
|
374
|
+
signal?: AbortSignal;
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Generic plugin into decoder (most of the time this will be wrapped with the standard plugin to provide
|
|
378
|
+
* additional or existing abis)
|
|
379
|
+
*/
|
|
380
|
+
type DecoderPlugin = {
|
|
381
|
+
enhance: (transaction: DecoderResult, options: DecoderOptions) => Promise<DecoderResult | undefined>;
|
|
382
|
+
decodeEvent: (log: DecodeEventResult, options: DecoderOptions) => Promise<DecodeEventResult>;
|
|
383
|
+
getAggregationKey?: EnhancerAggregationKeyCallback;
|
|
384
|
+
summarize?: EnhancerSummarizeCallback;
|
|
385
|
+
name?: string;
|
|
386
|
+
required?: boolean;
|
|
387
|
+
priority?: number;
|
|
388
|
+
usesAsync?: boolean;
|
|
389
|
+
/** Aggregations supported by this plugin */
|
|
390
|
+
aggregations?: Aggregation[];
|
|
391
|
+
};
|
|
392
|
+
type PluginOptions = {
|
|
393
|
+
abiName: string;
|
|
394
|
+
decoderName?: string;
|
|
395
|
+
moduleHint?: string;
|
|
396
|
+
name?: string;
|
|
397
|
+
required?: boolean;
|
|
398
|
+
priority?: number;
|
|
399
|
+
usesAsync?: boolean;
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Type for the actual enhancement logic
|
|
403
|
+
*/
|
|
404
|
+
type EnhancerCallback = (result: DecoderResult, pluginOptions: PluginOptions, options: DecoderOptions) => Promise<DecoderResult | undefined>;
|
|
405
|
+
type EnhancerAggregationKeyCallback = (result: DecoderResult, pluginOptions: PluginOptions, options: DecoderOptions) => Promise<string | undefined>;
|
|
406
|
+
type EnhancerSummarizeCallback = (aggregateKey: string, result: DecoderResult[], pluginOptions: PluginOptions, options: DecoderOptions) => Promise<DecoderResult | undefined>;
|
|
407
|
+
/**
|
|
408
|
+
* Plugins to execute decodeData with custom schema tables.
|
|
409
|
+
* The passed in data will contain the abi name, functionName and so on.
|
|
410
|
+
*/
|
|
411
|
+
type SchemaPlugin = ((key: Hex, value: Hex) => Promise<Info | undefined>) & {
|
|
412
|
+
name?: string;
|
|
413
|
+
required?: boolean;
|
|
414
|
+
priority?: number;
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* Plugin callback function to decode events.
|
|
418
|
+
*/
|
|
419
|
+
type DecodeEventCallback = (log: DecodeEventResult, options: DecoderOptions) => Promise<DecodeEventResult>;
|
|
420
|
+
type DecodeEventResult = ({
|
|
421
|
+
eventName: string;
|
|
422
|
+
args: ArrayArgs;
|
|
423
|
+
} & Log) | undefined;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Core types for @lukso/decoder
|
|
427
|
+
*/
|
|
428
|
+
|
|
429
|
+
type DataKey = Hex;
|
|
430
|
+
type DeepReadonly<T> = T extends (infer R)[] ? DeepReadonlyArray<R> : T extends (...args: unknown[]) => unknown ? T : T extends object ? DeepReadonlyObject<T> : T;
|
|
431
|
+
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {
|
|
432
|
+
}
|
|
433
|
+
type DeepReadonlyObject<T> = {
|
|
434
|
+
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* State wrapper for address/asset information
|
|
438
|
+
*/
|
|
439
|
+
interface AddressState {
|
|
440
|
+
loading: boolean;
|
|
441
|
+
data?: DeepReadonly<EnhancedInfo>;
|
|
442
|
+
error?: string;
|
|
443
|
+
lastUpdated?: number;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Transaction decoding status
|
|
447
|
+
* - raw: No decoding attempted yet
|
|
448
|
+
* - decoded: Sync decoding complete (phase 1)
|
|
449
|
+
* - enhanced: ABI retrieval complete (phase 2)
|
|
450
|
+
* - complete: Address resolution complete (phase 3)
|
|
451
|
+
* - failed: Decoding failed
|
|
452
|
+
*/
|
|
453
|
+
type DecodingStatus = 'raw' | 'decoded' | 'enhanced' | 'complete' | 'failed';
|
|
454
|
+
/**
|
|
455
|
+
* State wrapper for decoded transactions
|
|
456
|
+
*/
|
|
457
|
+
interface TransactionState {
|
|
458
|
+
loading: boolean;
|
|
459
|
+
data: DeepReadonly<DecoderResult>;
|
|
460
|
+
addresses: ReadonlyArray<DataKey>;
|
|
461
|
+
error?: string;
|
|
462
|
+
lastUpdated?: number;
|
|
463
|
+
decodingStatus?: DecodingStatus;
|
|
464
|
+
addressesResolved?: boolean;
|
|
465
|
+
resolvedData?: DeepReadonly<DecoderResult>;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Options for creating a data model instance
|
|
469
|
+
*/
|
|
470
|
+
interface DataModelOptions {
|
|
471
|
+
onMissingKeys?: (keys: DataKey[]) => void;
|
|
472
|
+
onNewTransaction?: (transaction: unknown) => void;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Read-only interface for consumers (views, components)
|
|
476
|
+
* This is the interface available on window.transactionDecoder
|
|
477
|
+
*/
|
|
478
|
+
interface IDataModelConsumer {
|
|
479
|
+
getTransaction(jsonTransaction: unknown): Signal<TransactionState> | undefined;
|
|
480
|
+
getTransactionByKey(hash: Hex, decoderIndex?: number): Signal<TransactionState> | undefined;
|
|
481
|
+
getTransactionsByIndex(index: number): Map<number | null, Signal<TransactionState>> | undefined;
|
|
482
|
+
getTransactionHashByIndex(index: number): Hex | undefined;
|
|
483
|
+
getTransactionCount(): number;
|
|
484
|
+
getDecodedCount(hash: Hex): number;
|
|
485
|
+
getDecodedTransactions(hash: Hex): Array<Signal<TransactionState>>;
|
|
486
|
+
getTransactionsInOrder(): Array<{
|
|
487
|
+
hash: Hex;
|
|
488
|
+
transactions: Array<Signal<TransactionState>>;
|
|
489
|
+
}>;
|
|
490
|
+
getAddress(address: DataKey): Signal<AddressState>;
|
|
491
|
+
getSignal(key: DataKey): Signal<AddressState>;
|
|
492
|
+
subscribe(key: DataKey, callback: (state: AddressState) => void): () => void;
|
|
493
|
+
getState(key: DataKey): AddressState;
|
|
494
|
+
hasData(key: DataKey): boolean;
|
|
495
|
+
getData(key: DataKey): DeepReadonly<EnhancedInfo> | undefined;
|
|
496
|
+
isLoading(key: DataKey): boolean;
|
|
497
|
+
getError(key: DataKey): string | undefined;
|
|
498
|
+
getAllKeys(): ReadonlyArray<DataKey>;
|
|
499
|
+
getAllData(): Readonly<Record<string, AddressState>>;
|
|
500
|
+
getAllTransactions(): Readonly<Record<string, TransactionState>>;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Full interface for data management (used by data providers)
|
|
504
|
+
* Includes all consumer methods plus data modification methods
|
|
505
|
+
*/
|
|
506
|
+
interface IDataModel extends IDataModelConsumer {
|
|
507
|
+
addTransactions<T extends unknown | unknown[]>(jsonTransactions: T): T extends unknown[] ? Array<Signal<TransactionState>> : Signal<TransactionState>;
|
|
508
|
+
updateTransactionData(hash: Hex, newData: DecoderResult, decoderIndex?: number): void;
|
|
509
|
+
injectData(dataList: EnhancedInfo[]): void;
|
|
510
|
+
updateData(data: EnhancedInfo): void;
|
|
511
|
+
setLoading(keys: DataKey[]): void;
|
|
512
|
+
setError(key: DataKey, error: string): void;
|
|
513
|
+
getMissingKeys(): DataKey[];
|
|
514
|
+
getLoadingKeys(): DataKey[];
|
|
515
|
+
clear(): void;
|
|
516
|
+
remove(keys: DataKey[]): void;
|
|
517
|
+
}
|
|
518
|
+
declare global {
|
|
519
|
+
interface Window {
|
|
520
|
+
TransactionDecoder?: IDataModelConsumer;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export type { ArrayArgs as A, CustomDecodeFunctionDataReturn as C, DataModelOptions as D, EnhancedInfo as E, IDataModel as I, NamedArgs as N, PluginOptions as P, ResultShared as R, SchemaPlugin as S, TransactionState as T, DecodeEventResult as a, DecoderResult as b, DataKey as c, AddressState as d, Info as e, ResultType as f, IDataModelConsumer as g, DecoderOptions as h, EnhancerCallback as i, DecodeEventCallback as j, EnhancerAggregationKeyCallback as k, EnhancerSummarizeCallback as l, Aggregation as m, DecoderPlugin as n, ResultSetData as o, ResultAggregate as p, ResultCreate as q, ResultError as r, ResultExecute as s, ResultExecuteBatch as t, ResultFollowProfile as u, ResultGrafitti as v, ResultRaw as w, ResultSetDataBatch as x, ResultWrapper as y };
|