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? someToContract,
  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? someToContract,
  required int amount,
  required int fee,
  required ValueTypeIdentifier tokenType,
  Option<GroupId>? groupId,
  Option<SeriesId>? seriesId,
}) async {
  try {
    final fromFellowship = fromCoordinates.$1;
    final fromContract = fromCoordinates.$2;
    final someFromState = fromCoordinates.$3;
    final someChangeFellowship = changeCoordinates.$1;
    final someChangeContract = changeCoordinates.$2;
    final someChangeState = changeCoordinates.$3;

    final validationResult =
        walletStateAlgebra.validateCurrentIndicesForFunds(
            fromFellowship, fromContract, someFromState);

    if (validationResult.isLeft) {
      return Either.left('Invalid params\n ${validationResult.left}');
    }

    final res =
        await simpleTransactionAlgebra.createSimpleTransactionFromParams(
      keyfile: keyfile,
      password: password,
      fromFellowship: fromFellowship,
      fromContract: fromContract,
      someFromState: someFromState,
      someChangeFellowship: someChangeFellowship,
      someChangeContract: someChangeContract,
      someChangeState: someChangeState,
      someToAddress: someToAddress,
      someToFellowship: someToFellowship,
      someToContract: someToContract,
      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');
  }
}