diff --git a/lib/blocs/pin_file/pin_file_bloc.dart b/lib/blocs/pin_file/pin_file_bloc.dart index b1ffddb6d7..257fdffb0a 100644 --- a/lib/blocs/pin_file/pin_file_bloc.dart +++ b/lib/blocs/pin_file/pin_file_bloc.dart @@ -3,7 +3,7 @@ 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' show EntityTag, FileEntity; import 'package:ardrive/entities/string_types.dart'; import 'package:ardrive/misc/misc.dart'; import 'package:ardrive/models/models.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, @@ -311,13 +312,29 @@ class PinFileBloc extends Bloc { .folderById(driveId: _driveId, folderId: _parentFolderId) .getSingle(); + final isAPublicPin = fileKey == null; + if (_turboUploadService.useTurboUpload) { final fileDataItem = await _arweave.prepareEntityDataItem( newFileEntity, - profileState.wallet, + wallet, key: fileKey, + skipSignature: true, ); + if (isAPublicPin) { + fileDataItem.addTag( + EntityTag.arFsPin, + 'true', + ); + fileDataItem.addTag( + EntityTag.pinnedDataTx, + newFileEntity.dataTxId!, + ); + } + + await fileDataItem.sign(wallet); + await _turboUploadService.postDataItem( dataItem: fileDataItem, wallet: profileState.wallet, @@ -326,10 +343,24 @@ class PinFileBloc extends Bloc { } else { final fileDataItem = await _arweave.prepareEntityTx( newFileEntity, - profileState.wallet, + wallet, fileKey, + skipSignature: true, ); + if (isAPublicPin) { + fileDataItem.addTag( + EntityTag.arFsPin, + 'true', + ); + fileDataItem.addTag( + EntityTag.pinnedDataTx, + newFileEntity.dataTxId!, + ); + } + + await fileDataItem.sign(wallet); + await _arweave.postTx(fileDataItem); newFileEntity.txId = fileDataItem.id; } 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 { 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; }