Skip to content

Commit

Permalink
Merge pull request #1365 from ardriveapp/PE-4545
Browse files Browse the repository at this point in the history
PE-4545: Adds a GQL Tag for public pinned files
  • Loading branch information
matibat authored Sep 21, 2023
2 parents 668cb18 + c2a4153 commit 5918a44
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
37 changes: 34 additions & 3 deletions lib/blocs/pin_file/pin_file_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -279,6 +279,7 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
) async {
final stateAsPinFileFieldsValid = state as PinFileFieldsValid;
final profileState = _profileCubit.state as ProfileLoggedIn;
final wallet = profileState.wallet;

emit(PinFileCreating(
id: stateAsPinFileFieldsValid.id,
Expand Down Expand Up @@ -311,13 +312,29 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
.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,
Expand All @@ -326,10 +343,24 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
} 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;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/entities/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion lib/services/arweave/arweave_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5918a44

Please sign in to comment.