-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathutil.ts
32 lines (30 loc) · 902 Bytes
/
util.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
import { retryUntil } from '@aztec/foundation/retry';
import { CompleteAddress, PXE } from '@aztec/types';
import { WaitOpts } from '../contract/index.js';
/**
* Waits for the account to finish synchronizing with the PXE Service.
* @param pxe - PXE instance
* @param address - Address to wait for synch
* @param opts - Wait options
*/
export async function waitForAccountSynch(
pxe: PXE,
address: CompleteAddress,
{ interval, timeout }: WaitOpts,
): Promise<void> {
const publicKey = address.publicKey.toString();
await retryUntil(
async () => {
const status = await pxe.getSyncStatus();
const accountSynchedToBlock = status.notes[publicKey];
if (typeof accountSynchedToBlock === 'undefined') {
return false;
} else {
return accountSynchedToBlock >= status.blocks;
}
},
'waitForAccountSynch',
timeout,
interval,
);
}