Skip to content

Commit

Permalink
including notes in receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 26, 2023
1 parent faded28 commit b0ad462
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 17 additions & 1 deletion yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
};

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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<NoteSpendingInfoDao[]> {
await this.wait();
return this.pxe.getNotes({ txHash: await this.getTxHash() });
}

protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
const txHash = await this.getTxHash();
return await retryUntil(
Expand Down
6 changes: 5 additions & 1 deletion yarn-project/types/src/tx/tx_receipt.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -40,6 +40,10 @@ export class TxReceipt {
* The deployed contract's address.
*/
public contractAddress?: AztecAddress,
/**
* Notes created in this tx.
*/
public notes?: NoteSpendingInfoDao[],
) {}

/**
Expand Down

0 comments on commit b0ad462

Please sign in to comment.