@d9-network/ink 1.1.0 → 1.2.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/dist/chunk-BiucMVzj.mjs +18 -0
- package/dist/index-DgYVGyHC.d.cts +593 -0
- package/dist/index-Doyoeg38.d.mts +591 -0
- package/dist/index.cjs +41 -208
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -415
- package/dist/index.d.mts +10 -415
- package/dist/index.mjs +29 -202
- package/dist/index.mjs.map +1 -1
- package/dist/indexer/index.cjs +11 -0
- package/dist/indexer/index.d.cts +2 -0
- package/dist/indexer/index.d.mts +2 -0
- package/dist/indexer/index.mjs +3 -0
- package/dist/indexer-Buc6flPW.cjs +572 -0
- package/dist/indexer-Buc6flPW.cjs.map +1 -0
- package/dist/indexer-C-EZviUx.mjs +449 -0
- package/dist/indexer-C-EZviUx.mjs.map +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { __exportAll as t };
|
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import { HexString, SS58String } from "polkadot-api";
|
|
2
|
+
import { Event, InkCallableDescriptor, InkDescriptors, InkMetadata, InkStorageDescriptor } from "@polkadot-api/ink-contracts";
|
|
3
|
+
|
|
4
|
+
//#region rolldown:runtime
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/call-types.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Raw call data from a transaction
|
|
10
|
+
*/
|
|
11
|
+
interface RawContractCall {
|
|
12
|
+
/** The call data (SCALE encoded selector + args) */
|
|
13
|
+
data: Uint8Array;
|
|
14
|
+
/** Contract address being called */
|
|
15
|
+
contractAddress?: SS58String;
|
|
16
|
+
/** Transaction hash (if from a transaction) */
|
|
17
|
+
txHash?: string;
|
|
18
|
+
/** Block number (if from a transaction) */
|
|
19
|
+
blockNumber?: number;
|
|
20
|
+
/** Block hash (if from a transaction) */
|
|
21
|
+
blockHash?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Extract message labels as a union type from InkCallableDescriptor
|
|
25
|
+
* e.g. ExtractMessageLabels<Messages> = "PSP22::transfer" | "PSP22::balance_of" | ...
|
|
26
|
+
*/
|
|
27
|
+
type ExtractMessageLabels<M extends InkCallableDescriptor> = keyof M & string;
|
|
28
|
+
/**
|
|
29
|
+
* Type-safe parsed contract call with discriminated union
|
|
30
|
+
* Enables type narrowing: `if (call.type === "PSP22::transfer") { call.args.to }`
|
|
31
|
+
*/
|
|
32
|
+
type TypedContractCall<M extends InkCallableDescriptor> = { [K in keyof M & string]: {
|
|
33
|
+
/** Call type/method name (discriminant for type narrowing) */
|
|
34
|
+
type: K;
|
|
35
|
+
/** Decoded call arguments (type-safe based on method) */
|
|
36
|
+
args: M[K]["message"];
|
|
37
|
+
/** 4-byte selector */
|
|
38
|
+
selector: Uint8Array;
|
|
39
|
+
/** Original raw call data */
|
|
40
|
+
raw: RawContractCall;
|
|
41
|
+
} }[keyof M & string];
|
|
42
|
+
/**
|
|
43
|
+
* Call filter options
|
|
44
|
+
*/
|
|
45
|
+
interface CallFilterOptions {
|
|
46
|
+
/** Message labels to include (e.g., ["PSP22::transfer", "PSP22::approve"]) */
|
|
47
|
+
messageLabels?: string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Type-safe call filter options with literal message labels
|
|
51
|
+
* Provides compile-time validation of message label names
|
|
52
|
+
*
|
|
53
|
+
* @typeParam M - The InkCallableDescriptor type (message definitions)
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const options: TypedCallFilterOptions<typeof contracts.usdt.__types.messages> = {
|
|
58
|
+
* messageLabels: ["PSP22::transfer", "PSP22::approve"], // Must be valid message names
|
|
59
|
+
* };
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
interface TypedCallFilterOptions<M extends InkCallableDescriptor> {
|
|
63
|
+
/** Message labels to include (type-safe) */
|
|
64
|
+
messageLabels?: Array<ExtractMessageLabels<M>>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Message info from metadata
|
|
68
|
+
*/
|
|
69
|
+
interface MessageInfo {
|
|
70
|
+
/** Message label (e.g., "PSP22::transfer") */
|
|
71
|
+
label: string;
|
|
72
|
+
/** 4-byte selector */
|
|
73
|
+
selector: Uint8Array;
|
|
74
|
+
/** Whether the message is mutable (writes state) */
|
|
75
|
+
mutates: boolean;
|
|
76
|
+
/** Whether the message is payable */
|
|
77
|
+
payable: boolean;
|
|
78
|
+
/** Argument definitions */
|
|
79
|
+
args: Array<{
|
|
80
|
+
label: string;
|
|
81
|
+
type: {
|
|
82
|
+
type: number;
|
|
83
|
+
};
|
|
84
|
+
}>;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/calls.d.ts
|
|
88
|
+
/**
|
|
89
|
+
* Type-safe call parser for a specific contract
|
|
90
|
+
*
|
|
91
|
+
* @typeParam S - The storage descriptor type
|
|
92
|
+
* @typeParam M - The InkCallableDescriptor type (message definitions)
|
|
93
|
+
* @typeParam C - The constructors descriptor type
|
|
94
|
+
* @typeParam E - The events Enum type
|
|
95
|
+
*/
|
|
96
|
+
declare class ContractCallParser<S extends InkStorageDescriptor = InkStorageDescriptor, M extends InkCallableDescriptor = InkCallableDescriptor, C extends InkCallableDescriptor = InkCallableDescriptor, E extends Event = Event> {
|
|
97
|
+
private messageDecoders;
|
|
98
|
+
private selectorToLabel;
|
|
99
|
+
private metadata;
|
|
100
|
+
constructor(descriptor: InkDescriptors<S, M, C, E>);
|
|
101
|
+
/**
|
|
102
|
+
* Parse raw call data into a type-safe contract call
|
|
103
|
+
*
|
|
104
|
+
* @param callData - The raw call data (selector + encoded args) or RawContractCall
|
|
105
|
+
* @returns Parsed call or null if cannot parse
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const call = parser.parseCall(callData);
|
|
110
|
+
* if (call?.type === "PSP22::transfer") {
|
|
111
|
+
* // call.args is typed as { to: SS58String; value: bigint; data: Uint8Array }
|
|
112
|
+
* console.log(call.args.to);
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
parseCall(callData: Uint8Array | RawContractCall): TypedContractCall<M> | null;
|
|
117
|
+
/**
|
|
118
|
+
* Parse multiple calls and optionally filter by message labels
|
|
119
|
+
*
|
|
120
|
+
* @param calls - Array of raw call data
|
|
121
|
+
* @param options - Filter options
|
|
122
|
+
* @returns Array of parsed calls
|
|
123
|
+
*/
|
|
124
|
+
parseCalls(calls: Array<Uint8Array | RawContractCall>, options?: CallFilterOptions): TypedContractCall<M>[];
|
|
125
|
+
/**
|
|
126
|
+
* Filter calls by specific type with proper type narrowing
|
|
127
|
+
*
|
|
128
|
+
* This method provides better type safety than parseCalls with messageLabels
|
|
129
|
+
* because TypeScript can narrow the return type to only the specified call type.
|
|
130
|
+
*
|
|
131
|
+
* @param calls - Array of raw call data
|
|
132
|
+
* @param label - The message label to filter by
|
|
133
|
+
* @returns Array of calls narrowed to the specific type
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const transfers = parser.filterByType(callDataArray, "PSP22::transfer");
|
|
138
|
+
*
|
|
139
|
+
* for (const t of transfers) {
|
|
140
|
+
* // t.args is fully typed as PSP22::transfer args
|
|
141
|
+
* console.log(t.args.to, t.args.value);
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
filterByType<L extends string>(calls: Array<Uint8Array | RawContractCall>, label: L): Array<TypedContractCall<M> & {
|
|
146
|
+
type: L;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Get information about a message by label
|
|
150
|
+
*/
|
|
151
|
+
getMessageInfo(label: string): MessageInfo | null;
|
|
152
|
+
/**
|
|
153
|
+
* Get all available message labels
|
|
154
|
+
*/
|
|
155
|
+
getMessageLabels(): string[];
|
|
156
|
+
/**
|
|
157
|
+
* Check if a selector matches a specific message
|
|
158
|
+
*/
|
|
159
|
+
matchesMessage(selector: Uint8Array, label: string): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Get selector for a message label
|
|
162
|
+
*
|
|
163
|
+
* @param label - Message label (e.g., "PSP22::transfer")
|
|
164
|
+
* @returns Selector as Uint8Array or null if not found
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const selector = parser.getSelector("PSP22::transfer");
|
|
169
|
+
* // selector is Uint8Array([0xdb, 0x20, 0xf9, 0xf5])
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
getSelector(label: string): Uint8Array | null;
|
|
173
|
+
/**
|
|
174
|
+
* Get selector as hex string for a message label
|
|
175
|
+
*
|
|
176
|
+
* @param label - Message label (e.g., "PSP22::transfer")
|
|
177
|
+
* @returns Selector hex string (without 0x) or null if not found
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const selectorHex = parser.getSelectorHex("PSP22::transfer");
|
|
182
|
+
* // selectorHex is "db20f9f5"
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
getSelectorHex(label: string): string | null;
|
|
186
|
+
/**
|
|
187
|
+
* Get the label for a selector
|
|
188
|
+
*
|
|
189
|
+
* @param selector - Selector as Uint8Array or hex string (with or without 0x)
|
|
190
|
+
* @returns Message label or null if not found
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* const label = parser.getLabel("db20f9f5");
|
|
195
|
+
* // label is "PSP22::transfer"
|
|
196
|
+
*
|
|
197
|
+
* // Also works with Uint8Array
|
|
198
|
+
* const label2 = parser.getLabel(callData.slice(0, 4));
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
getLabel(selector: Uint8Array | string): string | null;
|
|
202
|
+
/**
|
|
203
|
+
* Get all selector-to-label mappings
|
|
204
|
+
*
|
|
205
|
+
* @returns Map of selector hex (without 0x) -> label
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* const map = parser.getSelectorMap();
|
|
210
|
+
* for (const [selectorHex, label] of map) {
|
|
211
|
+
* console.log(`${selectorHex} -> ${label}`);
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
getSelectorMap(): Map<string, string>;
|
|
216
|
+
/**
|
|
217
|
+
* Check if a selector exists in this contract
|
|
218
|
+
*
|
|
219
|
+
* @param selector - Selector to check (Uint8Array or hex string)
|
|
220
|
+
* @returns True if selector is valid for this contract
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* if (parser.hasSelector("db20f9f5")) {
|
|
225
|
+
* // This selector is valid for this contract
|
|
226
|
+
* }
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
hasSelector(selector: Uint8Array | string): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Normalize selector to hex string (without 0x prefix)
|
|
232
|
+
*/
|
|
233
|
+
private normalizeSelector;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Type guard for narrowing call types
|
|
237
|
+
*
|
|
238
|
+
* Use this function when you have a `TypedContractCall` and need to
|
|
239
|
+
* narrow it to a specific call type. This is useful when the type
|
|
240
|
+
* information is lost (e.g., after serialization or in generic functions).
|
|
241
|
+
*
|
|
242
|
+
* @typeParam M - The InkCallableDescriptor type (message definitions)
|
|
243
|
+
* @typeParam L - The specific message label to check
|
|
244
|
+
* @param call - The call to check
|
|
245
|
+
* @param label - The message label to match
|
|
246
|
+
* @returns True if the call type matches the label
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* const call = parser.parseCall(callData);
|
|
251
|
+
*
|
|
252
|
+
* if (call && isCallType(call, "PSP22::transfer")) {
|
|
253
|
+
* // TypeScript knows call.args is transfer args
|
|
254
|
+
* console.log(call.args.to);
|
|
255
|
+
* console.log(call.args.value);
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare function isCallType<M extends InkCallableDescriptor, L extends ExtractMessageLabels<M>>(call: TypedContractCall<M>, label: L): call is Extract<TypedContractCall<M>, {
|
|
260
|
+
type: L;
|
|
261
|
+
}>;
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/selectors.d.ts
|
|
264
|
+
/**
|
|
265
|
+
* Information about a contract message selector
|
|
266
|
+
*/
|
|
267
|
+
interface SelectorInfo {
|
|
268
|
+
/** Message label (e.g., "PSP22::transfer") */
|
|
269
|
+
label: string;
|
|
270
|
+
/** 4-byte selector */
|
|
271
|
+
selector: Uint8Array;
|
|
272
|
+
/** Hex string without 0x prefix (e.g., "db20f9f5") */
|
|
273
|
+
selectorHex: string;
|
|
274
|
+
/** Whether the message mutates state */
|
|
275
|
+
mutates: boolean;
|
|
276
|
+
/** Whether the message is payable */
|
|
277
|
+
payable: boolean;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* PSP22 standard selectors for quick reference
|
|
281
|
+
*
|
|
282
|
+
* These are derived from the PSP22 standard and are consistent across implementations.
|
|
283
|
+
* Use these when you need to quickly check if call data matches a specific PSP22 method.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* import { PSP22_SELECTORS, extractSelectorHex } from "@d9-network/ink";
|
|
288
|
+
*
|
|
289
|
+
* const selectorHex = extractSelectorHex(callData);
|
|
290
|
+
* if (selectorHex === PSP22_SELECTORS.transfer) {
|
|
291
|
+
* // This is a PSP22::transfer call
|
|
292
|
+
* }
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
declare const PSP22_SELECTORS: {
|
|
296
|
+
/** PSP22::total_supply - 0x162df8c2 */
|
|
297
|
+
readonly totalSupply: "162df8c2";
|
|
298
|
+
/** PSP22::balance_of - 0x6568382f */
|
|
299
|
+
readonly balanceOf: "6568382f";
|
|
300
|
+
/** PSP22::allowance - 0x4d47d921 */
|
|
301
|
+
readonly allowance: "4d47d921";
|
|
302
|
+
/** PSP22::transfer - 0xdb20f9f5 */
|
|
303
|
+
readonly transfer: "db20f9f5";
|
|
304
|
+
/** PSP22::transfer_from - 0x54b3c76e */
|
|
305
|
+
readonly transferFrom: "54b3c76e";
|
|
306
|
+
/** PSP22::approve - 0xb20f1bbd */
|
|
307
|
+
readonly approve: "b20f1bbd";
|
|
308
|
+
/** PSP22::increase_allowance - 0x96d6b57a */
|
|
309
|
+
readonly increaseAllowance: "96d6b57a";
|
|
310
|
+
/** PSP22::decrease_allowance - 0xfecb57d5 */
|
|
311
|
+
readonly decreaseAllowance: "fecb57d5";
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* PSP22 selector type for type safety
|
|
315
|
+
*/
|
|
316
|
+
type PSP22SelectorKey = keyof typeof PSP22_SELECTORS;
|
|
317
|
+
/**
|
|
318
|
+
* Build a selector lookup map from contract metadata
|
|
319
|
+
*
|
|
320
|
+
* @param metadata - Contract metadata
|
|
321
|
+
* @returns Map of selector hex (without 0x) -> SelectorInfo
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* import { contracts } from "@d9-network/spec";
|
|
326
|
+
* import { buildSelectorMap } from "@d9-network/ink";
|
|
327
|
+
*
|
|
328
|
+
* const selectors = buildSelectorMap(contracts.usdt.metadata);
|
|
329
|
+
* const info = selectors.get("db20f9f5");
|
|
330
|
+
* if (info) {
|
|
331
|
+
* console.log(info.label); // "PSP22::transfer"
|
|
332
|
+
* }
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
declare function buildSelectorMap(metadata: InkMetadata): Map<string, SelectorInfo>;
|
|
336
|
+
/**
|
|
337
|
+
* Build a reverse lookup map (label -> selector info)
|
|
338
|
+
*
|
|
339
|
+
* @param metadata - Contract metadata
|
|
340
|
+
* @returns Map of label -> SelectorInfo
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* const labelMap = buildLabelMap(contracts.usdt.metadata);
|
|
345
|
+
* const info = labelMap.get("PSP22::transfer");
|
|
346
|
+
* console.log(info?.selectorHex); // "db20f9f5"
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
declare function buildLabelMap(metadata: InkMetadata): Map<string, SelectorInfo>;
|
|
350
|
+
/**
|
|
351
|
+
* Get selector for a message label
|
|
352
|
+
*
|
|
353
|
+
* @param metadata - Contract metadata
|
|
354
|
+
* @param label - Message label (e.g., "PSP22::transfer")
|
|
355
|
+
* @returns Selector info or null if not found
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* const info = getSelectorForLabel(contracts.usdt.metadata, "PSP22::transfer");
|
|
360
|
+
* console.log(info?.selectorHex); // "db20f9f5"
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
declare function getSelectorForLabel(metadata: InkMetadata, label: string): SelectorInfo | null;
|
|
364
|
+
/**
|
|
365
|
+
* Get message label for a selector
|
|
366
|
+
*
|
|
367
|
+
* @param metadata - Contract metadata
|
|
368
|
+
* @param selector - Selector as Uint8Array or hex string (with or without 0x)
|
|
369
|
+
* @returns Selector info or null if not found
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```ts
|
|
373
|
+
* const info = getLabelForSelector(contracts.usdt.metadata, "db20f9f5");
|
|
374
|
+
* console.log(info?.label); // "PSP22::transfer"
|
|
375
|
+
*
|
|
376
|
+
* // Also works with Uint8Array
|
|
377
|
+
* const info2 = getLabelForSelector(contracts.usdt.metadata, callData.slice(0, 4));
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
declare function getLabelForSelector(metadata: InkMetadata, selector: Uint8Array | string): SelectorInfo | null;
|
|
381
|
+
/**
|
|
382
|
+
* Check if call data matches a specific message
|
|
383
|
+
*
|
|
384
|
+
* @param metadata - Contract metadata
|
|
385
|
+
* @param callData - Call data bytes or hex string
|
|
386
|
+
* @param label - Message label to check
|
|
387
|
+
* @returns True if the call data selector matches the label
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* if (isMessageCall(contracts.usdt.metadata, callData, "PSP22::transfer")) {
|
|
392
|
+
* // This is a transfer call
|
|
393
|
+
* }
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare function isMessageCall(metadata: InkMetadata, callData: Uint8Array | string, label: string): boolean;
|
|
397
|
+
/**
|
|
398
|
+
* Check if call data matches a PSP22 method
|
|
399
|
+
*
|
|
400
|
+
* @param callData - Call data bytes or hex string
|
|
401
|
+
* @param method - PSP22 method name (e.g., "transfer", "transferFrom")
|
|
402
|
+
* @returns True if the call data selector matches the PSP22 method
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* if (isPSP22Call(callData, "transfer")) {
|
|
407
|
+
* // This is a PSP22::transfer call
|
|
408
|
+
* }
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
declare function isPSP22Call(callData: Uint8Array | string, method: PSP22SelectorKey): boolean;
|
|
412
|
+
/**
|
|
413
|
+
* Get all selectors from contract metadata
|
|
414
|
+
*
|
|
415
|
+
* @param metadata - Contract metadata
|
|
416
|
+
* @returns Array of SelectorInfo for all messages
|
|
417
|
+
*/
|
|
418
|
+
declare function getAllSelectors(metadata: InkMetadata): SelectorInfo[];
|
|
419
|
+
//#endregion
|
|
420
|
+
//#region src/indexer/extrinsic-utils.d.ts
|
|
421
|
+
/**
|
|
422
|
+
* Compute the blake2b-256 hash of an extrinsic
|
|
423
|
+
*
|
|
424
|
+
* This is the standard way to compute extrinsic hashes on Substrate chains.
|
|
425
|
+
*
|
|
426
|
+
* @param extrinsicHex - The raw extrinsic as a hex string (with or without 0x prefix)
|
|
427
|
+
* @returns The extrinsic hash as a hex string with 0x prefix
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* import { computeExtrinsicHash } from "@d9-network/ink/indexer";
|
|
432
|
+
*
|
|
433
|
+
* const extrinsicHex = "0x..."; // from getBlockBody()
|
|
434
|
+
* const hash = computeExtrinsicHash(extrinsicHex);
|
|
435
|
+
* // hash is "0xabcd..." (64 hex chars)
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
declare function computeExtrinsicHash(extrinsicHex: HexString | string): HexString;
|
|
439
|
+
/**
|
|
440
|
+
* Options for parseContractCallFromHex
|
|
441
|
+
*/
|
|
442
|
+
interface ParseContractCallOptions {
|
|
443
|
+
/** Contract address to include in the raw call metadata */
|
|
444
|
+
contractAddress?: SS58String;
|
|
445
|
+
/** Caller/signer address */
|
|
446
|
+
caller?: SS58String;
|
|
447
|
+
/** Block number */
|
|
448
|
+
blockNumber?: number;
|
|
449
|
+
/** Block hash */
|
|
450
|
+
blockHash?: string;
|
|
451
|
+
/** Extrinsic hash */
|
|
452
|
+
txHash?: string;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Search parameters for finding contract call data in an extrinsic
|
|
456
|
+
*/
|
|
457
|
+
interface ContractCallSearchParams {
|
|
458
|
+
/** Target contract address (to match dest field) */
|
|
459
|
+
targetContract?: SS58String;
|
|
460
|
+
/** Known selector to search for (4 bytes hex without 0x) */
|
|
461
|
+
selector?: string;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Attempt to find and extract contract call data from a raw extrinsic hex
|
|
465
|
+
*
|
|
466
|
+
* This function searches the extrinsic hex for patterns that look like
|
|
467
|
+
* contract call data (selector followed by SCALE-encoded arguments).
|
|
468
|
+
*
|
|
469
|
+
* @param extrinsicHex - The raw extrinsic hex
|
|
470
|
+
* @param selector - The 4-byte selector hex to search for (without 0x)
|
|
471
|
+
* @returns The call data starting from the selector, or null if not found
|
|
472
|
+
*/
|
|
473
|
+
declare function extractCallDataFromHex(extrinsicHex: HexString | string, selector: string): Uint8Array | null;
|
|
474
|
+
/**
|
|
475
|
+
* Parse a contract call from raw hex extrinsic data
|
|
476
|
+
*
|
|
477
|
+
* This is useful for indexers that receive extrinsics as raw hex strings
|
|
478
|
+
* from `getBlockBody()` and need to decode specific contract calls.
|
|
479
|
+
*
|
|
480
|
+
* @param extrinsicHex - The raw extrinsic hex
|
|
481
|
+
* @param callParser - A ContractCallParser instance for the target contract
|
|
482
|
+
* @param options - Additional options and metadata
|
|
483
|
+
* @returns Parsed contract call or null if parsing fails
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* import { parseContractCallFromHex, ContractCallParser } from "@d9-network/ink/indexer";
|
|
488
|
+
* import { contracts } from "@d9-network/spec";
|
|
489
|
+
*
|
|
490
|
+
* const parser = new ContractCallParser(contracts.usdt);
|
|
491
|
+
* const call = parseContractCallFromHex(extrinsicHex, parser, {
|
|
492
|
+
* contractAddress: USDT_ADDRESS,
|
|
493
|
+
* caller: signerAddress,
|
|
494
|
+
* });
|
|
495
|
+
*
|
|
496
|
+
* if (call?.type === "PSP22::transfer") {
|
|
497
|
+
* console.log(call.args.to, call.args.value);
|
|
498
|
+
* }
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
declare function parseContractCallFromHex<M extends InkCallableDescriptor>(extrinsicHex: HexString | string, callParser: ContractCallParser<any, M, any, any>, options?: ParseContractCallOptions): TypedContractCall<M> | null;
|
|
502
|
+
/**
|
|
503
|
+
* Extract selector hex from call data
|
|
504
|
+
*
|
|
505
|
+
* @param callData - Raw call data (Uint8Array or hex string)
|
|
506
|
+
* @returns 4-byte selector as hex string without 0x prefix, or null if too short
|
|
507
|
+
*/
|
|
508
|
+
declare function extractSelectorFromCallData(callData: Uint8Array | HexString | string): string | null;
|
|
509
|
+
/**
|
|
510
|
+
* Check if extrinsic contains a specific selector
|
|
511
|
+
*
|
|
512
|
+
* @param extrinsicHex - Raw extrinsic hex
|
|
513
|
+
* @param selector - Selector to check for (with or without 0x)
|
|
514
|
+
* @returns True if selector is found in the extrinsic
|
|
515
|
+
*/
|
|
516
|
+
declare function hasSelector(extrinsicHex: HexString | string, selector: string): boolean;
|
|
517
|
+
/**
|
|
518
|
+
* Check if extrinsic contains a PSP22 call
|
|
519
|
+
*
|
|
520
|
+
* @param extrinsicHex - Raw extrinsic hex
|
|
521
|
+
* @returns The PSP22 method name if found, null otherwise
|
|
522
|
+
*/
|
|
523
|
+
declare function findPSP22Selector(extrinsicHex: HexString | string): keyof typeof PSP22_SELECTORS | null;
|
|
524
|
+
//#endregion
|
|
525
|
+
//#region src/indexer/psp22.d.ts
|
|
526
|
+
/**
|
|
527
|
+
* Decoded PSP22 transfer result
|
|
528
|
+
*/
|
|
529
|
+
interface DecodedPSP22Transfer {
|
|
530
|
+
/** Transfer type */
|
|
531
|
+
type: "transfer" | "transfer_from";
|
|
532
|
+
/** Source address (D9 format) */
|
|
533
|
+
from: SS58String;
|
|
534
|
+
/** Destination address (D9 format) */
|
|
535
|
+
to: SS58String;
|
|
536
|
+
/** Transfer amount */
|
|
537
|
+
value: bigint;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Options for PSP22 decoding
|
|
541
|
+
*/
|
|
542
|
+
interface DecodePSP22Options {
|
|
543
|
+
/**
|
|
544
|
+
* SS58 prefix for returned addresses.
|
|
545
|
+
* Defaults to D9_SS58_PREFIX (9).
|
|
546
|
+
*/
|
|
547
|
+
ss58Prefix?: number;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Decode a PSP22 transfer or transfer_from call from raw extrinsic hex
|
|
551
|
+
*
|
|
552
|
+
* This function handles the common case of extracting PSP22 token transfers
|
|
553
|
+
* from raw blockchain data without needing the full contract metadata.
|
|
554
|
+
*
|
|
555
|
+
* PSP22::transfer args: (to: AccountId, value: u128, data: Vec<u8>)
|
|
556
|
+
* PSP22::transfer_from args: (from: AccountId, to: AccountId, value: u128, data: Vec<u8>)
|
|
557
|
+
*
|
|
558
|
+
* @param extrinsicHex - The raw extrinsic hex
|
|
559
|
+
* @param caller - The transaction signer (used as 'from' for transfer)
|
|
560
|
+
* @param options - Decoding options
|
|
561
|
+
* @returns Decoded transfer or null if not a PSP22 transfer
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* import { decodePSP22Transfer } from "@d9-network/ink/indexer";
|
|
566
|
+
*
|
|
567
|
+
* const transfer = decodePSP22Transfer(extrinsicHex, signerAddress);
|
|
568
|
+
* if (transfer) {
|
|
569
|
+
* console.log(`${transfer.from} -> ${transfer.to}: ${transfer.value}`);
|
|
570
|
+
* }
|
|
571
|
+
* ```
|
|
572
|
+
*/
|
|
573
|
+
declare function decodePSP22Transfer(extrinsicHex: HexString | string, caller: SS58String, options?: DecodePSP22Options): DecodedPSP22Transfer | null;
|
|
574
|
+
/**
|
|
575
|
+
* Check if an extrinsic contains a PSP22 transfer call
|
|
576
|
+
*
|
|
577
|
+
* @param extrinsicHex - Raw extrinsic hex
|
|
578
|
+
* @returns True if contains PSP22::transfer or PSP22::transfer_from
|
|
579
|
+
*/
|
|
580
|
+
declare function isPSP22TransferExtrinsic(extrinsicHex: HexString | string): boolean;
|
|
581
|
+
/**
|
|
582
|
+
* Get the PSP22 transfer type from extrinsic hex
|
|
583
|
+
*
|
|
584
|
+
* @param extrinsicHex - Raw extrinsic hex
|
|
585
|
+
* @returns "transfer", "transfer_from", or null
|
|
586
|
+
*/
|
|
587
|
+
declare function getPSP22TransferType(extrinsicHex: HexString | string): "transfer" | "transfer_from" | null;
|
|
588
|
+
declare namespace index_d_exports {
|
|
589
|
+
export { ContractCallSearchParams, DecodePSP22Options, DecodedPSP22Transfer, ParseContractCallOptions, computeExtrinsicHash, decodePSP22Transfer, extractCallDataFromHex, extractSelectorFromCallData, findPSP22Selector, getPSP22TransferType, hasSelector, isPSP22TransferExtrinsic, parseContractCallFromHex };
|
|
590
|
+
}
|
|
591
|
+
//#endregion
|
|
592
|
+
export { RawContractCall as A, isMessageCall as C, CallFilterOptions as D, isCallType as E, TypedContractCall as M, ExtractMessageLabels as O, getSelectorForLabel as S, ContractCallParser as T, SelectorInfo as _, getPSP22TransferType as a, getAllSelectors as b, ParseContractCallOptions as c, extractSelectorFromCallData as d, findPSP22Selector as f, PSP22_SELECTORS as g, PSP22SelectorKey as h, decodePSP22Transfer as i, TypedCallFilterOptions as j, MessageInfo as k, computeExtrinsicHash as l, parseContractCallFromHex as m, DecodePSP22Options as n, isPSP22TransferExtrinsic as o, hasSelector as p, DecodedPSP22Transfer as r, ContractCallSearchParams as s, index_d_exports as t, extractCallDataFromHex as u, buildLabelMap as v, isPSP22Call as w, getLabelForSelector as x, buildSelectorMap as y };
|
|
593
|
+
//# sourceMappingURL=index-DgYVGyHC.d.cts.map
|