invokeAction method

Future<TransactionResponseDoc> invokeAction({
  1. required String operator,
  2. required String name,
  3. required String fromAccountId,
  4. String? targetAccountId,
  5. bool targetAll = false,
  6. List<int> payload = const [],
  7. String? contextId,
})

Implementation

Future<TransactionResponseDoc> invokeAction({
  required String operator,
  required String name,
  required String fromAccountId,
  String? targetAccountId,
  bool targetAll = false,
  List<int> payload = const [],
  String? contextId,
}) async {
  final Target target;
  if (targetAccountId != null) {
    target = Target()..accountId = hex.decode(targetAccountId);
  } else if (targetAll) {
    target = Target()..anyAccount = Empty();
  } else {
    throw 'Missing action target';
  }

  final action = InvokeAction()
    ..name = name
    ..fromAccount = hex.decode(fromAccountId)
    ..target = target
    ..payload = payload;

  final request = TransactionRequestPayload()
    ..data = (TransactionData()..invokeAction = action);
  final client = getServiceClient(operator);
  final envelop = await requestEnvelope(
    request: request,
    contextId: contextId != null ? hex.decode(contextId) : null,
  );
  final response = await client.tx.createTransaction(envelop);

  return TransactionResponseDoc(response, contextId);
}