wait method
- {int millisecond = 0}
override
Waits for a specified duration and returns a FilterEvent
based on an event emitted by the smart contract.
millisecond
: The duration to wait in milliseconds.
Returns a Future that completes with a FilterEvent
or null
.
Implementation
@override
Future<FilterEvent?> wait({int millisecond = 0}) async {
if (millisecond == 0) {
return null;
}
require(entrypoint != null, "Entrypoint required! use Wallet.init");
final block = await entrypoint!.client.getBlockNumber();
final end = DateTime.now().millisecondsSinceEpoch + millisecond;
return await Isolate.run(() async {
while (DateTime.now().millisecondsSinceEpoch < end) {
final filterEvent = await entrypoint!.client
.events(
FilterOptions.events(
contract: entrypoint!.self,
event: entrypoint!.self.event('UserOperationEvent'),
fromBlock: BlockNum.exact(block - 100),
),
)
.take(1)
.first;
if (filterEvent.transactionHash != null) {
return filterEvent;
}
await Future.delayed(Duration(milliseconds: millisecond));
}
return null;
});
}