MCPcopy Create free account
hub / github.com/d1ll0n/stack-packer / ParserWrapper

Class ParserWrapper

src/parser/index.ts:25–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25export class ParserWrapper {
26 enums: Record<string, AbiEnum> = {}
27 structs: Record<string, AbiStruct> = {};
28 functions: Record<string, AbiFunction> = {}
29 errors: Record<string, AbiError> = {}
30 events: Record<string, AbiEvent> = {}
31
32 constructor(parsed: DefinedType[]) {
33 let i = 0;
34 let n = 0;
35 while (n < parsed.length && i < 50) for (let p of parsed) if (this.handleType(p)) (i++ && n++);
36 }
37
38 get allStructs(): AbiType<false, false>[] {
39 return [
40 ...Object.values(this.structs),
41 ...Object.values(this.enums)
42 ]
43 }
44
45 get allErrors(): AbiError[] {
46 return Object.values(this.errors)
47 }
48
49 get allEvents(): AbiEvent[] {
50 return Object.values(this.events)
51 }
52
53 get allFunctions(): AbiFunction[] {
54 return Object.values(this.functions)
55 }
56
57 handleFields(fields: StructField[]) {
58 const outFields: AbiStructField[] = [];
59 let size = 0;
60 for (let field of fields) {
61 let { name, typeName, coderType, accessors } = field;
62 const abiType = this.convertFieldType(typeName);
63 if (!abiType) return null;
64 const outField: AbiStructField = { name, type: abiType, coderType, accessors }
65 if ((field as any).isIndexed) {
66 (outField as any).isIndexed = (field as any).isIndexed
67 }
68 outFields.push(outField);
69 if (abiType.size == null) size = null;
70 else if (size != null) size += abiType.size;
71 }
72 return {
73 fields: outFields,
74 dynamic: size == null,
75 size
76 }
77 }
78
79 buildGroup(struct: AbiStruct, group: GroupType): StructGroup {
80 const members: AbiStructField[] = []
81 for (const member of group.members) {
82 const field = struct.fields.find((field) => field.name === member.name);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected