observeActions method

Future<Stream<List<ActionDoc>>> observeActions({
  1. required String operator,
  2. required String name,
  3. required List<String> accounts,
  4. Int64? startingFrom,
})

Implementation

Future<Stream<List<ActionDoc>>> observeActions({
  required String operator,
  required String name,
  required List<String> accounts,
  Int64? startingFrom,
}) async {
  final request = ObserveActionsRequest()..name = name;
  request.involvesAccounts
    ..clear()
    ..addAll(accounts.map(hex.decode));

  if (startingFrom != null) {
    request.startingFrom = TxId()..txId = startingFrom;
  }

  final envelop = await requestEnvelope(request: request);
  final stream = getServiceClient(operator).query.observeActions(envelop);
  return stream.map(
    (transactions) => transactions.transactions.map((tx) {
      final action = tx.request.data.invokeAction;
      return ActionDoc(
        Action()
          ..txId = tx.response.txId
          ..name = action.name
          ..contextId = tx.request.contextId
          ..fromAccount = action.fromAccount
          ..target = action.target
          ..payload = action.payload,
      );
    }).toList(),
  );
}