From 9b834fc4d8b202ae82145f22eb59a2967de31f29 Mon Sep 17 00:00:00 2001 From: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:27:58 -0400 Subject: [PATCH] feat: do not write to ipfs --- src/services/anchor-service.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/services/anchor-service.ts b/src/services/anchor-service.ts index 78029762..a69eb367 100644 --- a/src/services/anchor-service.ts +++ b/src/services/anchor-service.ts @@ -318,14 +318,17 @@ export class AnchorService { logger.debug('Creating anchor commits') const anchors = await this._createAnchorCommits(ipfsProofCid, merkleTree) - logger.debug('Importing Merkle CAR to IPFS') - try { - await this.ipfsService.importCAR(merkleTree.car) - } catch (e) { - Metrics.count(METRIC_NAMES.MERKLE_CAR_STORAGE_FAILURE_IPFS, 1) - const message = `Can not store Merkle CAR to IPFS. Batch failed: ${e}` - logger.err(message) - throw e + // Do not store CAR file in IPFS by default + if (process.env['CAS_USE_IPFS_STORAGE']) { + logger.debug('Importing Merkle CAR to IPFS') + try { + await this.ipfsService.importCAR(merkleTree.car) + } catch (e) { + Metrics.count(METRIC_NAMES.MERKLE_CAR_STORAGE_FAILURE_IPFS, 1) + const message = `Can not store Merkle CAR to IPFS. Batch failed: ${e}` + logger.err(message) + throw e + } } logger.debug('Storing Merkle CAR file') @@ -504,8 +507,10 @@ export class AnchorService { } try { - await this.ipfsService.storeRecord(ipfsAnchorCommit) - + // Do not store in IPFS by default + if (process.env['CAS_USE_IPFS_STORAGE']) { + await this.ipfsService.storeRecord(ipfsAnchorCommit) + } // Do not publish to pubsub by default if (process.env['CAS_PUBSUB_PUBLISH']) { // TODO: Remove this case entirely after js-ceramic no longer supports pubsub