-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.ts
443 lines (398 loc) Β· 12.2 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
/**
* A mapping between libraries and the addresses to which they were deployed.
*
* Containing support for two level configuration, These two level
* configurations can be seen below.
*
* {
* "lib.sol:L1": "0x...",
* "lib.sol:L2": "0x...",
* "lib.sol": {"L3": "0x..."}
* }
*/
export interface LibraryAddresses {
[qualifiedNameOrSourceUnit: string]: string | { [unqualifiedLibraryName: string]: string }
}
/**
* A mapping between libraries and lists of placeholder instances present in their hex-encoded bytecode.
* For each placeholder its length and the position of the first character is stored.
*
* Each start and length entry will always directly refer to the position in
* binary and not hex-encoded bytecode.
*/
export interface LinkReferences {
[libraryLabel: string]: Array<{ start: number; length: number }>
}
export interface SolJson {
/**
* Returns a native JavaScript wrapper for a C function.
*
* This is similar to ccall(), but returns a JavaScript function that can be
* reused as many times as needed. The C function can be defined in a C file,
* or be a C-compatible C++ function defined using extern "C" (to prevent
* name mangling).
*
* @param ident The name of the C function to be called.
*
* @param returnType The return type of the function. This can be "number",
* "string" or "array", which correspond to the appropriate JavaScript
* types (use "number" for any C pointer, and "array" for JavaScript arrays
* and typed arrays; note that arrays are 8-bit), or for a void function it
* can be null (note: the JavaScript null value, * not a string containing
* the word βnullβ).
*
* @param argTypes An array of the types of arguments for the function (if
* there are no arguments, this can be omitted). Types are as in returnType,
* except that array is not supported as there is no way for us to know the
* length of the array).
*
* @returns A JavaScript function that can be used for running the C function.
*/
cwrap<T>(ident: string, returnType: string | null, argTypes: string[]): T
/**
* Sets a value at a specific memory address at run-time.
*
* Note:
* setValue() and getValue() only do aligned writes and reads.
*
* The type is an LLVM IR type (one of i8, i16, i32, i64, float, double, or
* a pointer type like i8* or just *), not JavaScript types as used in ccall()
* or cwrap(). This is a lower-level operation, and we do need to care what
* specific type is being used.
*
* @param ptr A pointer (number) representing the memory address.
*
* @param value The value to be stored
*
* @param type An LLVM IR type as a string (see βnoteβ above).
*
* @param noSafe Developers should ignore this variable. It is only
* used in SAFE_HEAP compilation mode, where it can help avoid infinite recursion
* in some specialist use cases.
*/
setValue(ptr: number, value: unknown, type: string, noSafe?: boolean): void
/**
* Given a pointer ptr to a null-terminated UTF8-encoded string in the
* Emscripten HEAP, returns a copy of that string as a JavaScript String
* object.
*
* @param ptr A pointer to a null-terminated UTF8-encoded string in the
* Emscripten HEAP.
*
* @param maxBytesToRead An optional length that specifies the maximum number
* of bytes to read. You can omit this parameter to scan the string until the
* first 0 byte. If maxBytesToRead is passed, and the string at
* [ptr, ptr+maxBytesToReadr) contains a null byte in the middle, then the
* string will cut short at that byte index (i.e. maxBytesToRead will not
* produce a string of exact length [ptr, ptr+maxBytesToRead)) N.B. mixing
* frequent uses of UTF8ToString() with and without maxBytesToRead may throw
* JS JIT optimizations off, so it is worth to consider consistently using
* one style or the other.
*/
UTF8ToString(ptr: number, maxBytesToRead?: number): string
/**
* v1.38.27: 02/10/2019 (emscripten)
* --------------------
* - Remove deprecated Pointer_stringify (use UTF8ToString instead). See #8011
*
* @param ptr
* @param length
* @constructor
*
* @deprecated use UTF8ToString instead
*/
// eslint-disable-next-line camelcase
Pointer_stringify(ptr: number, length?: number): string
/**
* Given a string input return the current length of the given UTF8 bytes.
* Used when performing stringToUTF8 since stringToUTF8 will require at most
* str.length*4+1 bytes of space in the HEAP.
*
* @param str The input string.
*/
lengthBytesUTF8(str: string): number
/**
* Copies the given JavaScript String object str to the Emscripten HEAP at
* address outPtr, null-terminated and encoded in UTF8 form.
*
* The copy will require at most str.length*4+1 bytes of space in the HEAP.
* You can use the function lengthBytesUTF8() to compute the exact amount
* of bytes (excluding the null terminator) needed to encode the string.
*
* @param str A JavaScript String object.
*
* @param outPtr Pointer to data copied from str, encoded in UTF8 format and
* null-terminated.
*
* @param maxBytesToWrite A limit on the number of bytes that this function
* can at most write out. If the string is longer than this, the output is
* truncated. The outputted string will always be null terminated, even if
* truncation occurred, as long as maxBytesToWrite > 0
*/
stringToUTF8(str: string, outPtr: number, maxBytesToWrite?: number): void
/**
* Allocates size bytes of uninitialized storage.
*
* If allocation succeeds, returns a pointer that is suitably aligned for any
* object type with fundamental alignment.
*
* @param size number of bytes to allocate
*
* @returns On success, returns the pointer to the beginning of newly
* allocated memory. To avoid a memory leak, the returned pointer must be
* deallocated with free() or realloc().
*/
_malloc(size: number): number
/**
* Use addFunction to return an integer value that represents a function
* pointer. Passing that integer to C code then lets it call that value as a
* function pointer, and the JavaScript function you sent to addFunction will
* be called.
*
* when using addFunction on LLVM wasm backend, you need to provide an
* additional second argument, a Wasm function signature string. Each
* character within a signature string represents a type. The first character
* represents the return type of the function, and remaining characters are for
* parameter types.
*
* 'v': void type
* 'i': 32-bit integer type
* 'j': 64-bit integer type (currently does not exist in JavaScript)
* 'f': 32-bit float type
* 'd': 64-bit float type
*
* @param func
* @param signature
*/
addFunction: CoreBindings['addFunction']
/**
* Removes an allocated function by the provided function pointer.
*
* @param funcPtr
*/
removeFunction: CoreBindings['removeFunction']
}
/**************************
* core binding functions
*************************/
/**
* Allocates a chunk of memory of size bytes.
*
* Use this function inside callbacks to allocate data that is to be passed to
* the compiler. You may use solidity_free() or solidity_reset() to free this
* memory again, but it is not required as the compiler takes ownership for any
* data passed to it via callbacks.
*
* This function will return NULL if the requested memory region could not be
* allocated.
*
* @param size The size of bytes to be allocated.
*/
export type Alloc = (size: number) => number
/**
* Returns the complete license document.
*/
export type License = () => string | undefined
/**
* This should be called right before each compilation, but not at the end,
* so additional memory can be freed.
*/
export type Reset = () => string
/**
* Returns the compiler version.
*/
export type Version = () => string
// compile binding functions
export type ReadCallbackResult = { contents: string } | { error: string }
export type ReadCallback = (path: string) => ReadCallbackResult
export type Callbacks = { [x: string]: ReadCallback }
/**
* Will attempt to bind into compileStandard before falling back to solidity_compile.
* compileStandard - solidityMaxVersion 0.5.0
*
* @solidityMinVersion 0.4.11
*
* @param input
* @param callbackPtr
* @param contextPtr
*/
export type CompileJsonStandard = (input: string, callbackPtr: number, contextPtr?: number) => string
/**
* Compile the provided input, using the best case implementation based on the
* current binary.
*
* @param input
* @param readCallback
*/
export type CompileSolidity = (input: string, readCallback?: Callbacks) => string
export interface CompileBindings {
compileStandard: CompileJsonStandard
}
export interface CoreBindings {
alloc: Alloc
license: License
reset: Reset
version: Version
copyFromCString: (ptr: number) => string
copyToCString: (input: string, ptr: number) => string
addFunction: <Func extends (...args: any[]) => void>(func: Func, signature?: string) => number
removeFunction: (ptr: number) => void
}
export interface SupportedMethods {
licenseSupported: boolean
versionSupported: boolean
allocSupported: boolean
resetSupported: boolean
compileJsonSupported: boolean
compileJsonMultiSupported: boolean
compileJsonCallbackSupported: boolean
compileJsonStandardSupported: boolean
}
export interface Wrapper {
/**
* Returns the complete license document.
*/
license(): string | undefined
/**
* Returns the compiler version.
*/
version(): string
/**
* Compile the provided input, using the best case implementation based on the
* current binary.
*
* @param input
* @param readCallback
*/
compile(input: string, readCallback?: Callbacks): string
}
export interface Input {
language: 'Solidity' | 'Yul'
sources: { [contractName: string]: { content: string } }
settings?: {
outputSelection?: { '*'?: { '*'?: string[] } }
optimizer?: {
enabled?: boolean
runs?: number
}
evmVersion?: string
libraries?: { [libraryName: string]: string }
remappings?: string[]
}
}
interface ContractABI {
inputs: { internalType: string; name: string; type: string; indexed?: boolean }[]
name: string
outputs: { internalType: string; name: string; type: string }[]
stateMutability: string
type: string
}
interface DevDoc {
kind: 'dev'
methods: Record<string, unknown>
version: number
details: string
}
interface UserDoc {
kind: 'user'
methods: Record<string, unknown>
version: number
}
interface AST {
nativeSrc: string
nodeType: string
src: string
statements: { body?: AST; name: string; nativeSrc: string; nodeType: string }[]
}
interface GeneratedSource {
ast: AST
contents: string
id: number
language: 'Yul'
name: `${string}.yul`
}
interface Bytecode {
linkReferences: LinkReferences
object: string
generatedSources: GeneratedSource[]
}
interface GasEstimates {
creation: {
codeDepositCost: string
executionCost: string
totalCost: string
}
external: {
[functionName: string]: string
}
}
interface LegacyAssemblyItem {
begin: number
end: number
name: string
source: number
value: string
}
interface LegacyAssembly {
'.code': LegacyAssemblyItem[]
'.data': {
'0': {
'.auxdata': string
'.code': LegacyAssemblyItem[]
}
}
sourceList: string[]
}
interface EVM {
assembly: string
bytecode: Bytecode
deployedBytecode: Bytecode
gasEstimates: GasEstimates
legacyAssembly: LegacyAssembly
methodIdentifiers: Record<string, string>
}
interface Ewasm {
wasm: string
}
interface StorageItem {
astId: number
contract: string
label: string
offset: number
slot: string
type: string
}
interface StorageType {
encoding: string
label: string
numberOfBytes: string
}
interface StorageLayout {
storage: StorageItem[]
types: Record<string, StorageType>
}
interface Contract {
abi: ContractABI[]
devdoc: DevDoc
evm: EVM
ewasm: Ewasm
metadata: string
storageLayout: StorageLayout
transientStorageLayout?: StorageLayout
userdoc: UserDoc
}
interface Contracts {
[contractName: string]: {
[contractInstance: string]: Contract
}
}
interface Sources {
[sourceName: string]: {
id: number
}
}
export interface Output {
sources: Sources
contracts: Contracts
errors: unknown[]
}