From 4a1e34445e9975ee6abadb8b665863fe7298fd55 Mon Sep 17 00:00:00 2001 From: Mati Date: Fri, 15 Sep 2023 13:07:17 -0300 Subject: [PATCH 1/5] feat(pin file bloc): adds a gql tag for public pinned files PE-4545 --- lib/blocs/pin_file/pin_file_bloc.dart | 27 +++++++++++++++++++++-- lib/services/arweave/arweave_service.dart | 5 ++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/blocs/pin_file/pin_file_bloc.dart b/lib/blocs/pin_file/pin_file_bloc.dart index b1ffddb6d7..b2bbc29adf 100644 --- a/lib/blocs/pin_file/pin_file_bloc.dart +++ b/lib/blocs/pin_file/pin_file_bloc.dart @@ -279,6 +279,7 @@ class PinFileBloc extends Bloc { ) async { final stateAsPinFileFieldsValid = state as PinFileFieldsValid; final profileState = _profileCubit.state as ProfileLoggedIn; + final wallet = profileState.wallet; emit(PinFileCreating( id: stateAsPinFileFieldsValid.id, @@ -314,10 +315,21 @@ class PinFileBloc extends Bloc { if (_turboUploadService.useTurboUpload) { final fileDataItem = await _arweave.prepareEntityDataItem( newFileEntity, - profileState.wallet, + wallet, key: fileKey, + skipSignature: true, ); + if (fileKey == null) { + // If file is public + fileDataItem.addTag( + 'Pinned-Data-Owner', + stateAsPinFileFieldsValid.pinnedDataOwnerAddress, + ); + } + + fileDataItem.sign(wallet); + await _turboUploadService.postDataItem( dataItem: fileDataItem, wallet: profileState.wallet, @@ -326,10 +338,21 @@ class PinFileBloc extends Bloc { } else { final fileDataItem = await _arweave.prepareEntityTx( newFileEntity, - profileState.wallet, + wallet, fileKey, + skipSignature: true, ); + if (fileKey == null) { + // If file is public + fileDataItem.addTag( + 'Pinned-Data-Owner', + stateAsPinFileFieldsValid.pinnedDataOwnerAddress, + ); + } + + fileDataItem.sign(wallet); + await _arweave.postTx(fileDataItem); newFileEntity.txId = fileDataItem.id; } diff --git a/lib/services/arweave/arweave_service.dart b/lib/services/arweave/arweave_service.dart index 06ad23c6f2..4afa342aaf 100644 --- a/lib/services/arweave/arweave_service.dart +++ b/lib/services/arweave/arweave_service.dart @@ -1068,11 +1068,14 @@ class ArweaveService { Entity entity, Wallet wallet, { SecretKey? key, + bool skipSignature = false, }) async { final item = await entity.asDataItem(key); item.setOwner(await wallet.getOwner()); - await item.sign(wallet); + if (!skipSignature) { + await item.sign(wallet); + } return item; } From e0785f1da200377ee403c23686e4fb3686cb3007 Mon Sep 17 00:00:00 2001 From: Mati Date: Fri, 15 Sep 2023 15:29:57 -0300 Subject: [PATCH 2/5] feat(pin file bloc): sets ArFS-Pin tag for all pins, and Pinned-Data-Tx for public ones PE-4545 --- lib/blocs/pin_file/pin_file_bloc.dart | 19 +++++++++++++------ lib/entities/constants.dart | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/blocs/pin_file/pin_file_bloc.dart b/lib/blocs/pin_file/pin_file_bloc.dart index b2bbc29adf..8d017cf330 100644 --- a/lib/blocs/pin_file/pin_file_bloc.dart +++ b/lib/blocs/pin_file/pin_file_bloc.dart @@ -1,9 +1,8 @@ import 'dart:async'; import 'package:ardrive/blocs/blocs.dart'; -import 'package:ardrive/core/arfs/entities/arfs_entities.dart'; import 'package:ardrive/core/crypto/crypto.dart'; -import 'package:ardrive/entities/file_entity.dart'; +import 'package:ardrive/entities/entities.dart'; import 'package:ardrive/entities/string_types.dart'; import 'package:ardrive/misc/misc.dart'; import 'package:ardrive/models/models.dart'; @@ -320,11 +319,15 @@ class PinFileBloc extends Bloc { skipSignature: true, ); + fileDataItem.addTag( + EntityTag.arFsPin, + 'true', + ); if (fileKey == null) { // If file is public fileDataItem.addTag( - 'Pinned-Data-Owner', - stateAsPinFileFieldsValid.pinnedDataOwnerAddress, + EntityTag.pinnedDataTx, + newFileEntity.dataTxId!, ); } @@ -343,11 +346,15 @@ class PinFileBloc extends Bloc { skipSignature: true, ); + fileDataItem.addTag( + EntityTag.arFsPin, + 'true', + ); if (fileKey == null) { // If file is public fileDataItem.addTag( - 'Pinned-Data-Owner', - stateAsPinFileFieldsValid.pinnedDataOwnerAddress, + EntityTag.pinnedDataTx, + newFileEntity.dataTxId!, ); } diff --git a/lib/entities/constants.dart b/lib/entities/constants.dart index 45089943d8..8d904258c7 100644 --- a/lib/entities/constants.dart +++ b/lib/entities/constants.dart @@ -30,6 +30,9 @@ class EntityTag { static const blockEnd = 'Block-End'; static const dataStart = 'Data-Start'; static const dataEnd = 'Data-End'; + + static const pinnedDataTx = 'Pinned-Data-Tx'; + static const arFsPin = 'ArFS-Pin'; } class ContentType { From 2d8de9234a9e09fe00cf6e33350a927ad07580d0 Mon Sep 17 00:00:00 2001 From: Mati Date: Fri, 15 Sep 2023 16:23:27 -0300 Subject: [PATCH 3/5] feat(pin file bloc): corrects imports PE-4545 --- lib/blocs/pin_file/pin_file_bloc.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/blocs/pin_file/pin_file_bloc.dart b/lib/blocs/pin_file/pin_file_bloc.dart index 8d017cf330..9d1888eb63 100644 --- a/lib/blocs/pin_file/pin_file_bloc.dart +++ b/lib/blocs/pin_file/pin_file_bloc.dart @@ -1,8 +1,9 @@ import 'dart:async'; import 'package:ardrive/blocs/blocs.dart'; +import 'package:ardrive/core/arfs/entities/arfs_entities.dart'; import 'package:ardrive/core/crypto/crypto.dart'; -import 'package:ardrive/entities/entities.dart'; +import 'package:ardrive/entities/entities.dart' show EntityTag, FileEntity; import 'package:ardrive/entities/string_types.dart'; import 'package:ardrive/misc/misc.dart'; import 'package:ardrive/models/models.dart'; From 791649ddfe53ab22c599f9b394bd64fb2d9f1e48 Mon Sep 17 00:00:00 2001 From: Mati Date: Mon, 18 Sep 2023 13:37:30 -0300 Subject: [PATCH 4/5] feat(pin file bloc): tag public pinned files only PE-4545 --- lib/blocs/pin_file/pin_file_bloc.dart | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/blocs/pin_file/pin_file_bloc.dart b/lib/blocs/pin_file/pin_file_bloc.dart index 9d1888eb63..332636d99e 100644 --- a/lib/blocs/pin_file/pin_file_bloc.dart +++ b/lib/blocs/pin_file/pin_file_bloc.dart @@ -312,6 +312,8 @@ class PinFileBloc extends Bloc { .folderById(driveId: _driveId, folderId: _parentFolderId) .getSingle(); + final isAPublicPin = fileKey == null; + if (_turboUploadService.useTurboUpload) { final fileDataItem = await _arweave.prepareEntityDataItem( newFileEntity, @@ -320,12 +322,11 @@ class PinFileBloc extends Bloc { skipSignature: true, ); - fileDataItem.addTag( - EntityTag.arFsPin, - 'true', - ); - if (fileKey == null) { - // If file is public + if (isAPublicPin) { + fileDataItem.addTag( + EntityTag.arFsPin, + 'true', + ); fileDataItem.addTag( EntityTag.pinnedDataTx, newFileEntity.dataTxId!, @@ -347,12 +348,11 @@ class PinFileBloc extends Bloc { skipSignature: true, ); - fileDataItem.addTag( - EntityTag.arFsPin, - 'true', - ); - if (fileKey == null) { - // If file is public + if (isAPublicPin) { + fileDataItem.addTag( + EntityTag.arFsPin, + 'true', + ); fileDataItem.addTag( EntityTag.pinnedDataTx, newFileEntity.dataTxId!, From 8b338ee149c2b2a689152009b195fe9c84caa86e Mon Sep 17 00:00:00 2001 From: Mati Date: Wed, 20 Sep 2023 12:46:04 -0300 Subject: [PATCH 5/5] feat(pin file bloc): awaits for the signature of the transaction PE-4645 --- lib/blocs/pin_file/pin_file_bloc.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/blocs/pin_file/pin_file_bloc.dart b/lib/blocs/pin_file/pin_file_bloc.dart index 332636d99e..257fdffb0a 100644 --- a/lib/blocs/pin_file/pin_file_bloc.dart +++ b/lib/blocs/pin_file/pin_file_bloc.dart @@ -333,7 +333,7 @@ class PinFileBloc extends Bloc { ); } - fileDataItem.sign(wallet); + await fileDataItem.sign(wallet); await _turboUploadService.postDataItem( dataItem: fileDataItem, @@ -359,7 +359,7 @@ class PinFileBloc extends Bloc { ); } - fileDataItem.sign(wallet); + await fileDataItem.sign(wallet); await _arweave.postTx(fileDataItem); newFileEntity.txId = fileDataItem.id;