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

Function getEncoder

src/code-gen/functions.ts:150–181  ·  view source on GitHub ↗
(
  struct: AbiStruct,
  fields: ProcessedField[],
  context: FileContext,
  name: string,
  maskReference?: string
)

Source from the content-addressed store, hash-verified

148}
149
150const getEncoder = (
151 struct: AbiStruct,
152 fields: ProcessedField[],
153 context: FileContext,
154 name: string,
155 maskReference?: string
156): CodeGenFunction => {
157 const orBlocks: { positioned: string; }[] = [...fields];
158 const inputs = fields.map((field) => ({ definition:field.parameterDefinition, name: field.name, type: field.type }));
159 let outputName = 'encoded'
160 if (maskReference) {
161 orBlocks.unshift({ positioned: `and(old, ${maskReference})` })
162 inputs.unshift({ definition:`${fields[0].structName} old`, name: 'old', type: struct })
163 outputName = 'updated'
164 }
165 let encodeChunks = buildNestedAssemblyOr(orBlocks);
166 encodeChunks = prefixFirstString(encodeChunks, `${outputName} := `)
167 return {
168 name,
169 inputs,
170 outputs: [{ definition:`${fields[0].structName} ${outputName}`, name: outputName, type: struct }],
171 visibility: 'pure',
172 location: 'internal',
173 body: buildAssemblyBlock([
174 ...getOverflowCheck(fields, context),
175 ...toArray(encodeChunks)
176 ]),
177 internalType: 'setter',
178 outputFields: [],
179 inputFields: fields
180 }
181}
182
183export const generateFieldSetter = (
184 struct: AbiStruct,

Callers 3

getEncodeGroupFunctionFunction · 0.85
getEncodeFunctionFunction · 0.85
generateFieldSetterFunction · 0.85

Calls 5

buildNestedAssemblyOrFunction · 0.90
prefixFirstStringFunction · 0.90
buildAssemblyBlockFunction · 0.90
toArrayFunction · 0.90
getOverflowCheckFunction · 0.85

Tested by

no test coverage detected