diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index f61f2d669faa..437c0777b7c9 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -1,6 +1,6 @@ import { FieldsOf } from '@aztec/circuits.js'; import { retryUntil } from '@aztec/foundation/retry'; -import { GetUnencryptedLogsResponse, PXE, TxHash, TxReceipt, TxStatus } from '@aztec/types'; +import { GetUnencryptedLogsResponse, NoteSpendingInfoDao, PXE, TxHash, TxReceipt, TxStatus } from '@aztec/types'; import every from 'lodash.every'; @@ -15,12 +15,15 @@ export type WaitOpts = { * If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true. **/ waitForNotesSync?: boolean; + /** Whether newly created notes should be included in the receipt. */ + getNotes?: boolean; }; const DefaultWaitOpts: WaitOpts = { timeout: 60, interval: 1, waitForNotesSync: true, + getNotes: false, }; /** @@ -61,6 +64,9 @@ export class SentTx { const receipt = await this.waitForReceipt(opts); if (receipt.status !== TxStatus.MINED) throw new Error(`Transaction ${await this.getTxHash()} was ${receipt.status}`); + if (opts?.getNotes) { + receipt.notes = await this.pxe.getNotes({ txHash: await this.getTxHash() }); + } return receipt; } @@ -74,6 +80,16 @@ export class SentTx { return this.pxe.getUnencryptedLogs({ txHash: await this.getTxHash() }); } + /** + * Gets notes created in this tx. + * @remarks This function will wait for the tx to be mined if it hasn't been already. + * @returns The requested notes. + */ + public async getNotes(): Promise { + await this.wait(); + return this.pxe.getNotes({ txHash: await this.getTxHash() }); + } + protected async waitForReceipt(opts?: WaitOpts): Promise { const txHash = await this.getTxHash(); return await retryUntil( diff --git a/yarn-project/types/src/tx/tx_receipt.ts b/yarn-project/types/src/tx/tx_receipt.ts index 5d2a167b3753..7a27d16d05fb 100644 --- a/yarn-project/types/src/tx/tx_receipt.ts +++ b/yarn-project/types/src/tx/tx_receipt.ts @@ -1,5 +1,5 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { TxHash } from '@aztec/types'; +import { NoteSpendingInfoDao, TxHash } from '@aztec/types'; /** * Possible status of a transaction. @@ -40,6 +40,10 @@ export class TxReceipt { * The deployed contract's address. */ public contractAddress?: AztecAddress, + /** + * Notes created in this tx. + */ + public notes?: NoteSpendingInfoDao[], ) {} /**