observeRequests method
Implementation
Future<Stream<List<PaymentRequestDoc>>> observeRequests({
required String operator,
required List<String> accounts,
Int64? startingFrom,
}) async {
final request = ObserveActionsRequest()..name = 'm10.Request';
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.asyncMap(
(FinalizedTransactions transactions) async {
final txDocs =
transactions.transactions.map(TransactionDoc.new).toList();
final requests =
[txDocs].map(PaymentRequestDoc.from).whereNotNull().toList();
final requestDocs = requests.map(
(r) async => r
..fromAccount = await getAccountInfoCached(
id: r.fromAccountId,
operator: operator,
)
..toAccount = await getAccountInfoCached(
id: r.toAccountId,
operator: operator,
),
);
return Future.wait(requestDocs);
},
);
}