onMessage method
Called when a message is received.
Implementation
@override
Future<void> onMessage(dynamic message) async {
try {
switch (message) {
case final InitiateChannelMessage msg:
await _handleInitiateChannel(msg);
break;
case final AcceptChannelMessage msg:
await _handleAcceptChannel(msg);
break;
case final RecordServerAcceptanceMessage msg:
await _handleRecordServerAcceptance(msg);
break;
case final BuildRefundTransactionMessage msg:
await _handleBuildRefundTransaction(msg);
break;
case final SignRefundTransactionMessage msg:
await _handleSignRefundTransaction(msg);
break;
case final MultisigTransactionSignedResponse msg:
await _handleMultisigSignedResponse(msg);
break;
case final RecordRefundSignatureMessage msg:
await _handleRecordRefundSignature(msg);
break;
case final OpenChannelMessage msg:
await _handleOpenChannel(msg);
break;
case final RetryChannelFundingMessage msg:
await _handleRetryChannelFunding(msg);
break;
case final ResendChannelOpenMessage msg:
await _handleResendChannelOpen(msg);
break;
case final RecordFundingFailedMessage msg:
await _handleRecordFundingFailed(msg);
break;
case final RecordServerOpenedMessage msg:
await _handleRecordServerOpened(msg);
break;
case final RecordPaymentMessage msg:
await _handleRecordPayment(msg);
break;
case final AcknowledgePaymentMessage msg:
await _handleAcknowledgePayment(msg);
break;
case final CloseChannelMessage msg:
await _handleCloseChannel(msg);
case final RecordSettlementMessage msg:
await _handleRecordSettlement(msg);
break;
case final ExpireChannelMessage msg:
await _handleExpireChannel(msg);
break;
case final ClaimRefundMessage msg:
await _handleClaimRefund(msg);
break;
case final QueryChannelStateMessage msg:
await _handleQueryChannelState(msg);
break;
case final ChannelDetailsQueryMessage msg:
await _handleChannelDetailsQuery(msg);
break;
default:
}
} catch (e, stackTrace) {
// Every request-shaped handler owns its own failure reply: each wraps
// its whole body in try/catch and answers the sender it captured
// before its first await, in the response type that matches the
// request (ChannelInitiatedResponse for InitiateChannelMessage,
// ChannelClosedResponse for CloseChannelMessage, and so on), with
// `success: false` and the error text. So nothing generic is answered
// from here.
//
// This used to call a `_sendErrorResponse(dynamic, String)` that knew
// only two of the twenty message types and replied to `context.sender`
// — which, after the handler's awaits, is the sender of whatever
// message arrived next, not of `message`. For those two types it could
// only ever duplicate the reply the handler had already sent, and for
// the other eighteen it did nothing at all. Removed (bead
// libspiffy-q7a).
//
// Reaching this point therefore means a handler's own catch escaped,
// which is a defect in that handler: log it loudly rather than guess a
// response type and a recipient.
_log.severe(
'Unhandled error in ${message.runtimeType}; the handler failed to '
'answer its sender: $e',
e,
stackTrace);
}
}