Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Dec 8, 2024
1 parent e7dbfc8 commit 390329a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 28 deletions.
7 changes: 2 additions & 5 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ export abstract class BaseWallet implements Wallet {
getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<any> {
return this.pxe.getPublicStorageAt(contract, storageSlot);
}
addNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNote(note, this.getAddress());
}
addNullifiedNote(note: ExtendedNote): Promise<void> {
return this.pxe.addNullifiedNote(note);
deliverNote(note: ExtendedNote, isNullified?: boolean): Promise<void> {
return this.pxe.deliverNote(note, isNullified, this.getAddress());
}
getBlock(number: number): Promise<L2Block | undefined> {
return this.pxe.getBlock(number);
Expand Down
27 changes: 16 additions & 11 deletions yarn-project/circuit-types/src/interfaces/pxe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ describe('PXESchema', () => {
expect(result).toEqual([expect.any(BigInt), expect.any(SiblingPath)]);
});

it('addNote', async () => {
await context.client.addNote(ExtendedNote.random(), address);
});
// it('addNote', async () => {
// await context.client.addNote(ExtendedNote.random(), address);
// });

it('addNullifiedNote', async () => {
await context.client.addNullifiedNote(ExtendedNote.random());
});
// it('addNullifiedNote', async () => {
// await context.client.addNullifiedNote(ExtendedNote.random());
// });

it('getBlock', async () => {
const result = await context.client.getBlock(1);
Expand Down Expand Up @@ -430,15 +430,20 @@ class MockPXE implements PXE {
expect(secret).toBeInstanceOf(Fr);
return Promise.resolve([1n, SiblingPath.random(L1_TO_L2_MSG_TREE_HEIGHT)]);
}
addNote(note: ExtendedNote, scope?: AztecAddress | undefined): Promise<void> {
deliverNote(note: ExtendedNote, _isNullified?: boolean, scope?: AztecAddress): Promise<void> {
expect(note).toBeInstanceOf(ExtendedNote);
expect(scope).toEqual(this.address);
return Promise.resolve();
}
addNullifiedNote(note: ExtendedNote): Promise<void> {
expect(note).toBeInstanceOf(ExtendedNote);
return Promise.resolve();
}
// addNote(note: ExtendedNote, scope?: AztecAddress | undefined): Promise<void> {
// expect(note).toBeInstanceOf(ExtendedNote);
// expect(scope).toEqual(this.address);
// return Promise.resolve();
// }
// addNullifiedNote(note: ExtendedNote): Promise<void> {
// expect(note).toBeInstanceOf(ExtendedNote);
// return Promise.resolve();
// }
getBlock(number: number): Promise<L2Block | undefined> {
return Promise.resolve(L2Block.random(number));
}
Expand Down
7 changes: 2 additions & 5 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ export interface PXE {
* @param note - The note to add.
* @param scope - The scope to add the note under. Currently optional.
*/
addNote(note: ExtendedNote, scope?: AztecAddress): Promise<void>;

/**
* Adds a nullified note to the database.
* @throws If the note hash of the note doesn't exist in the tree.
Expand All @@ -261,7 +259,7 @@ export interface PXE {
* which is undesirable. Instead, we are just adding the note to the database as nullified and the nullifier is set
* to 0 in the db.
*/
addNullifiedNote(note: ExtendedNote): Promise<void>;
deliverNote(note: ExtendedNote, nullified?: boolean, scope?: AztecAddress): Promise<void>;

/**
* Get the given block.
Expand Down Expand Up @@ -511,8 +509,7 @@ export const PXESchema: ApiSchemaFor<PXE> = {
.function()
.args(schemas.AztecAddress, schemas.Fr, schemas.Fr)
.returns(z.tuple([schemas.BigInt, SiblingPath.schemaFor(L1_TO_L2_MSG_TREE_HEIGHT)])),
addNote: z.function().args(ExtendedNote.schema, optional(schemas.AztecAddress)).returns(z.void()),
addNullifiedNote: z.function().args(ExtendedNote.schema).returns(z.void()),
deliverNote: z.function().args(ExtendedNote.schema, optional(z.boolean()), optional(schemas.AztecAddress)).returns(z.void()),
getBlock: z
.function()
.args(z.number())
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli-wallet/src/cmds/add_note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export async function addNote(
}

const extendedNote = new ExtendedNote(note, address, contractAddress, storageField.slot, contractNote.id, txHash);
await wallet.addNote(extendedNote);
await wallet.deliverNote(extendedNote);
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,6 @@ async function addPendingShieldNoteToPXE(
TokenBlacklistContract.notes.TransparentNote.id,
txHash,
);
await wallet.addNote(extendedNote);
await wallet.deliverNote(extendedNote);
// docs:end:pxe_add_note
}
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe('e2e_2_pxes', () => {
{
// We need to register the contract to be able to compute the note hash by calling compute_note_hash_and_optionally_a_nullifier(...)
await pxeB.registerContract(testContract);
await pxeB.addNullifiedNote(note);
await pxeB.deliverNote(note, true);
}

// 5. Try fetching the nullified note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class BlacklistTokenContractTest {
TokenBlacklistContract.notes.TransparentNote.id,
txHash,
);
await this.wallets[accountIndex].addNote(extendedNote);
await this.wallets[accountIndex].deliverNote(extendedNote);
}

async applyMintSnapshot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('e2e_non_contract_account', () => {
TestContract.notes.TestNote.id,
txHash,
);
await wallet.addNote(extendedNote);
await wallet.deliverNote(extendedNote);

expect(await contract.methods.get_constant().simulate()).toEqual(value);
});
Expand Down
12 changes: 10 additions & 2 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,15 @@ export class PXEService implements PXE {
return await getNonNullifiedL1ToL2MessageWitness(this.node, contractAddress, messageHash, secret);
}

public async addNote(note: ExtendedNote, scope?: AztecAddress) {
public async deliverNote(note: ExtendedNote, nullified: boolean = false, scope?: AztecAddress,) {
if (!nullified) {
await this.#addNote(note, scope);
} else {
await this.#addNullifiedNote(note);
}
}

async #addNote(note: ExtendedNote, scope?: AztecAddress) {
const owner = await this.db.getCompleteAddress(note.owner);
if (!owner) {
throw new Error(`Unknown account: ${note.owner.toString()}`);
Expand Down Expand Up @@ -392,7 +400,7 @@ export class PXEService implements PXE {
}
}

public async addNullifiedNote(note: ExtendedNote) {
async #addNullifiedNote(note: ExtendedNote) {
const { data: nonces, l2BlockHash, l2BlockNumber } = await this.#getNoteNonces(note);
if (nonces.length === 0) {
throw new Error(`Cannot find the note in tx: ${note.txHash}.`);
Expand Down

0 comments on commit 390329a

Please sign in to comment.