From 6f76e380a7eed257597d79acf7badc3f84631249 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 1 Oct 2024 13:02:26 +0000 Subject: [PATCH] feat: note fields in TS artifact --- yarn-project/foundation/src/abi/abi.ts | 14 ++++++++++ .../types/src/abi/contract_artifact.ts | 26 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/yarn-project/foundation/src/abi/abi.ts b/yarn-project/foundation/src/abi/abi.ts index a25a802dace9..160be402bff1 100644 --- a/yarn-project/foundation/src/abi/abi.ts +++ b/yarn-project/foundation/src/abi/abi.ts @@ -309,6 +309,20 @@ export type ContractNote = { * Type of the note (e.g., 'TransparentNote') */ typ: string; + /** + * Fields of the note. + */ + fields: NoteField[]; +}; + +/** Type representing a field of a note (e.g. `amount` in `TokenNote`). */ +export type NoteField = { + /** Name of the field (e.g. `amount`). */ + name: string; + /** Index where the note field starts in the serialized note array. */ + index: number; + /** Whether the field can be unset when creating the note (in the partial notes flow). */ + nullable: boolean; }; /** diff --git a/yarn-project/types/src/abi/contract_artifact.ts b/yarn-project/types/src/abi/contract_artifact.ts index b7484f0c0b9f..84eb0f140990 100644 --- a/yarn-project/types/src/abi/contract_artifact.ts +++ b/yarn-project/types/src/abi/contract_artifact.ts @@ -256,7 +256,23 @@ function getStorageLayout(input: NoirCompiledContract) { function getNoteTypes(input: NoirCompiledContract) { type t = { kind: string; - fields: [{ kind: string; sign: boolean; value: string }, { kind: string; value: string }]; + fields: [ + { kind: string; sign: boolean; value: string }, + { kind: string; value: string }, + { + fields: { + name: string; + value: { + kind: string; + value: string | boolean; + fields: [ + { name: string; value: { kind: string; sign: boolean; value: string } }, + { name: string; value: { kind: string; value: boolean } }, + ]; + }; + }[]; + }, + ]; }; const notes = input.outputs.globals.notes as t[]; @@ -269,9 +285,17 @@ function getNoteTypes(input: NoirCompiledContract) { const name = note.fields[1].value as string; // Note id is encoded as a hex string const id = NoteSelector.fromField(Fr.fromString(note.fields[0].value)); + const fields = note.fields[2].fields.map(field => { + return { + name: field.name, + index: Number(field.value.fields[0].value.value), // TODO: is this hex or decimal? + nullable: field.value.fields[1].value.value, + }; + }); acc[name] = { id, typ: name, + fields, }; return acc; }, {});