Skip to content

Commit 6f45447

Browse files
author
sklppy88
committed
init
1 parent b621603 commit 6f45447

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

yarn-project/types/src/abi/contract_artifact.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type AbiType,
55
type BasicValue,
66
type ContractArtifact,
7+
ContractArtifactSchema,
78
type ContractNote,
89
type FieldLayout,
910
type FunctionArtifact,
@@ -133,7 +134,10 @@ type NoirCompiledContractFunction = NoirCompiledContract['functions'][number];
133134
* @param contract - Parent contract.
134135
* @returns Function artifact.
135136
*/
136-
function generateFunctionArtifact(fn: NoirCompiledContractFunction, contract: NoirCompiledContract): FunctionArtifact {
137+
function generateFunctionArtifact(
138+
fn: NoirCompiledContractFunction,
139+
contract: NoirCompiledContract,
140+
): Omit<FunctionArtifact, 'bytecode'> & { bytecode: string } {
137141
if (fn.custom_attributes === undefined) {
138142
throw new Error(
139143
`No custom attributes found for contract function ${fn.name}. Try rebuilding the contract with the latest nargo version.`,
@@ -178,7 +182,7 @@ function generateFunctionArtifact(fn: NoirCompiledContractFunction, contract: No
178182
isInitializer: fn.custom_attributes.includes(AZTEC_INITIALIZER_ATTRIBUTE),
179183
parameters,
180184
returnTypes,
181-
bytecode: Buffer.from(fn.bytecode, 'base64'),
185+
bytecode: fn.bytecode,
182186
debugSymbols: fn.debug_symbols,
183187
errorTypes: fn.abi.error_types,
184188
...(fn.assert_messages ? { assertMessages: fn.assert_messages } : undefined),
@@ -238,11 +242,11 @@ function getStorageLayout(input: NoirCompiledContract) {
238242
return {};
239243
}
240244

241-
return storageFields.reduce((acc: Record<string, FieldLayout>, field) => {
245+
return storageFields.reduce((acc: Record<string, Omit<FieldLayout, 'slot'> & { slot: string }>, field) => {
242246
const name = field.name;
243247
const slot = field.value.fields[0].value as IntegerValue;
244248
acc[name] = {
245-
slot: Fr.fromString(slot.value),
249+
slot: slot.value,
246250
};
247251
return acc;
248252
}, {});
@@ -262,7 +266,7 @@ function getNoteTypes(input: NoirCompiledContract) {
262266
return {};
263267
}
264268

265-
return notes.reduce((acc: Record<string, ContractNote>, note) => {
269+
return notes.reduce((acc: Record<string, Omit<ContractNote, 'id'> & { id: string }>, note) => {
266270
const noteFields = note.fields;
267271

268272
// We find note type id by looking for respective kinds as each of them is unique
@@ -274,7 +278,7 @@ function getNoteTypes(input: NoirCompiledContract) {
274278
throw new Error(`Could not find note type id, name or fields for note ${note}`);
275279
}
276280

277-
const noteTypeId = NoteSelector.fromField(Fr.fromString(rawNoteTypeId.value));
281+
const noteTypeId = rawNoteTypeId.value as string;
278282
const name = rawName.value as string;
279283

280284
// Note type id is encoded as a hex string
@@ -301,15 +305,15 @@ function getNoteTypes(input: NoirCompiledContract) {
301305
*/
302306
function generateContractArtifact(contract: NoirCompiledContract, aztecNrVersion?: string): ContractArtifact {
303307
try {
304-
return {
308+
return ContractArtifactSchema.parse({
305309
name: contract.name,
306310
functions: contract.functions.map(f => generateFunctionArtifact(f, contract)),
307311
outputs: contract.outputs,
308312
storageLayout: getStorageLayout(contract),
309313
notes: getNoteTypes(contract),
310314
fileMap: contract.file_map,
311315
...(aztecNrVersion ? { aztecNrVersion } : {}),
312-
};
316+
});
313317
} catch (err) {
314318
throw new Error(`Could not generate contract artifact for ${contract.name}: ${err}`);
315319
}

0 commit comments

Comments
 (0)