send method
Future<TransactionConfirmation?>
send({
- required Transaction transaction,
- bool isEnoughConfirmations() = _defaultIsEnoughConfirmation,
- Duration timeout = const Duration(seconds: 30),
- TransactionConfirmationHandler? onConfirmation,
override
Sends a transaction and listens to confirmations.
Sender auto-closes in the following situations : - when transaction has enough confirmations - when timeout is reached - when transaction fails
Caller can be notified of incoming confirmations using onConfirmation
Implementation
@override
Future<TransactionConfirmation?> send({
required Transaction transaction,
bool Function(TransactionConfirmation) isEnoughConfirmations =
_defaultIsEnoughConfirmation,
Duration timeout = const Duration(seconds: 30),
TransactionConfirmationHandler? onConfirmation,
}) async {
assert(
_completer == null,
'ArchethicTransactionSender already in use. Call [close()] or create a new one.',
);
_completer = Completer<TransactionConfirmation?>();
_timer = Timer(
timeout,
() {
_onError(const TransactionError.timeout());
},
);
unawaited(
_send(
transaction: transaction,
isEnoughConfirmations: isEnoughConfirmations,
onConfirmation: onConfirmation,
),
);
return _completer!.future;
}