Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE-4545: Adds a GQL Tag for public pinned files #1365

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -314,10 +315,25 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
if (_turboUploadService.useTurboUpload) {
final fileDataItem = await _arweave.prepareEntityDataItem(
newFileEntity,
profileState.wallet,
wallet,
key: fileKey,
skipSignature: true,
);

fileDataItem.addTag(
EntityTag.arFsPin,
'true',
);
if (fileKey == null) {
// If file is public
fileDataItem.addTag(
EntityTag.pinnedDataTx,
newFileEntity.dataTxId!,
);
}

fileDataItem.sign(wallet);

await _turboUploadService.postDataItem(
dataItem: fileDataItem,
wallet: profileState.wallet,
Expand All @@ -326,10 +342,25 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
} else {
final fileDataItem = await _arweave.prepareEntityTx(
newFileEntity,
profileState.wallet,
wallet,
fileKey,
skipSignature: true,
);

fileDataItem.addTag(
EntityTag.arFsPin,
'true',
);
if (fileKey == null) {
// If file is public
fileDataItem.addTag(
EntityTag.pinnedDataTx,
newFileEntity.dataTxId!,
);
}

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