From b43a78a13c447e05dfb767431370ab022edfc4de Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:49:50 -0300 Subject: [PATCH 1/3] save drivekey in memory and don't break upload if fails to load the arns names --- lib/blocs/upload/upload_cubit.dart | 17 +++++++++---- lib/main.dart | 6 ++++- lib/services/arweave/arweave_service.dart | 29 ++++++++++++++++------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/blocs/upload/upload_cubit.dart b/lib/blocs/upload/upload_cubit.dart index 61ce3c5054..9725014cba 100644 --- a/lib/blocs/upload/upload_cubit.dart +++ b/lib/blocs/upload/upload_cubit.dart @@ -150,7 +150,7 @@ class UploadCubit extends Cubit { fileId: manifestModels[i].existingManifestFileId, ) .getSingle(); - + await _createManifestCubit.prepareManifestTx( manifestName: manifestFileEntry.name, folderId: manifestFileEntry.parentFolderId, @@ -886,6 +886,10 @@ class UploadCubit extends Cubit { if (state is UploadReady) { emit((state as UploadReady).copyWith(arnsRecords: value)); } + }).catchError((e) { + logger.e( + 'Error getting ant records for wallet. Proceeding with the upload...', + e); }); _files @@ -1032,9 +1036,14 @@ class UploadCubit extends Cubit { } if (manifestFileEntries.isNotEmpty) { - // load arns names - await _arnsRepository - .getAntRecordsForWallet(_auth.currentUser.walletAddress); + try { + await _arnsRepository + .getAntRecordsForWallet(_auth.currentUser.walletAddress); + } catch (e) { + logger.e( + 'Error getting ant records for wallet. Proceeding with the upload...', + e); + } } emit( diff --git a/lib/main.dart b/lib/main.dart index 0fe72a818a..1b75627f74 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -75,6 +75,7 @@ late ConfigService configService; late ArweaveService arweave; late TurboUploadService _turboUpload; late PaymentService _turboPayment; +late Database db; void main() async { await runZonedGuarded(() async { @@ -129,11 +130,14 @@ Future _initializeServices() async { final config = configService.config; + db = Database(); + arweave = ArweaveService( Arweave( gatewayUrl: Uri.parse(config.defaultArweaveGatewayForDataRequest.url), ), ArDriveCrypto(), + db.driveDao, configService, ); _turboUpload = config.useTurboUpload @@ -395,7 +399,7 @@ class AppState extends State { ), ), ), - RepositoryProvider(create: (_) => Database()), + RepositoryProvider(create: (_) => db), RepositoryProvider( create: (context) => context.read().profileDao), RepositoryProvider( diff --git a/lib/services/arweave/arweave_service.dart b/lib/services/arweave/arweave_service.dart index 0c1ff7f729..92ae0ee0d5 100644 --- a/lib/services/arweave/arweave_service.dart +++ b/lib/services/arweave/arweave_service.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:ardrive/core/crypto/crypto.dart'; import 'package:ardrive/entities/entities.dart'; +import 'package:ardrive/models/daos/drive_dao/drive_dao.dart'; import 'package:ardrive/services/arweave/arweave_service_exception.dart'; import 'package:ardrive/services/arweave/error/gateway_error.dart'; import 'package:ardrive/services/arweave/get_segmented_transaction_from_drive_strategy.dart'; @@ -42,12 +43,13 @@ const kMaxNumberOfTransactionsPerPage = 100; class ArweaveService { Arweave client; final ArDriveCrypto _crypto; - + final DriveDao _driveDao; final ArtemisClient _gql; ArweaveService( this.client, this._crypto, + this._driveDao, ConfigService configService, { ArtemisClient? artemisClient, }) : _gql = artemisClient ?? @@ -588,15 +590,24 @@ class ArweaveService { continue; } - final driveKey = - driveTx.getTag(EntityTag.drivePrivacy) == DrivePrivacyTag.private - ? await _crypto.deriveDriveKey( - wallet, - driveTx.getTag(EntityTag.driveId)!, - password, - ) - : null; + SecretKey? driveKey; + + if (driveTx.getTag(EntityTag.drivePrivacy) == DrivePrivacyTag.private) { + driveKey = await _driveDao.getDriveKeyFromMemory( + driveTx.getTag(EntityTag.driveId)!, + ); + + driveKey ??= await _crypto.deriveDriveKey( + wallet, + driveTx.getTag(EntityTag.driveId)!, + password, + ); + _driveDao.putDriveKeyInMemory( + driveID: driveTx.getTag(EntityTag.driveId)!, + driveKey: driveKey, + ); + } try { final drive = await DriveEntity.fromTransaction( driveTx, From 9c5af0f2c2f14f3044f4ecb626885478c58bf2cd Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:08:40 -0300 Subject: [PATCH 2/3] Update arweave_service.dart --- lib/services/arweave/arweave_service.dart | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/services/arweave/arweave_service.dart b/lib/services/arweave/arweave_service.dart index 92ae0ee0d5..208567b90e 100644 --- a/lib/services/arweave/arweave_service.dart +++ b/lib/services/arweave/arweave_service.dart @@ -597,16 +597,18 @@ class ArweaveService { driveTx.getTag(EntityTag.driveId)!, ); - driveKey ??= await _crypto.deriveDriveKey( - wallet, - driveTx.getTag(EntityTag.driveId)!, - password, - ); + if (driveKey == null) { + driveKey = await _crypto.deriveDriveKey( + wallet, + driveTx.getTag(EntityTag.driveId)!, + password, + ); - _driveDao.putDriveKeyInMemory( - driveID: driveTx.getTag(EntityTag.driveId)!, - driveKey: driveKey, - ); + _driveDao.putDriveKeyInMemory( + driveID: driveTx.getTag(EntityTag.driveId)!, + driveKey: driveKey, + ); + } } try { final drive = await DriveEntity.fromTransaction( From 91f5288300f4acba5e58a04ffea51ef0701fc707 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:58:29 -0300 Subject: [PATCH 3/3] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 686aa3a0c1..801305b206 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Secure, permanent storage publish_to: 'none' -version: 2.57.1 +version: 2.57.2 environment: sdk: '>=3.2.0 <4.0.0'