Skip to content

Commit

Permalink
Merge pull request #1894 from ardriveapp/PE-6948-hotfix
Browse files Browse the repository at this point in the history
PE-6948: proceed upload despite the contract read error
  • Loading branch information
thiagocarvalhodev authored Nov 13, 2024
2 parents 0417c28 + 6b6a724 commit c2a7d33
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
6 changes: 5 additions & 1 deletion lib/core/upload/bundle_signer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class ArweaveBundleTransactionSigner implements BundleTransactionSigner {

logger.i('Adding tip...');

await pstService.addCommunityTipToTx(bundleTx);
try {
await pstService.addCommunityTipToTx(bundleTx);
} catch (e) {
logger.e('Error adding community tip to transaction. Proceeding.', e);
}

logger.i('Tip added');

Expand Down
8 changes: 7 additions & 1 deletion lib/core/upload/cost_calculator.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:ardrive/services/arweave/arweave.dart';
import 'package:ardrive/turbo/turbo.dart';
import 'package:ardrive/utils/logger.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:arweave/utils.dart';
import 'package:equatable/equatable.dart';
import 'package:pst/pst.dart';
Expand Down Expand Up @@ -64,7 +65,12 @@ class UploadCostEstimateCalculatorForAR extends ArDriveUploadCostCalculator {
}) async {
final costInAR = await _arweaveService.getPrice(byteSize: totalSize);

final pstFee = await _pstService.getPSTFee(costInAR);
Winston pstFee = Winston(BigInt.zero);
try {
pstFee = await _pstService.getPSTFee(costInAR);
} catch (e) {
logger.e('Error adding community tip to transaction. Proceeding.', e);
}

final totalCostAR = costInAR + pstFee.value;

Expand Down
6 changes: 5 additions & 1 deletion lib/core/upload/transaction_signer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ class ArweaveTransactionSigner implements TransactionSigner {
..addApplicationTags(version: version)
..addUTags();

await pstService.addCommunityTipToTx(dataTx);
try {
await pstService.addCommunityTipToTx(dataTx);
} catch (e) {
logger.e('Error adding community tip to transaction. Proceeding.', e);
}

// Don't include the file's Content-Type tag if it is meant to be private.
if (!isPrivate) {
Expand Down
24 changes: 14 additions & 10 deletions lib/sync/domain/repositories/sync_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,20 @@ class _SyncRepository implements SyncRepository {

logger.i('Syncing licenses...');

final licenseTxIds = <String>{};
final revisionsToSyncLicense = (await _driveDao
.allFileRevisionsWithLicenseReferencedButNotSynced()
.get())
..retainWhere((rev) => licenseTxIds.add(rev.licenseTxId!));
logger.d('Found ${revisionsToSyncLicense.length} licenses to sync');

await _updateLicenses(
revisionsToSyncLicense: revisionsToSyncLicense,
);
try {
final licenseTxIds = <String>{};
final revisionsToSyncLicense = (await _driveDao
.allFileRevisionsWithLicenseReferencedButNotSynced()
.get())
..retainWhere((rev) => licenseTxIds.add(rev.licenseTxId!));
logger.d('Found ${revisionsToSyncLicense.length} licenses to sync');

await _updateLicenses(
revisionsToSyncLicense: revisionsToSyncLicense,
);
} catch (e) {
logger.e('Error syncing licenses. Proceeding.', e);
}

logger.i('Licenses synced');

Expand Down
11 changes: 9 additions & 2 deletions packages/ardrive_uploader/lib/src/cost_calculator.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:ardrive_uploader/src/utils/logger.dart';
import 'package:ardrive_utils/ardrive_utils.dart';
import 'package:arweave/arweave.dart';
import 'package:arweave/utils.dart';
// ignore: depend_on_referenced_packages
import 'package:equatable/equatable.dart';
import 'package:pst/pst.dart';
import 'package:ardrive_uploader/src/utils/logger.dart';

abstract class ArDriveUploadCostCalculator {
Future<UploadCostEstimate> calculateCost({required int totalSize});
Expand Down Expand Up @@ -67,7 +67,14 @@ class UploadCostEstimateCalculatorForAR extends ArDriveUploadCostCalculator {
.get('/price/$totalSize')
.then((res) => BigInt.parse(res.body));

final pstFee = await _pstService.getPSTFee(costInAR);
late final Winston pstFee;

try {
pstFee = await _pstService.getPSTFee(costInAR);
} catch (e) {
logger.e('Error adding community tip to transaction. Proceeding.', e);
pstFee = Winston(BigInt.zero);
}

final totalCostAR = costInAR + pstFee.value;

Expand Down

0 comments on commit c2a7d33

Please sign in to comment.