-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathdeploy_account_sent_tx.ts
42 lines (37 loc) · 1.71 KB
/
deploy_account_sent_tx.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { FieldsOf } from '@aztec/circuits.js';
import { TxHash, TxReceipt } from '@aztec/types';
import { Wallet } from '../account/index.js';
import { DefaultWaitOpts, SentTx, WaitOpts } from '../contract/index.js';
import { waitForAccountSynch } from './util.js';
/** Extends a transaction receipt with a wallet instance for the newly deployed contract. */
export type DeployAccountTxReceipt = FieldsOf<TxReceipt> & {
/** Wallet that corresponds to the newly deployed account contract. */
wallet: Wallet;
};
/**
* A deployment transaction for an account contract sent to the network, extending SentTx with methods to get the resulting wallet.
*/
export class DeployAccountSentTx extends SentTx {
constructor(private wallet: Wallet, txHashPromise: Promise<TxHash>) {
super(wallet, txHashPromise);
}
/**
* Awaits for the tx to be mined and returns the contract instance. Throws if tx is not mined.
* @param opts - Options for configuring the waiting for the tx to be mined.
* @returns The deployed contract instance.
*/
public async getWallet(opts?: WaitOpts): Promise<Wallet> {
const receipt = await this.wait(opts);
return receipt.wallet;
}
/**
* Awaits for the tx to be mined and returns the receipt along with a wallet instance. Throws if tx is not mined.
* @param opts - Options for configuring the waiting for the tx to be mined.
* @returns The transaction receipt with the wallet for the deployed account contract.
*/
public async wait(opts: WaitOpts = DefaultWaitOpts): Promise<DeployAccountTxReceipt> {
const receipt = await super.wait(opts);
await waitForAccountSynch(this.pxe, this.wallet.getCompleteAddress(), opts);
return { ...receipt, wallet: this.wallet };
}
}