Skip to content

Commit

Permalink
Merge pull request #373 from 0xPolygonID/fix/circuit-download-exception
Browse files Browse the repository at this point in the history
feat(exception): custom circuits not downloaded exception
  • Loading branch information
jrl351 authored Jan 29, 2024
2 parents 381cbf6 + 9e68b2f commit bf03cdb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
34 changes: 22 additions & 12 deletions lib/proof/data/data_sources/circuits_files_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:polygonid_flutter_sdk/proof/domain/exceptions/proof_generation_exceptions.dart';
import 'package:polygonid_flutter_sdk/sdk/di/injector.dart';

class CircuitsFilesDataSource {
Expand All @@ -12,18 +13,27 @@ class CircuitsFilesDataSource {
Future<List<Uint8List>> loadCircuitFiles(String circuitId) async {
String path = directory.path;

var circuitDatFileName = '$circuitId.dat';
var circuitDatFilePath = '$path/$circuitDatFileName';
var circuitDatFile = File(circuitDatFilePath);

var circuitZkeyFileName = '$circuitId.zkey';
var circuitZkeyFilePath = '$path/$circuitZkeyFileName';
var circuitZkeyFile = File(circuitZkeyFilePath);

return [
circuitDatFile.readAsBytesSync(),
circuitZkeyFile.readAsBytesSync()
];
try {
var circuitDatFileName = '$circuitId.dat';
var circuitDatFilePath = '$path/$circuitDatFileName';
var circuitDatFile = File(circuitDatFilePath);

var circuitZkeyFileName = '$circuitId.zkey';
var circuitZkeyFilePath = '$path/$circuitZkeyFileName';
var circuitZkeyFile = File(circuitZkeyFilePath);

return [
circuitDatFile.readAsBytesSync(),
circuitZkeyFile.readAsBytesSync()
];
} on PathNotFoundException catch (error) {
throw CircuitNotDownloadedException(
circuit: circuitId,
errorMessage: error.message,
);
} catch (_) {
rethrow;
}
}

///
Expand Down
10 changes: 10 additions & 0 deletions lib/proof/domain/exceptions/proof_generation_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ class ProofInputsException implements Exception {

ProofInputsException(this.errorMessage);
}

class CircuitNotDownloadedException implements Exception {
final String circuit;
final String errorMessage;

CircuitNotDownloadedException({
required this.circuit,
required this.errorMessage,
});
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ issue_tracker: https://github.com/0xPolygonID/polygonid-flutter-sdk/issues
documentation: https://0xpolygonid.github.io/tutorials/

environment:
sdk: ">=2.17.0 <4.0.0"
sdk: ">=2.19.0 <4.0.0"

dependencies:
flutter:
Expand Down

0 comments on commit bf03cdb

Please sign in to comment.