Skip to content

Commit

Permalink
feat: note fields in TS artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 1, 2024
1 parent 6ce30c5 commit d63d98f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions yarn-project/foundation/src/abi/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down
26 changes: 25 additions & 1 deletion yarn-project/types/src/abi/contract_artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
}, {});
Expand Down

0 comments on commit d63d98f

Please sign in to comment.