executeWith method

Future<Execution> executeWith(
  1. Profile prf,
  2. List<Item> inputs, {
  3. int CoinInputIndex = 0,
  4. List<PaymentInfo> paymentInfoGen()?,
})

Executes the provided recipe using the provided profile and item inputs, and returns an execution. If the execution fails, returns an error instead. Because executions are currently not working, all you really get out of this is "the transaction didn't fail." If you need specific outputs after executing a recipe, you'll have to retrieve those from the user profile manually.

This is obviously not an ideal state of affairs, and will be fixed ASAP.

Implementation

Future<Execution> executeWith (Profile prf, List<Item> inputs, {int CoinInputIndex = 0, List<generated.PaymentInfo>Function()? paymentInfoGen} ) async {
  var ids = <String>[];
  var infos = <generated.PaymentInfo>[];
  if (paymentInfoGen != null) infos = paymentInfoGen();

  inputs.forEach((item) {
    ids.add(item.getId());
  });
  // Pass this through to the low-level API
  String cb;
  String name;
  if (_native != null) {
    cb = _native!.cookbookId;
    name = _native!.name;
  } else {
    cb = Cookbook.current!.getId();
    name = _forcedId!;
  }
  var lowLevel = await PylonsWallet.instance.txExecuteRecipe(
      cookbookId: cb,
      recipeName: name,
      itemIds: List.unmodifiable(ids),
      coinInputIndex: 0,
      paymentInfo: List.unmodifiable(infos),
      sender: prf.address,
      requestResponse: true);
  if (lowLevel.error == '') {
    return Execution(lowLevel.data!);
  } else {
    print(lowLevel.error);
    return Future.error(lowLevel.error);
  }
}