createSimpleTransactionFromParams method

Future<Either<String, String>> createSimpleTransactionFromParams({
  1. required String keyfile,
  2. required String password,
  3. required (String, String, int?) fromCoordinates,
  4. required (String?, String?, int?) changeCoordinates,
  5. LockAddress? someToAddress,
  6. String? someToFellowship,
  7. String? someToTemplate,
  8. required int amount,
  9. required int fee,
  10. required ValueTypeIdentifier tokenType,
  11. Option<GroupId>? groupId,
  12. Option<SeriesId>? seriesId,
})

Implementation

Future<Either<String, String>> createSimpleTransactionFromParams({
  required String keyfile,
  required String password,
  required (String, String, int?) fromCoordinates,
  required (String?, String?, int?) changeCoordinates,
  LockAddress? someToAddress,
  String? someToFellowship,
  String? someToTemplate,
  required int amount,
  required int fee,
  required ValueTypeIdentifier tokenType,
  Option<GroupId>? groupId,
  Option<SeriesId>? seriesId,
}) async {
  try {
    final fromFellowship = fromCoordinates.$1;
    final fromTemplate = fromCoordinates.$2;
    final someFromState = fromCoordinates.$3;
    final someChangeFellowship = changeCoordinates.$1;
    final someChangeTemplate = changeCoordinates.$2;
    final someChangeState = changeCoordinates.$3;

    walletStateAlgebra.validateCurrentIndicesForFunds(
        fromFellowship, fromTemplate, someFromState);

    final res =
        await simpleTransactionAlgebra.createSimpleTransactionFromParams(
      keyfile: keyfile,
      password: password,
      fromFellowship: fromFellowship,
      fromTemplate: fromTemplate,
      someFromState: someFromState,
      someChangeFellowship: someChangeFellowship,
      someChangeTemplate: someChangeTemplate,
      someChangeState: someChangeState,
      someToAddress: someToAddress,
      someToFellowship: someToFellowship,
      someToTemplate: someToTemplate,
      amount: amount,
      fee: fee,
      tokenType: tokenType,
    );

    return res.fold((p0) => Either.left(p0.description),
        (_) => Either.right("Transaction successfully created"));
  } catch (e) {
    return Either.left('Unexpected error: $e');
  }
}