MCPcopy Index your code
hub / github.com/dethcrypto/TypeChain / parseEvmType

Function parseEvmType

packages/typechain/src/parser/parseEvmType.ts:76–154  ·  view source on GitHub ↗
(rawType: string, components?: EvmSymbol[], internalType?: string)

Source from the content-addressed store, hash-verified

74const isBytesTypeRegex = /^bytes([0-9]+)$/
75
76export function parseEvmType(rawType: string, components?: EvmSymbol[], internalType?: string): EvmType {
77 const lastChar = rawType[rawType.length - 1]
78
79 // first we parse array type
80 if (lastChar === ']') {
81 let finishArrayTypeIndex = rawType.length - 2
82 while (rawType[finishArrayTypeIndex] !== '[') {
83 finishArrayTypeIndex--
84 }
85
86 const arraySizeRaw = rawType.slice(finishArrayTypeIndex + 1, rawType.length - 1)
87 const arraySize = arraySizeRaw !== '' ? parseInt(arraySizeRaw) : undefined
88
89 const restOfTheType = rawType.slice(0, finishArrayTypeIndex)
90
91 const result: ArrayType = {
92 type: 'array',
93 itemType: parseEvmType(restOfTheType, components, internalType),
94 originalType: rawType,
95 }
96 if (arraySize) result.size = arraySize
97 const structName = extractStructNameIfAvailable(internalType)
98 if (structName) result.structName = structName
99
100 return result
101 }
102
103 // otherwise this has to be primitive type
104
105 // deal with simple to parse types
106 switch (rawType) {
107 case 'bool':
108 return { type: 'boolean', originalType: rawType }
109 case 'address':
110 return { type: 'address', originalType: rawType }
111 case 'string':
112 return { type: 'string', originalType: rawType }
113 case 'byte':
114 return { type: 'bytes', size: 1, originalType: rawType }
115 case 'bytes':
116 return { type: 'dynamic-bytes', originalType: rawType }
117 case 'tuple':
118 if (!components) throw new Error('Tuple specified without components!')
119 const result: TupleType = { type: 'tuple', components, originalType: rawType }
120 const structName = extractStructNameIfAvailable(internalType)
121 if (structName) result.structName = structName
122 return result
123 }
124
125 if (isUIntTypeRegex.test(rawType)) {
126 const match = isUIntTypeRegex.exec(rawType)
127 return { type: 'uinteger', bits: parseInt(match![1] || '256'), originalType: rawType }
128 }
129
130 if (isIntTypeRegex.test(rawType)) {
131 const match = isIntTypeRegex.exec(rawType)
132 return { type: 'integer', bits: parseInt(match![1] || '256'), originalType: rawType }
133 }

Callers 2

parseRawAbiParameterTypeFunction · 0.90

Calls 2

warnMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…